Skip to content

Commit

Permalink
w1: fix data abort if no one wire bus master present
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Eugen Hristev <[email protected]>
  • Loading branch information
Martin Fuzzey authored and trini committed Nov 1, 2018
1 parent 586d4b0 commit 65b6089
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions drivers/w1/w1-uclass.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,17 +115,19 @@ int w1_get_bus(int busnum, struct udevice **busp)
struct udevice *dev;

for (ret = uclass_first_device(UCLASS_W1, &dev);
!ret;
uclass_next_device(&dev), i++) {
if (ret) {
debug("Cannot find w1 bus %d\n", busnum);
return ret;
}
dev && !ret;
ret = uclass_next_device(&dev), i++) {
if (i == busnum) {
*busp = dev;
return 0;
}
}

if (!ret) {
debug("Cannot find w1 bus %d\n", busnum);
ret = -ENODEV;
}

return ret;
}

Expand Down

0 comments on commit 65b6089

Please sign in to comment.