]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
dm: treewide: Do not use the return value of simple uclass iterator
authorMichal Suchanek <msuchanek@suse.de>
Wed, 12 Oct 2022 19:58:08 +0000 (21:58 +0200)
committerSimon Glass <sjg@chromium.org>
Sat, 29 Oct 2022 13:36:33 +0000 (07:36 -0600)
uclass_first_device/uclass_next_device return value will be removed,
don't use it.

With the current implementation dev is equivalent to !ret. It is
redundant to check both, ret check can be replaced with dev check, and
ret check inside the iteration is dead code.

Signed-off-by: Michal Suchanek <msuchanek@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
cmd/virtio.c
drivers/dma/dma-uclass.c
drivers/gpio/gpio-uclass.c
drivers/pci/pci-uclass.c
drivers/w1/w1-uclass.c

index ec87d4f02c93ccc412a234741776fe7c79d53b48..019e317e75588ff4322e5af32cd9f1a7a2421623 100644 (file)
@@ -23,18 +23,15 @@ static int do_virtio(struct cmd_tbl *cmdtp, int flag, int argc,
                 * device_probe() for children (i.e. virtio devices)
                 */
                struct udevice *bus, *child;
-               int ret;
 
-               ret = uclass_first_device(UCLASS_VIRTIO, &bus);
-               if (ret)
+               uclass_first_device(UCLASS_VIRTIO, &bus);
+               if (!bus)
                        return CMD_RET_FAILURE;
 
                while (bus) {
                        device_foreach_child_probe(child, bus)
                                ;
-                       ret = uclass_next_device(&bus);
-                       if (ret)
-                               break;
+                       uclass_next_device(&bus);
                }
 
                return CMD_RET_SUCCESS;
index 81dbb4da1074ef74a594d89007726f1e591fb50e..34f72fa5dc883acf1be2885578e4cd7dcc2208ca 100644 (file)
@@ -210,10 +210,9 @@ int dma_get_cfg(struct dma *dma, u32 cfg_id, void **cfg_data)
 int dma_get_device(u32 transfer_type, struct udevice **devp)
 {
        struct udevice *dev;
-       int ret;
 
-       for (ret = uclass_first_device(UCLASS_DMA, &dev); dev && !ret;
-            ret = uclass_next_device(&dev)) {
+       for (uclass_first_device(UCLASS_DMA, &dev); dev;
+            uclass_next_device(&dev)) {
                struct dma_dev_priv *uc_priv;
 
                uc_priv = dev_get_uclass_priv(dev);
@@ -229,7 +228,7 @@ int dma_get_device(u32 transfer_type, struct udevice **devp)
 
        *devp = dev;
 
-       return ret;
+       return 0;
 }
 
 int dma_memcpy(void *dst, void *src, size_t len)
index 65033258f47887d26f5afe1cd14c02e8ce277cb5..3a6ef3b01d530688b1b6dfda14dcfaff5715bb1f 100644 (file)
@@ -59,11 +59,10 @@ static int gpio_to_device(unsigned int gpio, struct gpio_desc *desc)
 {
        struct gpio_dev_priv *uc_priv;
        struct udevice *dev;
-       int ret;
 
-       for (ret = uclass_first_device(UCLASS_GPIO, &dev);
+       for (uclass_first_device(UCLASS_GPIO, &dev);
             dev;
-            ret = uclass_next_device(&dev)) {
+            uclass_next_device(&dev)) {
                uc_priv = dev_get_uclass_priv(dev);
                if (gpio >= uc_priv->gpio_base &&
                    gpio < uc_priv->gpio_base + uc_priv->gpio_count) {
@@ -73,7 +72,7 @@ static int gpio_to_device(unsigned int gpio, struct gpio_desc *desc)
        }
 
        /* No such GPIO */
-       return ret ? ret : -ENOENT;
+       return -ENOENT;
 }
 
 #if CONFIG_IS_ENABLED(DM_GPIO_LOOKUP_LABEL)
@@ -119,12 +118,11 @@ int dm_gpio_lookup_name(const char *name, struct gpio_desc *desc)
        struct udevice *dev;
        ulong offset;
        int numeric;
-       int ret;
 
        numeric = isdigit(*name) ? dectoul(name, NULL) : -1;
-       for (ret = uclass_first_device(UCLASS_GPIO, &dev);
+       for (uclass_first_device(UCLASS_GPIO, &dev);
             dev;
-            ret = uclass_next_device(&dev)) {
+            uclass_next_device(&dev)) {
                int len;
 
                uc_priv = dev_get_uclass_priv(dev);
@@ -152,7 +150,7 @@ int dm_gpio_lookup_name(const char *name, struct gpio_desc *desc)
        }
 
        if (!dev)
-               return ret ? ret : -EINVAL;
+               return -EINVAL;
 
        gpio_desc_init(desc, dev, offset);
 
index 6dd19650f9ce8157f72b6433a43da99f72255b8e..9343cfc62a968c0227dda6591de4fcfaad275f1a 100644 (file)
@@ -1211,7 +1211,6 @@ static int pci_bridge_write_config(struct udevice *bus, pci_dev_t bdf,
 static int skip_to_next_device(struct udevice *bus, struct udevice **devp)
 {
        struct udevice *dev;
-       int ret = 0;
 
        /*
         * Scan through all the PCI controllers. On x86 there will only be one
@@ -1223,9 +1222,7 @@ static int skip_to_next_device(struct udevice *bus, struct udevice **devp)
                        *devp = dev;
                        return 0;
                }
-               ret = uclass_next_device(&bus);
-               if (ret)
-                       return ret;
+               uclass_next_device(&bus);
        }
 
        return 0;
@@ -1235,7 +1232,6 @@ int pci_find_next_device(struct udevice **devp)
 {
        struct udevice *child = *devp;
        struct udevice *bus = child->parent;
-       int ret;
 
        /* First try all the siblings */
        *devp = NULL;
@@ -1248,9 +1244,7 @@ int pci_find_next_device(struct udevice **devp)
        }
 
        /* We ran out of siblings. Try the next bus */
-       ret = uclass_next_device(&bus);
-       if (ret)
-               return ret;
+       uclass_next_device(&bus);
 
        return bus ? skip_to_next_device(bus, devp) : 0;
 }
@@ -1258,12 +1252,9 @@ int pci_find_next_device(struct udevice **devp)
 int pci_find_first_device(struct udevice **devp)
 {
        struct udevice *bus;
-       int ret;
 
        *devp = NULL;
-       ret = uclass_first_device(UCLASS_PCI, &bus);
-       if (ret)
-               return ret;
+       uclass_first_device(UCLASS_PCI, &bus);
 
        return skip_to_next_device(bus, devp);
 }
index de4f25bcf95766099ba1d6eb1e5ea8e6cf60815e..a4247ecd62330e01ee4bc5d0db68ca21831fc968 100644 (file)
@@ -36,15 +36,10 @@ int w1_bus_find_dev(const struct udevice *bus, u64 id, struct udevice
 {
        struct udevice *dev;
        u8 family = id & 0xff;
-       int ret;
 
-       for (ret = uclass_first_device(UCLASS_W1_EEPROM, &dev);
-               !ret && dev;
+       for (uclass_first_device(UCLASS_W1_EEPROM, &dev);
+               dev;
                uclass_next_device(&dev)) {
-               if (ret || !dev) {
-                       debug("cannot find w1 eeprom dev\n");
-                       return -ENODEV;
-               }
 
                if (dev_get_driver_data(dev) == family) {
                        *devp = dev;