From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Lars Schmidt <l.schmidt@pengutronix.de>,
Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH] fixup! bootchooser: implement locking of attempts counter
Date: Mon, 23 Jun 2025 15:13:06 +0200 [thread overview]
Message-ID: <20250623131306.2179862-1-a.fatoum@pengutronix.de> (raw)
We have two code paths with goto err that don't set ret beforehand with
the expectation that the default -EINVAL will be used.
ret is now being reused though and thus the -EINVAL is clobbered. In the
worst case, an error ends up with ERR_PTR(ret) == NULL crashing
bootchooser -i when a state prefix is set, but no targets are defined.
Fix this by always initializing ret explicitly.
Cc: Lars Schmidt <l.schmidt@pengutronix.de>
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/bootchooser.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/common/bootchooser.c b/common/bootchooser.c
index 623cb8ce7714..a79eee8ca2c4 100644
--- a/common/bootchooser.c
+++ b/common/bootchooser.c
@@ -352,7 +352,7 @@ struct bootchooser *bootchooser_get(void)
struct bootchooser *bc;
struct bootchooser_target *target;
char *targets, *str, *freep = NULL, *delim;
- int ret = -EINVAL, id = 1;
+ int ret, id = 1;
uint32_t last_chosen;
static int attempts_resetted;
uint32_t locked;
@@ -430,11 +430,13 @@ struct bootchooser *bootchooser_get(void)
if (id == 1) {
pr_err("Target list $global.bootchooser.targets is empty\n");
+ ret = -EINVAL;
goto err;
}
if (list_empty(&bc->targets)) {
pr_err("No targets could be initialized\n");
+ ret = -EINVAL;
goto err;
}
--
2.39.5
next reply other threads:[~2025-06-23 17:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-23 13:13 Ahmad Fatoum [this message]
2025-06-24 7:19 ` Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250623131306.2179862-1-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.org \
--cc=l.schmidt@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox