mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-19 05:31:32 +00:00
w1: fix data abort if no one wire bus master present
When the "w1 bus" command is used with no bus master present a data abort may occur. This is because uclass_first_device() returns zero, but sets the output struct udevice pointer to NULL in the no device found case. Fix w1_get_bus() to account for this and return an error code as is expected by the callers. Signed-off-by: Martin Fuzzey <martin.fuzzey@flowbird.group> Reviewed-by: Eugen Hristev <eugen.hristev@microchip.com>
This commit is contained in:
parent
586d4b010e
commit
65b60897a7
1 changed files with 8 additions and 6 deletions
|
@ -115,17 +115,19 @@ int w1_get_bus(int busnum, struct udevice **busp)
|
||||||
struct udevice *dev;
|
struct udevice *dev;
|
||||||
|
|
||||||
for (ret = uclass_first_device(UCLASS_W1, &dev);
|
for (ret = uclass_first_device(UCLASS_W1, &dev);
|
||||||
!ret;
|
dev && !ret;
|
||||||
uclass_next_device(&dev), i++) {
|
ret = uclass_next_device(&dev), i++) {
|
||||||
if (ret) {
|
|
||||||
debug("Cannot find w1 bus %d\n", busnum);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
if (i == busnum) {
|
if (i == busnum) {
|
||||||
*busp = dev;
|
*busp = dev;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!ret) {
|
||||||
|
debug("Cannot find w1 bus %d\n", busnum);
|
||||||
|
ret = -ENODEV;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue