From: Simon Glass <sjg@chromium.org> When bootflow_check() succeeds in bootflow_scan_next(), iter->err is not cleared. It retains the error from the previous failed iteration, so callers of iter_incr() cannot reliably determine whether the last bootflow was found successfully. Clear iter->err to 0 on success, matching the convention that iter->err reflects the result of the most recent bootflow check. Fixes: 5033e36637af ("bootstd: Add support for bootflows") Signed-off-by: Simon Glass <sjg@chromium.org> --- boot/bootflow.c | 4 +++- test/boot/bootflow.c | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/boot/bootflow.c b/boot/bootflow.c index a8a73ee0c7f..4a55cc637fa 100644 --- a/boot/bootflow.c +++ b/boot/bootflow.c @@ -687,8 +687,10 @@ int bootflow_scan_next(struct bootflow_iter *iter, struct bootflow *bflow) } ret = bootflow_check(iter, bflow); log_debug("check - ret=%d\n", ret); - if (!ret) + if (!ret) { + iter->err = 0; return 0; + } iter->err = ret; if (ret != BF_NO_MORE_PARTS && ret != -ENOSYS) { if (iter->flags & BOOTFLOWIF_ALL) diff --git a/test/boot/bootflow.c b/test/boot/bootflow.c index 5ecb5f557b1..3bea1cc6634 100644 --- a/test/boot/bootflow.c +++ b/test/boot/bootflow.c @@ -402,6 +402,7 @@ static int bootflow_iter(struct unit_test_state *uts) ut_asserteq(0x1e, iter.max_part); ut_asserteq_str("extlinux", iter.method->name); ut_asserteq(0, bflow.err); + ut_asserteq(0, iter.err); ut_asserteq(BOOTFLOWST_READY, bflow.state); bootflow_free(&bflow); -- 2.43.0