[PATCH v2 10/17] boot: Move preparing bootdev into a function
Simon Glass
sjg at chromium.org
Wed Oct 1 23:26:35 CEST 2025
The code at the end of iter_inc() is already somewhat tortuous. Before
making it worse, move it into a function.
Signed-off-by: Simon Glass <sjg at chromium.org>
---
(no changes since v1)
boot/bootflow.c | 40 +++++++++++++++++++++++++++++-----------
1 file changed, 29 insertions(+), 11 deletions(-)
diff --git a/boot/bootflow.c b/boot/bootflow.c
index 60f3498e2b9..4218b53d19f 100644
--- a/boot/bootflow.c
+++ b/boot/bootflow.c
@@ -245,6 +245,32 @@ static void scan_next_in_uclass(struct udevice **devp)
*devp = dev;
}
+/**
+ * prepare_bootdev() - Get ready to use a bootdev
+ *
+ * @iter: Bootflow iterator being used
+ * @dev: UCLASS_BOOTDEV device to use
+ * @method_flags: Method flag for the bootdev
+ * Return 0 if OK, -ve if the bootdev failed to probe
+ */
+static int prepare_bootdev(struct bootflow_iter *iter, struct udevice *dev,
+ int method_flags)
+{
+ int ret;
+
+ /*
+ * Probe the bootdev. This does not probe any attached block device,
+ * since they are siblings
+ */
+ ret = device_probe(dev);
+ log_debug("probe %s %d\n", dev->name, ret);
+ if (ret)
+ return log_msg_ret("probe", ret);
+ bootflow_iter_set_dev(iter, dev, method_flags);
+
+ return 0;
+}
+
/**
* iter_incr() - Move to the next item (method, part, bootdev)
*
@@ -387,18 +413,10 @@ static int iter_incr(struct bootflow_iter *iter)
}
log_debug("ret=%d, dev=%p %s\n", ret, dev,
dev ? dev->name : "none");
- if (ret) {
+ if (ret)
bootflow_iter_set_dev(iter, NULL, 0);
- } else {
- /*
- * Probe the bootdev. This does not probe any attached
- * block device, since they are siblings
- */
- ret = device_probe(dev);
- log_debug("probe %s %d\n", dev->name, ret);
- if (!log_msg_ret("probe", ret))
- bootflow_iter_set_dev(iter, dev, method_flags);
- }
+ else
+ ret = prepare_bootdev(iter, dev, method_flags);
}
/* if there are no more bootdevs, give up */
--
2.43.0
More information about the U-Boot
mailing list