[Concept,04/14] bootstd: Clear iter->err on successful bootflow check
Commit Message
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(-)
@@ -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)
@@ -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);