`uclass_find_device_by_name` fails to find the device
Nandor Han
nandor.han at vaisala.com
Tue Jan 7 10:16:28 CET 2020
Hi Simon and thanks,
On 2019-12-24 17:58, Simon Glass wrote:
<snip>
>
> Can you use a phandle to refer to the device from another node,
> perhaps a UCLASS_BOARD node if needed? It is not a good idea to use
> this function.
I'm not sure, I'll have to check that. Anyway
`uclass_find_device_by_name` is used by `uclass_get_device_by_name`,
which already seems to be used in plenty of places.
>
> Alternatively we could add a new function which finds by partial name.
My fix was to ignore the suffix starting from "@", if that exist, since
that's more like metadata...and compare entire string when "@" is missing.
Something like:
uclass_foreach_dev(dev, uc) {
- if (!strcmp(dev->name, name)) {
+ char *at_char = strchr(dev->name, '@');
+ int name_length;
+
+ if (at_char)
+ name_length = at_char - dev->name;
+ else
+ name_length = max(strlen(dev->name), strlen(name));
+
+ if (!strncmp(dev->name, name, name_length)) {
*devp = dev;
return 0;
}
I could probably to prepare an RFC with this change.
Regards,
Nandor
More information about the U-Boot
mailing list