[PATCH] boot: omit menu freeing loop when CONFIG_MENU is disabled

Ahmad Fatoum a.fatoum at pengutronix.de
Fri Feb 14 01:54:12 PST 2025


While free() can handle NULL pointers, it's better to not even call
free() when we know at compile-time that the pointers are NULL.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/boot.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/common/boot.c b/common/boot.c
index f6ac4779cc33..ced3b3a3477c 100644
--- a/common/boot.c
+++ b/common/boot.c
@@ -50,13 +50,14 @@ void bootentries_free(struct bootentries *bootentries)
 		be->release(be);
 	}
 
-	if (bootentries->menu) {
+	if (IS_ENABLED(CONFIG_MENU) && bootentries->menu) {
 		int i;
 		for (i = 0; i < bootentries->menu->display_lines; i++)
 			free_const(bootentries->menu->display[i]);
 		free_const(bootentries->menu->display);
+		free(bootentries->menu);
 	}
-	free(bootentries->menu);
+
 	free(bootentries);
 }
 
-- 
2.39.5




More information about the barebox mailing list