w1-eeprom: ds24xxx: fix data abort in ds24xxx_probe()
PATCH 1/1 w1-eeprom: ds24xxx: fix data abort in ds24xxx_probe()
Data abort was occurring when using "w1 bus" with a DS24B33 present.
The abort occurred in the ds24xxx_probe() because the struct w1_device pointer was NULL. This is because that structure is allocated by the parent device uclass (by .per_child_platdata_auto_alloc_size) and thus the correct accessor is dev_get_parent_platdata() not dev_get_platdata()
--- drivers/w1-eeprom/ds24xxx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/w1-eeprom/ds24xxx.c +1 -1
@@ -31,7 +31,7 @@ static int ds24xxx_probe(struct udevice *dev) {struct w1_device *w1; - w1 =dev_get_platdata (dev); + w1 =dev_get_parent_platdata (dev); w1->id =0 ;return 0 ; }
Signature · 1 line
1.9.1
PATCH 1/1 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.
--- drivers/w1/w1-uclass.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/w1/w1-uclass.c +8 -6
@@ -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; }
Signature · 1 line
1.9.1
PATCH 1/1 w1: fix data abort if no one wire bus master present
Quoted 27 lines · Martin Fuzzey
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]>--- drivers/w1/w1-uclass.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)drivers/w1/w1-uclass.c +0
-5@@ -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;
drivers/w1/w1-uclass.c int w1_get_bus(int busnum, struct udevice **busp) · line 126
Quoted 10 lines
drivers/w1/w1-uclass.c +4
-1- } + dev && !ret; + ret = uclass_next_device(&dev), i++) {if (i == busnum) { *busp = dev;return 0 ; } } + +if (!ret) {
Hi Martin,
Does this mean that if ret != 0 , we had errors, but we are not printing this debug message ? Perhaps we should print out here the debug error regardless of the ret value ? Since we exited with a return 0 if we did find the proper bus.
May I also ask on which board setup you tested this ? And which defconfig.
Thanks,
Eugen
Quoted 8 lines
drivers/w1/w1-uclass.c +4
-0+debug ("Cannot find w1 bus %d\n" , busnum); + ret = -ENODEV ; + } +return ret; }
PATCH 1/1 w1: fix data abort if no one wire bus master present
Hi Eugen,
Quoted 41 lines · Eugen.Hristev at microchip.com
Quoted 27 lines · Martin Fuzzey
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]>--- drivers/w1/w1-uclass.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)drivers/w1/w1-uclass.c +0
-5@@ -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;drivers/w1/w1-uclass.c int w1_get_bus(int busnum, struct udevice **busp) · line 126
Quoted 10 lines
drivers/w1/w1-uclass.c +4
-1- } + dev && !ret; + ret = uclass_next_device(&dev), i++) {if (i == busnum) { *busp = dev;return 0 ; } } + +if (!ret) {Hi Martin,
Quoted 5 lines
Does this mean that if ret != 0 , we had errors, but we are not printing this debug message ? Perhaps we should print out here the debug error regardless of the ret value ? Since we exited with a return 0 if we did find the proper bus.
With the current code ret != 0 means that a probe error occurred, not that the bus cannot be found,
if no errors occurred but the requested bus did not exist (either because there were no busses at all or
the index requested was too big) ret from uclass_first|next_device() == 0
In the error case "Cannot find w1 bus %d" is probably not the correct error message.
I would have expected the failing driver to have printed a more explicit error message.
So that is why I only print the debug message if ret == 0 but the device was not found.
Quoted 1 line
May I also ask on which board setup you tested this ? And which defconfig.
Tested on an i.MX53 based custom board.
I am working on the W1 host controller driver for i.MX53 and plan to submit it soon.
I ran into this problem by accident when I forgot to add the DT entry for my new driver.
Regards,
Martin
PATCH 1/1 w1: fix data abort if no one wire bus master present
Quoted 55 lines · Martin Fuzzey
Hi Eugen,
Quoted 40 lines · Eugen.Hristev at microchip.com
Quoted 26 lines · Martin Fuzzey
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]>---
drivers/w1/w1-uclass.c| 14 ++++++++------1 file changed, 8 insertions(+), 6 deletions(-)drivers/w1/w1-uclass.c +0
-5@@ -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;drivers/w1/w1-uclass.c int w1_get_bus(int busnum, struct udevice **busp) · line 125
Quoted 10 lines
drivers/w1/w1-uclass.c +4
-1- } + dev && !ret; + ret = uclass_next_device(&dev), i++) { if (i == busnum) { *busp = dev; return 0; } } + + if (!ret) {Hi Martin,
Quoted 5 lines
Does this mean that if ret != 0 , we had errors, but we are not printing this debug message ? Perhaps we should print out here the debug error regardless of the ret value ? Since we exited with a return 0 if we did find the proper bus.
With the current code ret != 0 means that a probe error occurred, not that the bus cannot be found,
if no errors occurred but the requested bus did not exist (either because there were no busses at all or
the index requested was too big) ret from uclass_first|next_device() == 0
Quoted 6 lines
In the error case "Cannot find w1 bus %d" is probably not the correct error message.
I would have expected the failing driver to have printed a more explicit error message.
So that is why I only print the debug message if ret == 0 but the device was not found.
Good for me.
In cmd/w1.c there is an error message printed regardless of the ret, so, return -ENODEV here if there is no dev is a good way of fixing it.
Thanks again for your fix
Quoted 10 lines
Quoted 3 lines
May I also ask on which board setup you tested this ? And which defconfig.
Tested on an i.MX53 based custom board.
I am working on the W1 host controller driver for i.MX53 and plan to submit it soon.I ran into this problem by accident when I forgot to add the DT entry for my new driver.
Great news, hope that the w1 framework implemented here will help you get on track easily.
Quoted 6 lines
Regards,
Martin
[U-Boot] w1: fix data abort if no one wire bus master present
In reply to Martin FuzzeyQuoted 11 lines · Martin Fuzzey
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]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20181102/ef1c74df/attachment.sig>
PATCH 1/1 w1-eeprom: ds24xxx: fix data abort in ds24xxx_probe()
In reply to Martin FuzzeyQuoted 9 lines · Martin Fuzzey
Data abort was occurring when using "w1 bus" with a DS24B33 present.
The abort occurred in the
ds24xxx_probe()because the structw1_devicepointer was NULL. This is because that structure is allocated by the parent device uclass (by .per_child_platdata_auto_alloc_size) and thus the correct accessor isdev_get_parent_platdata()notdev_get_platdata()Signed-off-by Martin Fuzzey <[email protected]>
Hi Martin,
At some point during development I switched from holding the data in platdata to parent platdata, and this slipped.
Thanks for the fix.
Eugen
Quoted 18 lines
--- drivers/w1-eeprom/ds24xxx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/w1-eeprom/ds24xxx.c +1
-1@@ -31,7 +31,7 @@ static int ds24xxx_probe(struct udevice *dev) {struct w1_device *w1; - w1 =dev_get_platdata (dev); + w1 =dev_get_parent_platdata (dev); w1->id =0 ;return 0 ; }
Quoted 10 lines · Martin Fuzzey
Data abort was occurring when using "w1 bus" with a DS24B33 present.
The abort occurred in the
ds24xxx_probe()because the structw1_devicepointer was NULL. This is because that structure is allocated by the parent device uclass (by .per_child_platdata_auto_alloc_size) and thus the correct accessor isdev_get_parent_platdata()notdev_get_platdata()Signed-off-by Martin Fuzzey <[email protected]>Reviewed-by Eugen Hristev <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20181102/7e1f582b/attachment.sig>