Skip to content

Commit 4954937

Browse files
hramrachsjg20
authored andcommittedOct 29, 2022
dm: treewide: Do not use the return value of simple uclass iterator
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 <[email protected]> Reviewed-by: Simon Glass <[email protected]>
1 parent aa5511e commit 4954937

File tree

5 files changed

+17
-37
lines changed

5 files changed

+17
-37
lines changed
 

‎cmd/virtio.c

+3-6
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,15 @@ static int do_virtio(struct cmd_tbl *cmdtp, int flag, int argc,
2323
* device_probe() for children (i.e. virtio devices)
2424
*/
2525
struct udevice *bus, *child;
26-
int ret;
2726

28-
ret = uclass_first_device(UCLASS_VIRTIO, &bus);
29-
if (ret)
27+
uclass_first_device(UCLASS_VIRTIO, &bus);
28+
if (!bus)
3029
return CMD_RET_FAILURE;
3130

3231
while (bus) {
3332
device_foreach_child_probe(child, bus)
3433
;
35-
ret = uclass_next_device(&bus);
36-
if (ret)
37-
break;
34+
uclass_next_device(&bus);
3835
}
3936

4037
return CMD_RET_SUCCESS;

‎drivers/dma/dma-uclass.c

+3-4
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,9 @@ int dma_get_cfg(struct dma *dma, u32 cfg_id, void **cfg_data)
210210
int dma_get_device(u32 transfer_type, struct udevice **devp)
211211
{
212212
struct udevice *dev;
213-
int ret;
214213

215-
for (ret = uclass_first_device(UCLASS_DMA, &dev); dev && !ret;
216-
ret = uclass_next_device(&dev)) {
214+
for (uclass_first_device(UCLASS_DMA, &dev); dev;
215+
uclass_next_device(&dev)) {
217216
struct dma_dev_priv *uc_priv;
218217

219218
uc_priv = dev_get_uclass_priv(dev);
@@ -229,7 +228,7 @@ int dma_get_device(u32 transfer_type, struct udevice **devp)
229228

230229
*devp = dev;
231230

232-
return ret;
231+
return 0;
233232
}
234233

235234
int dma_memcpy(void *dst, void *src, size_t len)

‎drivers/gpio/gpio-uclass.c

+6-8
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,10 @@ static int gpio_to_device(unsigned int gpio, struct gpio_desc *desc)
5959
{
6060
struct gpio_dev_priv *uc_priv;
6161
struct udevice *dev;
62-
int ret;
6362

64-
for (ret = uclass_first_device(UCLASS_GPIO, &dev);
63+
for (uclass_first_device(UCLASS_GPIO, &dev);
6564
dev;
66-
ret = uclass_next_device(&dev)) {
65+
uclass_next_device(&dev)) {
6766
uc_priv = dev_get_uclass_priv(dev);
6867
if (gpio >= uc_priv->gpio_base &&
6968
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)
7372
}
7473

7574
/* No such GPIO */
76-
return ret ? ret : -ENOENT;
75+
return -ENOENT;
7776
}
7877

7978
#if CONFIG_IS_ENABLED(DM_GPIO_LOOKUP_LABEL)
@@ -119,12 +118,11 @@ int dm_gpio_lookup_name(const char *name, struct gpio_desc *desc)
119118
struct udevice *dev;
120119
ulong offset;
121120
int numeric;
122-
int ret;
123121

124122
numeric = isdigit(*name) ? dectoul(name, NULL) : -1;
125-
for (ret = uclass_first_device(UCLASS_GPIO, &dev);
123+
for (uclass_first_device(UCLASS_GPIO, &dev);
126124
dev;
127-
ret = uclass_next_device(&dev)) {
125+
uclass_next_device(&dev)) {
128126
int len;
129127

130128
uc_priv = dev_get_uclass_priv(dev);
@@ -152,7 +150,7 @@ int dm_gpio_lookup_name(const char *name, struct gpio_desc *desc)
152150
}
153151

154152
if (!dev)
155-
return ret ? ret : -EINVAL;
153+
return -EINVAL;
156154

157155
gpio_desc_init(desc, dev, offset);
158156

‎drivers/pci/pci-uclass.c

+3-12
Original file line numberDiff line numberDiff line change
@@ -1211,7 +1211,6 @@ static int pci_bridge_write_config(struct udevice *bus, pci_dev_t bdf,
12111211
static int skip_to_next_device(struct udevice *bus, struct udevice **devp)
12121212
{
12131213
struct udevice *dev;
1214-
int ret = 0;
12151214

12161215
/*
12171216
* 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)
12231222
*devp = dev;
12241223
return 0;
12251224
}
1226-
ret = uclass_next_device(&bus);
1227-
if (ret)
1228-
return ret;
1225+
uclass_next_device(&bus);
12291226
}
12301227

12311228
return 0;
@@ -1235,7 +1232,6 @@ int pci_find_next_device(struct udevice **devp)
12351232
{
12361233
struct udevice *child = *devp;
12371234
struct udevice *bus = child->parent;
1238-
int ret;
12391235

12401236
/* First try all the siblings */
12411237
*devp = NULL;
@@ -1248,22 +1244,17 @@ int pci_find_next_device(struct udevice **devp)
12481244
}
12491245

12501246
/* We ran out of siblings. Try the next bus */
1251-
ret = uclass_next_device(&bus);
1252-
if (ret)
1253-
return ret;
1247+
uclass_next_device(&bus);
12541248

12551249
return bus ? skip_to_next_device(bus, devp) : 0;
12561250
}
12571251

12581252
int pci_find_first_device(struct udevice **devp)
12591253
{
12601254
struct udevice *bus;
1261-
int ret;
12621255

12631256
*devp = NULL;
1264-
ret = uclass_first_device(UCLASS_PCI, &bus);
1265-
if (ret)
1266-
return ret;
1257+
uclass_first_device(UCLASS_PCI, &bus);
12671258

12681259
return skip_to_next_device(bus, devp);
12691260
}

‎drivers/w1/w1-uclass.c

+2-7
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,10 @@ int w1_bus_find_dev(const struct udevice *bus, u64 id, struct udevice
3636
{
3737
struct udevice *dev;
3838
u8 family = id & 0xff;
39-
int ret;
4039

41-
for (ret = uclass_first_device(UCLASS_W1_EEPROM, &dev);
42-
!ret && dev;
40+
for (uclass_first_device(UCLASS_W1_EEPROM, &dev);
41+
dev;
4342
uclass_next_device(&dev)) {
44-
if (ret || !dev) {
45-
debug("cannot find w1 eeprom dev\n");
46-
return -ENODEV;
47-
}
4843

4944
if (dev_get_driver_data(dev) == family) {
5045
*devp = dev;

0 commit comments

Comments
 (0)
Please sign in to comment.