[Concept,03/14] bootstd: Set iter->err before BOOTFLOWIF_ALL early return

Message ID 20260322235719.1729267-4-sjg@u-boot.org
State New
Headers
Series bootstd: Infrastructure for multi-entry bootflow support |

Commit Message

Simon Glass March 22, 2026, 11:57 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

In bootflow_scan_first(), iter->err is not set before the BOOTFLOWIF_ALL
early return, leaving it at its initial value of 0. This is inconsistent
with bootflow_scan_next() which sets iter->err before the same early
return.

Move the iter->err assignment before the BOOTFLOWIF_ALL check so that
subsequent calls to iter_incr() can correctly see the error from the
previous iteration.

Fixes: 5033e36637af ("bootstd: Add support for bootflows")
Signed-off-by: Simon Glass <sjg@chromium.org>
---

 boot/bootflow.c      | 2 +-
 test/boot/bootflow.c | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)
  

Patch

diff --git a/boot/bootflow.c b/boot/bootflow.c
index befe507af96..a8a73ee0c7f 100644
--- a/boot/bootflow.c
+++ b/boot/bootflow.c
@@ -655,11 +655,11 @@  int bootflow_scan_first(struct udevice *dev, const char *label,
 	ret = bootflow_check(iter, bflow);
 	if (ret) {
 		log_debug("check - ret=%d\n", ret);
+		iter->err = ret;
 		if (ret != BF_NO_MORE_PARTS && ret != -ENOSYS) {
 			if (iter->flags & BOOTFLOWIF_ALL)
 				return log_msg_ret("all", ret);
 		}
-		iter->err = ret;
 		bootflow_free(bflow);
 		ret = bootflow_scan_next(iter, bflow);
 		if (ret)
diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c
index 6c84a264bff..5ecb5f557b1 100644
--- a/test/boot/bootflow.c
+++ b/test/boot/bootflow.c
@@ -321,6 +321,7 @@  static int bootflow_iter(struct unit_test_state *uts)
 	ut_asserteq(0, iter.max_part);
 	ut_asserteq_str("extlinux", iter.method->name);
 	ut_asserteq(0, bflow.err);
+	ut_asserteq(-EPROTONOSUPPORT, iter.err);
 	ut_assert(!iter.doing_global);
 	ut_assert(!iter.have_global);
 	ut_asserteq(-1, iter.first_glob_method);