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.schm...@pengutronix.de> Signed-off-by: Ahmad Fatoum <a.fat...@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