[PATCH v2 2/5] usb: dwc3-generic: Return early when there is no child node

Jonas Karlman jonas at kwiboo.se
Sun Jul 16 03:05:08 CEST 2023


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

Regards,
Jonas


More information about the U-Boot mailing list