`uclass_find_device_by_name` fails to find the device
Simon Glass
sjg at chromium.org
Sat Mar 14 21:35:00 CET 2020
Hi Nandor,
On Tue, 7 Jan 2020 at 02:16, Nandor Han <nandor.han at vaisala.com> wrote:
>
>
> 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.
OK, that is the preferred method.
> 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.
I think this is OK as a new function, but do add a comment in the
header that it should not be used and phandles should be used instead.
Also please remember to add a test.
Regards,
Simon
More information about the U-Boot
mailing list