From: Eugen.Hristev at microchip.com <Eugen.Hristev@microchip.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] w1: fix data abort if no one wire bus master present
Date: Tue, 23 Oct 2018 08:30:36 +0000 [thread overview]
Message-ID: <a23f9668-f866-efb0-6e72-af986784b2ab@microchip.com> (raw)
In-Reply-To: <879201cc-160d-94d4-48a0-15f23af40f8c@flowbird.group>
On 23.10.2018 11:17, Martin Fuzzey wrote:
> Hi Eugen,
>
> On 23/10/18 09:05, Eugen.Hristev at microchip.com wrote:
>>
>> On 22.10.2018 19:31, Martin Fuzzey wrote:
>>> 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>
>>> ---
>>> drivers/w1/w1-uclass.c | 14 ++++++++------
>>> 1 file changed, 8 insertions(+), 6 deletions(-)
>>>
>>> diff --git a/drivers/w1/w1-uclass.c b/drivers/w1/w1-uclass.c
>>> index aecf7fe..cb41b68 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) {
>> 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.
>>
>
> 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.
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.
Reviewed-by: Eugen Hristev <eugen.hristev@microchip.com>
Thanks again for your fix
>
>> 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.
>
> Regards,
>
> Martin
>
>
next prev parent reply other threads:[~2018-10-23 8:30 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-10-22 16:31 [U-Boot] [PATCH] w1-eeprom: ds24xxx: fix data abort in ds24xxx_probe() Martin Fuzzey
2018-10-22 16:31 ` [U-Boot] [PATCH] w1: fix data abort if no one wire bus master present Martin Fuzzey
2018-10-23 7:05 ` Eugen.Hristev at microchip.com
2018-10-23 8:17 ` Martin Fuzzey
2018-10-23 8:30 ` Eugen.Hristev at microchip.com [this message]
2018-11-02 20:29 ` [U-Boot] " Tom Rini
2018-10-23 6:51 ` [U-Boot] [PATCH] w1-eeprom: ds24xxx: fix data abort in ds24xxx_probe() Eugen.Hristev at microchip.com
2018-11-02 20:29 ` [U-Boot] " Tom Rini
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a23f9668-f866-efb0-6e72-af986784b2ab@microchip.com \
--to=eugen.hristev@microchip.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox