[U-Boot] `uclass_find_device_by_name` fails to find the device

Nandor Han nandor.han at vaisala.com
Wed Nov 6 13:09:22 UTC 2019

Hi everybody,
   I've noticed that commit 4213609cc7fb78f84b2ea63f4a5691b60d01c248 
changes how `uclass.c:uclass_find_device_by_name` function compares the 
names for finding devices.

Because of this I have an issue when having a DTS and trying to find a 
device by name.

The `lists.c:lists_bind_fdt` function will bind a device to a device 
node tree and use the node name as device name.

int lists_bind_fdt(..)
name = ofnode_get_name(node);

Because of this devices will end up having names like: i2c at 021a0000, 
pfuze100 at 8...

When using `uclass.c:uclass_find_device_by_name` to get a device, before 
the change, this was not an issue since `strncmp` was used with the 
length of the name making a call like 
`uclass_find_device_by_name(pfuze100)` successfully even if the device 
name was `pfuze100 at 8`.
if (!strncmp(dev->name, name, strlen(name))) {

However after the change (which I think is correct), the check fails, 
resulting in not finding the expected device, since the device name has 
also the suffix `@...` included.

What's the proper fix here:

1. Changing the `lists.c:lists_bind_fdt` to drop the `@` suffix?
     Note: Could this be a problem when having the same node names but 
different addressees in DTS {e.g.foo at 1, foo at 2}

2. When using `uclass.c:uclass_find_device_by_name` the user should take 
in consideration that `@..` suffix needs to be added.
    Note: This could be a problem when same code is used with different 

3. Changing the comparation in `uclass.c:uclass_find_device_by_name` to 
ignore the part after `@` for device names.

4. What else?


More information about the U-Boot mailing list