[RFC 5/8] boot: prevent recursion in bootdev_hunt_drv()

Heinrich Schuchardt heinrich.schuchardt at canonical.com
Mon Apr 21 18:25:52 CEST 2025


If an implementation of the hunt() method calls bootdev_hunt() itself,
an infinite recursion may occur.

Set the sequence bit before invoking hunt().

Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
---
 boot/bootdev-uclass.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/boot/bootdev-uclass.c b/boot/bootdev-uclass.c
index 3791ebfcb42..da757a49481 100644
--- a/boot/bootdev-uclass.c
+++ b/boot/bootdev-uclass.c
@@ -791,6 +791,7 @@ static int bootdev_hunt_drv(struct bootdev_hunter *info, uint seq, bool show)
 		return log_msg_ret("std", ret);
 
 	if (!(std->hunters_used & BIT(seq))) {
+		std->hunters_used |= BIT(seq);
 		if (show)
 			printf("Hunting with: %s\n",
 			       uclass_get_name(info->uclass));
@@ -801,7 +802,6 @@ static int bootdev_hunt_drv(struct bootdev_hunter *info, uint seq, bool show)
 			if (ret && ret != -ENOENT)
 				return ret;
 		}
-		std->hunters_used |= BIT(seq);
 	}
 
 	return 0;
-- 
2.48.1



More information about the U-Boot mailing list