From 9d92c418acfb7576e12e2bd53fed294bb9543724 Mon Sep 17 00:00:00 2001 From: Caleb Connolly Date: Thu, 4 Jan 2024 16:03:35 +0000 Subject: bootdev: avoid infinite probe loop Sometimes, when only one bootdev is available, and it fails to probe, we end up in an infinite loop calling probe() on the same device over and over. With only debug level log output. Break the loop if we fail to probe the same device twice in a row, and promote the probe failure message to log_warning(). Signed-off-by: Caleb Connolly Reviewed-by: Simon Glass Reviewed-by: Dragan Simic --- boot/bootdev-uclass.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'boot') diff --git a/boot/bootdev-uclass.c b/boot/bootdev-uclass.c index 4926a50da85..35afb93c0e7 100644 --- a/boot/bootdev-uclass.c +++ b/boot/bootdev-uclass.c @@ -632,7 +632,7 @@ int bootdev_next_label(struct bootflow_iter *iter, struct udevice **devp, int bootdev_next_prio(struct bootflow_iter *iter, struct udevice **devp) { - struct udevice *dev = *devp; + struct udevice *dev = *devp, *last_dev = NULL; bool found; int ret; @@ -682,9 +682,19 @@ int bootdev_next_prio(struct bootflow_iter *iter, struct udevice **devp) } } else { ret = device_probe(dev); + if (!ret) + last_dev = dev; if (ret) { - log_debug("Device '%s' failed to probe\n", + log_warning("Device '%s' failed to probe\n", dev->name); + if (last_dev == dev) { + /* + * We have already tried this device + * and it failed to probe. Give up. + */ + return log_msg_ret("probe", ret); + } + last_dev = dev; dev = NULL; } } -- cgit v1.3.1 From 3f9312236a427db3bc11770ced4ed3c2b67d3c45 Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 7 Jan 2024 09:43:40 +0100 Subject: boot: remove dead code in bootflow_check() The 'return 0;' statement is not reachable. Remove it. 'else' is superfluous after an if statement with return. Addresses-Coverity-ID: 352451 ("Logically dead code") Signed-off-by: Heinrich Schuchardt --- boot/bootflow.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'boot') diff --git a/boot/bootflow.c b/boot/bootflow.c index 1ea2966ae9a..05484fd5b1b 100644 --- a/boot/bootflow.c +++ b/boot/bootflow.c @@ -361,7 +361,7 @@ static int bootflow_check(struct bootflow_iter *iter, struct bootflow *bflow) } /* Unless there is nothing more to try, move to the next device */ - else if (ret != BF_NO_MORE_PARTS && ret != -ENOSYS) { + if (ret != BF_NO_MORE_PARTS && ret != -ENOSYS) { log_debug("Bootdev '%s' part %d method '%s': Error %d\n", dev->name, iter->part, iter->method->name, ret); /* @@ -371,10 +371,8 @@ static int bootflow_check(struct bootflow_iter *iter, struct bootflow *bflow) if (iter->flags & BOOTFLOWIF_ALL) return log_msg_ret("all", ret); } - if (ret) - return log_msg_ret("check", ret); - return 0; + return log_msg_ret("check", ret); } int bootflow_scan_first(struct udevice *dev, const char *label, -- cgit v1.3.1 From 3a7744ed1e5bd61b0bf83b7e1897184cb1c54f3f Mon Sep 17 00:00:00 2001 From: Heinrich Schuchardt Date: Sun, 7 Jan 2024 10:01:07 +0100 Subject: boot: superfluous assignment in bootflow_menu_new() ret is assigned a value 0 which is never used but is immediately overwritten in the next statement. Addresses-Coverity-ID: 453304 ("Unused value") Signed-off-by: Heinrich Schuchardt --- boot/bootflow_menu.c | 1 - 1 file changed, 1 deletion(-) (limited to 'boot') diff --git a/boot/bootflow_menu.c b/boot/bootflow_menu.c index 7c1abe5772c..16f9cd8f8ca 100644 --- a/boot/bootflow_menu.c +++ b/boot/bootflow_menu.c @@ -120,7 +120,6 @@ int bootflow_menu_new(struct expo **expp) if (ret < 0) return log_msg_ret("itm", -EINVAL); - ret = 0; priv->num_bootflows++; } -- cgit v1.3.1