[PATCH v2 2/5] usb: dwc3-generic: Return early when there is no child node
Jonas Karlman
jonas at kwiboo.se
Sun Jul 16 09:57:39 CEST 2023
On 2023-07-16 03:19, Marek Vasut wrote:
> On 7/16/23 03:05, Jonas Karlman wrote:
>> On 2023-07-16 02:58, Marek Vasut wrote:
>>> On 7/16/23 01:10, Jonas Karlman wrote:
>>>> The current error check for device_find_first_child is not working as
>>>> expected, the documentation for device_find_first_child mention:
>>>>
>>>> @devp: Returns first child device, or NULL if none
>>>> Return: 0
>>>>
>>>> Change to return early when there is no child node to avoid any possible
>>>> null pointer dereference.
>>>>
>>>> Signed-off-by: Jonas Karlman <jonas at kwiboo.se>
>>>> ---
>>>> v2:
>>>> - Update commit message
>>>>
>>>> drivers/usb/dwc3/dwc3-generic.c | 6 +++---
>>>> 1 file changed, 3 insertions(+), 3 deletions(-)
>>>>
>>>> diff --git a/drivers/usb/dwc3/dwc3-generic.c b/drivers/usb/dwc3/dwc3-generic.c
>>>> index 35e4b36a695e..4d5d500aefab 100644
>>>> --- a/drivers/usb/dwc3/dwc3-generic.c
>>>> +++ b/drivers/usb/dwc3/dwc3-generic.c
>>>> @@ -558,9 +558,9 @@ int dwc3_glue_probe(struct udevice *dev)
>>>> return ret;
>>>> }
>>>>
>>>> - ret = device_find_first_child(dev, &child);
>>>> - if (ret)
>>>> - return ret;
>>>> + device_find_first_child(dev, &child);
>>>> + if (!child)
>>>> + return 0;
>>>
>>> What does device_find_first_child() return in your case ? ENODEV or ENOSYS ?
>>
>> device_find_first_child always returns 0, same as is documented.
>>
>> See https://source.denx.de/u-boot/u-boot/-/blob/master/drivers/core/device.c#L931-941>>
> Ah, I see, thanks for clarifying.
>
> Reviewed-by: Marek Vasut <marex at denx.de>
>
> Could you fix mtu3_plat.c the same way and switch this function to
> return void ? (separate series for these two things please)
Sorry, not sure when I would have time for that, currently way too much
ongoing in my pipeline :-)
Regards,
Jonas
More information about the U-Boot
mailing list