]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: treewide: Do not opencode uclass_probe_all()
authorMichal Suchanek <msuchanek@suse.de>
Wed, 12 Oct 2022 19:57:51 +0000 (21:57 +0200)
committerSimon Glass <sjg@chromium.org>
Tue, 18 Oct 2022 03:17:12 +0000 (21:17 -0600)
We already have a function for probing all devices of a specific class,
use it.

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/cpu/cpu-uclass.c
drivers/virtio/virtio-uclass.c
test/dm/core.c
test/test-main.c

index 71e5900d70e88ac83855445c7a28d3218b676258..a7548325265db7736fe783168a873f81dff7604c 100644 (file)
@@ -20,25 +20,13 @@ DECLARE_GLOBAL_DATA_PTR;
 
 int cpu_probe_all(void)
 {
-       struct udevice *cpu;
-       int ret;
+       int ret = uclass_probe_all(UCLASS_CPU);
 
-       ret = uclass_first_device(UCLASS_CPU, &cpu);
        if (ret) {
-               debug("%s: No CPU found (err = %d)\n", __func__, ret);
-               return ret;
-       }
-
-       while (cpu) {
-               ret = uclass_next_device(&cpu);
-               if (ret) {
-                       debug("%s: Error while probing CPU (err = %d)\n",
-                             __func__, ret);
-                       return ret;
-               }
+               debug("%s: Error while probing CPUs (err = %d %s)\n",
+                     __func__, ret, errno_str(ret));
        }
-
-       return 0;
+       return ret;
 }
 
 int cpu_is_current(struct udevice *cpu)
index 9e2d0e06a1e86b942599135408a2ad52141ec027..da4f2f26a632e51bbd19eb071fdcc45f13f94ca7 100644 (file)
@@ -183,21 +183,8 @@ void virtio_driver_features_init(struct virtio_dev_priv *priv,
 
 int virtio_init(void)
 {
-       struct udevice *bus;
-       int ret;
-
        /* Enumerate all known virtio devices */
-       ret = uclass_first_device(UCLASS_VIRTIO, &bus);
-       if (ret)
-               return ret;
-
-       while (bus) {
-               ret = uclass_next_device(&bus);
-               if (ret)
-                       break;
-       }
-
-       return ret;
+       return uclass_probe_all(UCLASS_VIRTIO);
 }
 
 static int virtio_uclass_pre_probe(struct udevice *udev)
index fd4d7569728000645dba206b716b8bb83b5d2bee..84eb76ed5fc8f931232ac29ad1f8974fa042cb45 100644 (file)
@@ -512,23 +512,15 @@ static int dm_test_leak(struct unit_test_state *uts)
        int i;
 
        for (i = 0; i < 2; i++) {
-               struct udevice *dev;
                int ret;
-               int id;
 
                dm_leak_check_start(uts);
 
                ut_assertok(dm_scan_plat(false));
                ut_assertok(dm_scan_fdt(false));
 
-               /* Scanning the uclass is enough to probe all the devices */
-               for (id = UCLASS_ROOT; id < UCLASS_COUNT; id++) {
-                       for (ret = uclass_first_device(UCLASS_TEST, &dev);
-                            dev;
-                            ret = uclass_next_device(&dev))
-                               ;
-                       ut_assertok(ret);
-               }
+               ret = uclass_probe_all(UCLASS_TEST);
+               ut_assertok(ret);
 
                ut_assertok(dm_leak_check_end(uts));
        }
@@ -653,10 +645,7 @@ static int dm_test_children(struct unit_test_state *uts)
        ut_asserteq(2 + NODE_COUNT, dm_testdrv_op_count[DM_TEST_OP_PROBE]);
 
        /* Probe everything */
-       for (ret = uclass_first_device(UCLASS_TEST, &dev);
-            dev;
-            ret = uclass_next_device(&dev))
-               ;
+       ret = uclass_probe_all(UCLASS_TEST);
        ut_assertok(ret);
 
        ut_asserteq(total, dm_testdrv_op_count[DM_TEST_OP_PROBE]);
index d74df297c43a6a88d2e2241b2bca3bd5904a055c..a98a77d68fcbb4ded7a82e7fbd779e40661bd24f 100644 (file)
@@ -165,16 +165,7 @@ static int dm_test_post_run(struct unit_test_state *uts)
 /* Ensure all the test devices are probed */
 static int do_autoprobe(struct unit_test_state *uts)
 {
-       struct udevice *dev;
-       int ret;
-
-       /* Scanning the uclass is enough to probe all the devices */
-       for (ret = uclass_first_device(UCLASS_TEST, &dev);
-            dev;
-            ret = uclass_next_device(&dev))
-               ;
-
-       return ret;
+       return uclass_probe_all(UCLASS_TEST);
 }
 
 /*