summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
authorMartin Fuzzey <martin.fuzzey@flowbird.group>2018-10-22 18:31:08 +0200
committerTom Rini <trini@konsulko.com>2018-11-01 10:02:10 -0400
commit65b60897a700e63af02ba46249de60ed3f79ca41 (patch)
tree12adeaae1bc8f2e486d4ed165dd0ec3c799e657a /drivers
parent586d4b010e8ff8894c29c65b68f2afb518a783c8 (diff)
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>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/w1/w1-uclass.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/drivers/w1/w1-uclass.c b/drivers/w1/w1-uclass.c
index aecf7fec77..cb41b68eff 100644
--- a/drivers/w1/w1-uclass.c
+++ b/drivers/w1/w1-uclass.c
@@ -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;
}