Skip to contentSkip to conversation

block: Remove unreachable code

PATCH Superseded Andrew Goodbody 2 participants 5 messages Jul 15, 2025

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover block: Remove unreachable code

Smatch reported unreachable code in blk-uclass.c which led to noticing that uclass_find_next_device always returned 0 which meant it had no need of any return value.

---
Changes in v2:
- make uclass_find_next_device a void and update callers
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Andrew Goodbody (2):
block: Remove unreachable code
uclass: Cleanup uclass_find_next_device

 board/emulation/qemu-ppce500/qemu-ppce500.c |  4 ++--
 boot/bootdev-uclass.c                       |  2 +-
 cmd/regulator.c                             |  4 ++--
 drivers/block/blk-uclass.c                  | 14 ++++----------
 drivers/core/uclass.c                       | 16 +++++-----------
 drivers/power/regulator/regulator-uclass.c  | 10 ++++++----
 drivers/remoteproc/rproc-uclass.c           |  6 ++++--
 include/dm/uclass-internal.h                |  4 +---
 test/dm/core.c                              | 28 ++++++++++++++--------------
 9 files changed, 39 insertions(+), 49 deletions(-)

---
base-commit: 074e05952705972072f52128cf2e3ec2d8f35de6
change-id: 20250714-blk-uclass-34684c01f60c

Best regards,

Signature · 1 line
Andrew Goodbody <[email protected]>
#1 lore raw

PATCH v2 1/2 block: Remove unreachable code

The two functions blk_find_first and blk_find_next use a for loop with the content being a 'return 0' which means that the 'increment' code is unreachable so remove it and also remove the variable ret which is assigned to but its value is never used.

This issue found by Smatch.

---
 drivers/block/blk-uclass.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
drivers/block/blk-uclass.c +4 -10
index f3ac8db9464..b38c21ffbe2 100644
@@ -613,11 +613,8 @@ static int blk_flags_check(struct udevice *dev, enum blk_flag_t req_flags)
 
 int blk_find_first(enum blk_flag_t flags, struct udevice **devp)
 {
-	int ret;
-
-	for (ret = uclass_find_first_device(UCLASS_BLK, devp);
-	     *devp && !blk_flags_check(*devp, flags);
-	     ret = uclass_find_next_device(devp))
+	for (uclass_find_first_device(UCLASS_BLK, devp);
+	     *devp && !blk_flags_check(*devp, flags);)
 		return 0;
 
 	return -ENODEV;
@@ -625,11 +622,8 @@ int blk_find_first(enum blk_flag_t flags, struct udevice **devp)
 
 int blk_find_next(enum blk_flag_t flags, struct udevice **devp)
 {
-	int ret;
-
-	for (ret = uclass_find_next_device(devp);
-	     *devp && !blk_flags_check(*devp, flags);
-	     ret = uclass_find_next_device(devp))
+	for (uclass_find_next_device(devp);
+	     *devp && !blk_flags_check(*devp, flags);)
 		return 0;
 
 	return -ENODEV;
Signature · 1 line
2.39.5
#2 lore raw

PATCH v2 2/2 uclass: Cleanup uclass_find_next_device

In reply to Andrew Goodbody

uclass_find_next_device always returns 0, so instead make it a void and update calling sites.

---
 board/emulation/qemu-ppce500/qemu-ppce500.c |  4 ++--
 boot/bootdev-uclass.c                       |  2 +-
 cmd/regulator.c                             |  4 ++--
 drivers/core/uclass.c                       | 16 +++++-----------
 drivers/power/regulator/regulator-uclass.c  | 10 ++++++----
 drivers/remoteproc/rproc-uclass.c           |  6 ++++--
 include/dm/uclass-internal.h                |  4 +---
 test/dm/core.c                              | 28 ++++++++++++++--------------
 8 files changed, 35 insertions(+), 39 deletions(-)
board/emulation/qemu-ppce500/qemu-ppce500.c +2 -2
index 40d295dbf06..58de4a05296 100644
@@ -170,9 +170,9 @@ int misc_init_r(void)
 	 * Detect the presence of the platform bus node, and
 	 * create a virtual memory mapping for it.
 	 */
-	for (ret = uclass_find_first_device(UCLASS_SIMPLE_BUS, &dev);
+	for (uclass_find_first_device(UCLASS_SIMPLE_BUS, &dev);
 	     dev;
-	     ret = uclass_find_next_device(&dev)) {
+	     uclass_find_next_device(&dev)) {
 		if (device_is_compatible(dev, "qemu,platform")) {
 			struct simple_bus_plat *plat = dev_get_uclass_plat(dev);
 
boot/bootdev-uclass.c +1 -1
index 3791ebfcb42..6718c482e52 100644
@@ -216,7 +216,7 @@ void bootdev_list(bool probe)
 		if (probe)
 			ret = uclass_next_device_check(&dev);
 		else
-			ret = uclass_find_next_device(&dev);
+			uclass_find_next_device(&dev);
 	}
 	printf("---  ------  ------  --------  ------------------\n");
 	printf("(%d bootdev%s)\n", i, i != 1 ? "s" : "");
cmd/regulator.c +2 -2
index da298090bb7..db843283662 100644
@@ -97,9 +97,9 @@ static int do_list(struct cmd_tbl *cmdtp, int flag, int argc,
 	       "Parent");
 
 	for (ret = uclass_find_first_device(UCLASS_REGULATOR, &dev); dev;
-	     ret = uclass_find_next_device(&dev)) {
+	     uclass_find_next_device(&dev)) {
 		if (ret)
-			continue;
+			break;
 
 		uc_pdata = dev_get_uclass_plat(dev);
 		printf("| %-*.*s| %-*.*s| %s\n",
drivers/core/uclass.c +5 -11
index ce5e61bbaa6..5365ac68f9e 100644
@@ -261,17 +261,14 @@ int uclass_find_first_device(enum uclass_id id, struct udevice **devp)
 	return 0;
 }
 
-int uclass_find_next_device(struct udevice **devp)
+void uclass_find_next_device(struct udevice **devp)
 {
 	struct udevice *dev = *devp;
 
 	*devp = NULL;
-	if (list_is_last(&dev->uclass_node, &dev->uclass->dev_head))
-		return 0;
-
-	*devp = list_entry(dev->uclass_node.next, struct udevice, uclass_node);
-
-	return 0;
+	if (!list_is_last(&dev->uclass_node, &dev->uclass->dev_head))
+		*devp = list_entry(dev->uclass_node.next, struct udevice,
+				   uclass_node);
 }
 
 int uclass_find_device_by_namelen(enum uclass_id id, const char *name, int len,
@@ -675,11 +672,8 @@ int uclass_first_device_check(enum uclass_id id, struct udevice **devp)
 
 int uclass_next_device_check(struct udevice **devp)
 {
-	int ret;
+	uclass_find_next_device(devp);
 
-	ret = uclass_find_next_device(devp);
-	if (ret)
-		return ret;
 	if (!*devp)
 		return 0;
 
drivers/power/regulator/regulator-uclass.c +6 -4
index 09567eb9dbb..eac025c9c02 100644
@@ -261,10 +261,10 @@ int regulator_get_by_platname(const char *plat_name, struct udevice **devp)
 	*devp = NULL;
 
 	for (ret = uclass_find_first_device(UCLASS_REGULATOR, &dev); dev;
-	     ret = uclass_find_next_device(&dev)) {
+	     uclass_find_next_device(&dev)) {
 		if (ret) {
 			dev_dbg(dev, "ret=%d\n", ret);
-			continue;
+			break;
 		}
 
 		uc_pdata = dev_get_uclass_plat(dev);
@@ -411,8 +411,10 @@ static bool regulator_name_is_unique(struct udevice *check_dev,
 	int len;
 
 	for (ret = uclass_find_first_device(UCLASS_REGULATOR, &dev); dev;
-	     ret = uclass_find_next_device(&dev)) {
-		if (ret || dev == check_dev)
+	     uclass_find_next_device(&dev)) {
+		if (ret)
+			break;
+		if (dev == check_dev)
 			continue;
 
 		uc_pdata = dev_get_uclass_plat(dev);
drivers/remoteproc/rproc-uclass.c +4 -2
index 3233ff80419..7916cb27e3d 100644
@@ -56,8 +56,10 @@ static int for_each_remoteproc_device(int (*fn) (struct udevice *dev,
 	int ret;
 
 	for (ret = uclass_find_first_device(UCLASS_REMOTEPROC, &dev); dev;
-	     ret = uclass_find_next_device(&dev)) {
-		if (ret || dev == skip_dev)
+	     uclass_find_next_device(&dev)) {
+		if (ret)
+			return ret;
+		if (dev == skip_dev)
 			continue;
 		uc_pdata = dev_get_uclass_plat(dev);
 		ret = fn(dev, uc_pdata, data);
include/dm/uclass-internal.h +1 -3
index 3ddcdd21439..9cb3f090271 100644
@@ -149,10 +149,8 @@ int uclass_find_first_device(enum uclass_id id, struct udevice **devp);
  *
  * The device is not prepared for use - this is an internal function.
  * The function uclass_get_device_tail() can be used to probe the device.
- *
- * Return: 0 if OK (found or not found), -ve on error
  */
-int uclass_find_next_device(struct udevice **devp);
+void uclass_find_next_device(struct udevice **devp);
 
 /**
  * uclass_find_device_by_namelen() - Find uclass device based on ID and name
test/dm/core.c +14 -14
index 959b834576f..201daee6836 100644
@@ -737,7 +737,7 @@ static int dm_test_device_reparent(struct unit_test_state *uts)
 	/* try to get devices */
 	for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
 	     dev;
-	     ret = uclass_find_next_device(&dev)) {
+	     uclass_find_next_device(&dev)) {
 		ut_assert(!ret);
 		ut_assertnonnull(dev);
 	}
@@ -746,7 +746,7 @@ static int dm_test_device_reparent(struct unit_test_state *uts)
 	/* try to get devices */
 	for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
 	     dev;
-	     ret = uclass_find_next_device(&dev)) {
+	     uclass_find_next_device(&dev)) {
 		ut_assert(!ret);
 		ut_assertnonnull(dev);
 	}
@@ -756,7 +756,7 @@ static int dm_test_device_reparent(struct unit_test_state *uts)
 	/* try to get devices */
 	for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
 	     dev;
-	     ret = uclass_find_next_device(&dev)) {
+	     uclass_find_next_device(&dev)) {
 		ut_assert(!ret);
 		ut_assertnonnull(dev);
 	}
@@ -765,7 +765,7 @@ static int dm_test_device_reparent(struct unit_test_state *uts)
 	/* try to get devices */
 	for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
 	     dev;
-	     ret = uclass_find_next_device(&dev)) {
+	     uclass_find_next_device(&dev)) {
 		ut_assert(!ret);
 		ut_assertnonnull(dev);
 	}
@@ -775,7 +775,7 @@ static int dm_test_device_reparent(struct unit_test_state *uts)
 	/* try to get devices */
 	for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
 	     dev;
-	     ret = uclass_find_next_device(&dev)) {
+	     uclass_find_next_device(&dev)) {
 		ut_assert(!ret);
 		ut_assertnonnull(dev);
 	}
@@ -784,7 +784,7 @@ static int dm_test_device_reparent(struct unit_test_state *uts)
 	/* try to get devices */
 	for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
 	     dev;
-	     ret = uclass_find_next_device(&dev)) {
+	     uclass_find_next_device(&dev)) {
 		ut_assert(!ret);
 		ut_assertnonnull(dev);
 	}
@@ -794,7 +794,7 @@ static int dm_test_device_reparent(struct unit_test_state *uts)
 	/* try to get devices */
 	for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
 	     dev;
-	     ret = uclass_find_next_device(&dev)) {
+	     uclass_find_next_device(&dev)) {
 		ut_assert(!ret);
 		ut_assertnonnull(dev);
 	}
@@ -803,7 +803,7 @@ static int dm_test_device_reparent(struct unit_test_state *uts)
 	/* try to get devices */
 	for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
 	     dev;
-	     ret = uclass_find_next_device(&dev)) {
+	     uclass_find_next_device(&dev)) {
 		ut_assert(!ret);
 		ut_assertnonnull(dev);
 	}
@@ -812,7 +812,7 @@ static int dm_test_device_reparent(struct unit_test_state *uts)
 	/* try to get devices */
 	for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
 	     dev;
-	     ret = uclass_find_next_device(&dev)) {
+	     uclass_find_next_device(&dev)) {
 		ut_assert(!ret);
 		ut_assertnonnull(dev);
 	}
@@ -820,7 +820,7 @@ static int dm_test_device_reparent(struct unit_test_state *uts)
 	ut_assertok(device_remove(top[2], DM_REMOVE_NORMAL));
 	for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
 	     dev;
-	     ret = uclass_find_next_device(&dev)) {
+	     uclass_find_next_device(&dev)) {
 		ut_assert(!ret);
 		ut_assertnonnull(dev);
 	}
@@ -829,7 +829,7 @@ static int dm_test_device_reparent(struct unit_test_state *uts)
 	/* try to get devices */
 	for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
 	     dev;
-	     ret = uclass_find_next_device(&dev)) {
+	     uclass_find_next_device(&dev)) {
 		ut_assert(!ret);
 		ut_assertnonnull(dev);
 	}
@@ -838,7 +838,7 @@ static int dm_test_device_reparent(struct unit_test_state *uts)
 	/* try to get devices */
 	for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
 	     dev;
-	     ret = uclass_find_next_device(&dev)) {
+	     uclass_find_next_device(&dev)) {
 		ut_assert(!ret);
 		ut_assertnonnull(dev);
 	}
@@ -1092,7 +1092,7 @@ static int dm_test_uclass_devices_find(struct unit_test_state *uts)
 
 	for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
 	     dev;
-	     ret = uclass_find_next_device(&dev)) {
+	     uclass_find_next_device(&dev)) {
 		ut_assert(!ret);
 		ut_assertnonnull(dev);
 	}
@@ -1123,7 +1123,7 @@ static int dm_test_uclass_devices_find_by_name(struct unit_test_state *uts)
 	*/
 	for (ret = uclass_find_first_device(UCLASS_TEST_FDT, &testdev);
 	     testdev;
-	     ret = uclass_find_next_device(&testdev)) {
+	     uclass_find_next_device(&testdev)) {
 		ut_assertok(ret);
 		ut_assertnonnull(testdev);
 
Signature · 1 line
2.39.5
#3 lore raw

Re: [PATCH v2 2/2] uclass: Cleanup uclass_find_next_device

Hi Andrew,

Quoted 36 lines · Andrew Goodbody

uclass_find_next_device always returns 0, so instead make it a void and update calling sites.

---
  board/emulation/qemu-ppce500/qemu-ppce500.c |  4 ++--
  boot/bootdev-uclass.c                       |  2 +-
  cmd/regulator.c                             |  4 ++--
  drivers/core/uclass.c                       | 16 +++++-----------
  drivers/power/regulator/regulator-uclass.c  | 10 ++++++----
  drivers/remoteproc/rproc-uclass.c           |  6 ++++--
  include/dm/uclass-internal.h                |  4 +---
  test/dm/core.c                              | 28 ++++++++++++++--------------
  8 files changed, 35 insertions(+), 39 deletions(-)
board/emulation/qemu-ppce500/qemu-ppce500.c +2 -2
index 40d295dbf06..58de4a05296 100644
@@ -170,9 +170,9 @@ int misc_init_r(void)
  	 * Detect the presence of the platform bus node, and
  	 * create a virtual memory mapping for it.
  	 */
-	for (ret = uclass_find_first_device(UCLASS_SIMPLE_BUS, &dev);
+	for (uclass_find_first_device(UCLASS_SIMPLE_BUS, &dev);
  	     dev;
-	     ret = uclass_find_next_device(&dev)) {
+	     uclass_find_next_device(&dev)) {
  		if (device_is_compatible(dev, "qemu,platform")) {
  			struct simple_bus_plat *plat = dev_get_uclass_plat(dev);
 
boot/bootdev-uclass.c +0 -0
index 3791ebfcb42..6718c482e52 100644

boot/bootdev-uclass.c void bootdev_list(bool probe) · line 219

Quoted 5 lines
boot/bootdev-uclass.c +1 -1
@@ -216,7 +216,7 @@ void bootdev_list(bool probe)
  		if (probe)
  			ret = uclass_next_device_check(&dev);
  		else
-			ret = uclass_find_next_device(&dev);
+			uclass_find_next_device(&dev);

I think we need to ret = 0 here as well? Otherwise the printf at the top of the for-loop will return whatever was the last return value?

Quoted 8 lines
boot/bootdev-uclass.c +0 -0
  	}
  	printf("---  ------  ------  --------  ------------------\n");
  	printf("(%d bootdev%s)\n", i, i != 1 ? "s" : "");
cmd/regulator.c +0 -0
index da298090bb7..db843283662 100644

cmd/regulator.c static int do_list(struct cmd_tbl *cmdtp, int flag, int argc, · line 102

Quoted 8 lines
cmd/regulator.c +2 -2
@@ -97,9 +97,9 @@ static int do_list(struct cmd_tbl *cmdtp, int flag, int argc,
  	       "Parent");
 
  	for (ret = uclass_find_first_device(UCLASS_REGULATOR, &dev); dev;
-	     ret = uclass_find_next_device(&dev)) {
+	     uclass_find_next_device(&dev)) {
  		if (ret)
-			continue;
+			break;

I think it would make this more readable by having

ret = uclass_find_first_device(UCLASS_REGULATOR, &dev); if (ret)

    return ret;
for (; dev; uclass_find_next_device(&dev)) {
    uc_pdata...
}

return ret;

What do you think? This also avoids checking for ret in every loop considering it won't ever change.

[...]

Quoted 5 lines
drivers/power/regulator/regulator-uclass.c +0 -0
index 09567eb9dbb..eac025c9c02 100644

drivers/power/regulator/regulator-uclass.c int regulator_get_by_platname(const char *plat_name, struct udevice **devp) · line 268

Quoted 10 lines
drivers/power/regulator/regulator-uclass.c +2 -2
@@ -261,10 +261,10 @@ int regulator_get_by_platname(const char *plat_name, struct udevice **devp)
  	*devp = NULL;
 
  	for (ret = uclass_find_first_device(UCLASS_REGULATOR, &dev); dev;
-	     ret = uclass_find_next_device(&dev)) {
+	     uclass_find_next_device(&dev)) {
  		if (ret) {
  			dev_dbg(dev, "ret=%d\n", ret);
-			continue;
+			break;
  		}

Same here.

drivers/power/regulator/regulator-uclass.c static bool regulator_name_is_unique(struct udevice *check_dev, · line 416

Quoted 11 lines
drivers/power/regulator/regulator-uclass.c +3 -2
  		uc_pdata = dev_get_uclass_plat(dev);
@@ -411,8 +411,10 @@ static bool regulator_name_is_unique(struct udevice *check_dev,
  	int len;
 
  	for (ret = uclass_find_first_device(UCLASS_REGULATOR, &dev); dev;
-	     ret = uclass_find_next_device(&dev)) {
-		if (ret || dev == check_dev)
+	     uclass_find_next_device(&dev)) {
+		if (ret)
+			break;

Ditto.

Quoted 9 lines
drivers/power/regulator/regulator-uclass.c +1 -0
+		if (dev == check_dev)
  			continue;
 
  		uc_pdata = dev_get_uclass_plat(dev);
drivers/remoteproc/rproc-uclass.c +0 -0
index 3233ff80419..7916cb27e3d 100644

drivers/remoteproc/rproc-uclass.c static int for_each_remoteproc_device(int (*fn) (struct udevice *dev, · line 61

Quoted 8 lines
drivers/remoteproc/rproc-uclass.c +3 -2
@@ -56,8 +56,10 @@ static int for_each_remoteproc_device(int (*fn) (struct udevice *dev,
  	int ret;
 
  	for (ret = uclass_find_first_device(UCLASS_REMOTEPROC, &dev); dev;
-	     ret = uclass_find_next_device(&dev)) {
-		if (ret || dev == skip_dev)
+	     uclass_find_next_device(&dev)) {
+		if (ret)
+			return ret;

Ditto.

Quoted 25 lines
drivers/remoteproc/rproc-uclass.c +1 -0
+		if (dev == skip_dev)
  			continue;
  		uc_pdata = dev_get_uclass_plat(dev);
  		ret = fn(dev, uc_pdata, data);
include/dm/uclass-internal.h +1 -3
index 3ddcdd21439..9cb3f090271 100644
@@ -149,10 +149,8 @@ int uclass_find_first_device(enum uclass_id id, struct udevice **devp);
   *
   * The device is not prepared for use - this is an internal function.
   * The function uclass_get_device_tail() can be used to probe the device.
- *
- * Return: 0 if OK (found or not found), -ve on error
   */
-int uclass_find_next_device(struct udevice **devp);
+void uclass_find_next_device(struct udevice **devp);
 
  /**
   * uclass_find_device_by_namelen() - Find uclass device based on ID and name
test/dm/core.c +0 -0
index 959b834576f..201daee6836 100644

test/dm/core.c static int dm_test_device_reparent(struct unit_test_state *uts) · line 741

Quoted 6 lines
test/dm/core.c +1 -1
@@ -737,7 +737,7 @@ static int dm_test_device_reparent(struct unit_test_state *uts)
  	/* try to get devices */
  	for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
  	     dev;
-	     ret = uclass_find_next_device(&dev)) {
+	     uclass_find_next_device(&dev)) {
  		ut_assert(!ret);

Ditto for all the tests in test/dm/core.c.

Cheers,
Quentin

#4 lore raw

Re: [PATCH v2 2/2] uclass: Cleanup uclass_find_next_device

Quoted 38 lines · Quentin Schulz

Hi Andrew,

Quoted 35 lines · Andrew Goodbody

uclass_find_next_device always returns 0, so instead make it a void and update calling sites.

---
  board/emulation/qemu-ppce500/qemu-ppce500.c |  4 ++-- boot/bootdev-uclass.c                       |  2 +- cmd/regulator.c                             |  4 ++-- drivers/core/uclass.c                       | 16 +++++----------- drivers/power/regulator/regulator-uclass.c  | 10 ++++++---- drivers/remoteproc/rproc-uclass.c           |  6 ++++-- include/dm/uclass-internal.h                |  4 +--- test/dm/core.c                              | 28 +++++++++++++
+--------------

  8 files changed, 35 insertions(+), 39 deletions(-)
board/emulation/qemu-ppce500/qemu-ppce500.c +2 -2
index 40d295dbf06..58de4a05296 100644
@@ -170,9 +170,9 @@ int misc_init_r(void)
        * Detect the presence of the platform bus node, and
        * create a virtual memory mapping for it.
        */
-    for (ret = uclass_find_first_device(UCLASS_SIMPLE_BUS, &dev);
+    for (uclass_find_first_device(UCLASS_SIMPLE_BUS, &dev);
            dev;
-         ret = uclass_find_next_device(&dev)) {
+         uclass_find_next_device(&dev)) {
           if (device_is_compatible(dev, "qemu,platform")) {
               struct simple_bus_plat *plat = dev_get_uclass_plat(dev);
boot/bootdev-uclass.c +0 -0
index 3791ebfcb42..6718c482e52 100644
Quoted 8 lines
Quoted 6 lines
boot/bootdev-uclass.c +0 -0
@@ -216,7 +216,7 @@ void bootdev_list(bool probe)
           if (probe)
               ret = uclass_next_device_check(&dev);

          else
-            ret = uclass_find_next_device(&dev);
+            uclass_find_next_device(&dev);

I think we need to ret = 0 here as well? Otherwise the printf at the top of the for-loop will return whatever was the last return value?

Yes, will fix.

Quoted 23 lines
Quoted 8 lines

      }
      printf("---  ------  ------  --------  ------------------\n"); printf("(%d bootdev%s)\n", i, i != 1 ? "s" : "");

cmd/regulator.c +0 -0
index da298090bb7..db843283662 100644

cmd/regulator.c static int do_list(struct cmd_tbl *cmdtp, int flag, · line 102

Quoted 8 lines
cmd/regulator.c +2 -2
@@ -97,9 +97,9 @@ static int do_list(struct cmd_tbl *cmdtp, int flag, 
 int argc,
              "Parent");
       for (ret = uclass_find_first_device(UCLASS_REGULATOR, &dev); dev;
-         ret = uclass_find_next_device(&dev)) {
+         uclass_find_next_device(&dev)) {
           if (ret)
-            continue;
+            break;

I think it would make this more readable by having

ret = uclass_find_first_device(UCLASS_REGULATOR, &dev); if (ret)
    return ret;

Quoted 7 lines

for (; dev; uclass_find_next_device(&dev)) {
    uc_pdata...
}

return ret;

What do you think? This also avoids checking for ret in every loop considering it won't ever change.

OK, will change as suggested.

Quoted 78 lines

[...]

Quoted 5 lines
drivers/power/regulator/regulator-uclass.c +0 -0
index 09567eb9dbb..eac025c9c02 100644

drivers/power/regulator/regulator-uclass.c int regulator_get_by_platname(const char · line 268

Quoted 10 lines
drivers/power/regulator/regulator-uclass.c +2 -2
@@ -261,10 +261,10 @@ int regulator_get_by_platname(const char 
 *plat_name, struct udevice **devp)
       *devp = NULL;
       for (ret = uclass_find_first_device(UCLASS_REGULATOR, &dev); dev;
-         ret = uclass_find_next_device(&dev)) {
+         uclass_find_next_device(&dev)) {
           if (ret) {
               dev_dbg(dev, "ret=%d\n", ret);
-            continue;
+            break;
           }

Same here.

drivers/power/regulator/regulator-uclass.c static bool regulator_name_is_unique(struct · line 416

Quoted 10 lines
drivers/power/regulator/regulator-uclass.c +3 -2
           uc_pdata = dev_get_uclass_plat(dev);
@@ -411,8 +411,10 @@ static bool regulator_name_is_unique(struct 
 udevice *check_dev,
       int len;
       for (ret = uclass_find_first_device(UCLASS_REGULATOR, &dev); dev;
-         ret = uclass_find_next_device(&dev)) {
-        if (ret || dev == check_dev)
+         uclass_find_next_device(&dev)) {
+        if (ret)
+            break;

Ditto.

Quoted 8 lines
drivers/power/regulator/regulator-uclass.c +1 -0
+        if (dev == check_dev)
               continue;
           uc_pdata = dev_get_uclass_plat(dev);
drivers/remoteproc/rproc-uclass.c +0 -0
index 3233ff80419..7916cb27e3d 100644

drivers/remoteproc/rproc-uclass.c static int for_each_remoteproc_device(int (*fn) · line 61

Quoted 8 lines
drivers/remoteproc/rproc-uclass.c +3 -2
@@ -56,8 +56,10 @@ static int for_each_remoteproc_device(int (*fn) 
 (struct udevice *dev,
       int ret;
       for (ret = uclass_find_first_device(UCLASS_REMOTEPROC, &dev); dev;
-         ret = uclass_find_next_device(&dev)) {
-        if (ret || dev == skip_dev)
+         uclass_find_next_device(&dev)) {
+        if (ret)
+            return ret;

Ditto.

Quoted 26 lines
drivers/remoteproc/rproc-uclass.c +1 -0
+        if (dev == skip_dev)
               continue;
           uc_pdata = dev_get_uclass_plat(dev);
           ret = fn(dev, uc_pdata, data);
include/dm/uclass-internal.h +1 -3
index 3ddcdd21439..9cb3f090271 100644
@@ -149,10 +149,8 @@ int uclass_find_first_device(enum uclass_id id, 
 struct udevice **devp);
    *
    * The device is not prepared for use - this is an internal function.
    * The function uclass_get_device_tail() can be used to probe the device.
- *
- * Return: 0 if OK (found or not found), -ve on error
    */
-int uclass_find_next_device(struct udevice **devp);
+void uclass_find_next_device(struct udevice **devp);
   /**
    * uclass_find_device_by_namelen() - Find uclass device based on ID and name
test/dm/core.c +0 -0
index 959b834576f..201daee6836 100644
@@ -737,7 +737,7 @@ static int dm_test_device_reparent(struct 
 unit_test_state *uts)
Quoted 8 lines

test/dm/core.c static int dm_test_device_reparent(struct unit_test_state *uts) · line 741

Quoted 6 lines
test/dm/core.c +1 -1
       /* try to get devices */
       for (ret = uclass_find_first_device(UCLASS_TEST, &dev);
            dev;
-         ret = uclass_find_next_device(&dev)) {
+         uclass_find_next_device(&dev)) {
           ut_assert(!ret);

Ditto for all the tests in test/dm/core.c.

The for loops in test/dm/core.c mostly reduce to being empty as the only test left inside is that dev is not NULL, but in that case the for loop terminates so the test can never fail. So the for loops can mostly be removed as they do nothing.

Thanks,
Andrew

Quoted 2 lines

Cheers,
Quentin