Commit 65b60897a700e63af02ba46249de60ed3f79ca41
Committed by
Tom Rini
1 parent
586d4b010e
Exists in
smarc_8mq_lf_v2020.04
and in
11 other branches
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>
Showing 1 changed file with 8 additions and 6 deletions Side-by-side Diff
drivers/w1/w1-uclass.c
... | ... | @@ -115,17 +115,19 @@ |
115 | 115 | struct udevice *dev; |
116 | 116 | |
117 | 117 | for (ret = uclass_first_device(UCLASS_W1, &dev); |
118 | - !ret; | |
119 | - uclass_next_device(&dev), i++) { | |
120 | - if (ret) { | |
121 | - debug("Cannot find w1 bus %d\n", busnum); | |
122 | - return ret; | |
123 | - } | |
118 | + dev && !ret; | |
119 | + ret = uclass_next_device(&dev), i++) { | |
124 | 120 | if (i == busnum) { |
125 | 121 | *busp = dev; |
126 | 122 | return 0; |
127 | 123 | } |
128 | 124 | } |
125 | + | |
126 | + if (!ret) { | |
127 | + debug("Cannot find w1 bus %d\n", busnum); | |
128 | + ret = -ENODEV; | |
129 | + } | |
130 | + | |
129 | 131 | return ret; |
130 | 132 | } |
131 | 133 |