Skip to contentSkip to conversation

boot: Ensure method_flags is initialised before use

PATCH In review Andrew Goodbody 2 participants 2 messages Jul 9, 2025 – Jul 16, 2025

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 boot: Ensure method_flags is initialised before use

The local variable method_flags is only assigned to in some of the code paths leaving it possibly uninitialised at first use. Initialise method_flags at declaration to ensure that it cannot be used uninitialised. Also remove now redundant assignments.

---
Changes in v2:
- When scanning a UCLASS set method_flags appropriately. This was
only happening accidentaly when method_flags was not initialised.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 boot/bootflow.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
boot/bootflow.c +2 -3
index 4054a966af8..d79f303486d 100644
@@ -245,7 +245,7 @@ static int iter_incr(struct bootflow_iter *iter)
 	if (iter->flags & BOOTFLOWIF_SINGLE_DEV) {
 		ret = -ENOENT;
 	} else {
-		int method_flags;
+		int method_flags = 0;
 
 		ret = 0;
 		dev = iter->dev;
@@ -264,7 +264,6 @@ static int iter_incr(struct bootflow_iter *iter)
 		} else if (IS_ENABLED(CONFIG_BOOTSTD_FULL) &&
 			   iter->flags & BOOTFLOWIF_SINGLE_MEDIA) {
 			log_debug("next in single\n");
-			method_flags = 0;
 			do {
 				/*
 				 * Move to the next bootdev child of this media
@@ -296,6 +295,7 @@ static int iter_incr(struct bootflow_iter *iter)
 					log_debug("looking for next device %s: %s\n",
 						  iter->dev->name,
 						  dev ? dev->name : "<none>");
+					method_flags = BOOTFLOW_METHF_SINGLE_UCLASS;
 				} else {
 					dev = NULL;
 				}
@@ -306,7 +306,6 @@ static int iter_incr(struct bootflow_iter *iter)
 				}
 			} else {
 				ret = bootdev_next_prio(iter, &dev);
-				method_flags = 0;
 			}
 		}
 		log_debug("ret=%d, dev=%p %s\n", ret, dev,

---
base-commit: 359e3012921f2fc2d43f3c4e320a752173f82b82
change-id: 20250627-bootflow_fix-b000ad021cc2

Best regards,

Signature · 1 line
Andrew Goodbody <[email protected]>
#1 lore raw
Quoted 6 lines · Andrew Goodbody

The local variable method_flags is only assigned to in some of the code paths leaving it possibly uninitialised at first use. Initialise method_flags at declaration to ensure that it cannot be used uninitialised. Also remove now redundant assignments.

Applied to u-boot/master, thanks!

[1/1] boot: Ensure method_flags is initialised before use

      commit: f1c03778a4be8e08decf88f6b2018b90f6662090
Signature · 1 line
Tom