w1: Fix bus counting in w1_get_bus

Use uclass_first_device_check/uclass_next_device_check to correctly
count buses that fail to probe.

Fixes: d3e19cf919 ("w1: Add 1-Wire uclass")
Signed-off-by: Michal Suchanek <msuchanek@suse.de>
Reviewed-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Michal Suchanek
2022-10-12 21:57:57 +02:00
committed by Simon Glass
parent f426423471
commit 9244645f92

View File

@@ -16,6 +16,7 @@
#include <common.h> #include <common.h>
#include <dm.h> #include <dm.h>
#include <errno.h>
#include <log.h> #include <log.h>
#include <w1.h> #include <w1.h>
#include <w1-eeprom.h> #include <w1-eeprom.h>
@@ -182,24 +183,25 @@ static int w1_enumerate(struct udevice *bus)
int w1_get_bus(int busnum, struct udevice **busp) int w1_get_bus(int busnum, struct udevice **busp)
{ {
int ret, i = 0; int ret, i = 0;
struct udevice *dev; struct udevice *dev;
for (ret = uclass_first_device(UCLASS_W1, &dev); for (ret = uclass_first_device_check(UCLASS_W1, &dev);
dev && !ret; dev;
ret = uclass_next_device(&dev), i++) { ret = uclass_next_device_check(&dev), i++) {
if (i == busnum) { if (i == busnum) {
if (ret) {
debug("Cannot probe w1 bus %d: %d (%s)\n",
busnum, ret, errno_str(ret));
return ret;
}
*busp = dev; *busp = dev;
return 0; return 0;
} }
} }
if (!ret) { debug("Cannot find w1 bus %d\n", busnum);
debug("Cannot find w1 bus %d\n", busnum);
ret = -ENODEV;
}
return ret; return -ENODEV;
} }
u8 w1_get_device_family(struct udevice *dev) u8 w1_get_device_family(struct udevice *dev)