From: Nandor Han Date: Wed, 6 Nov 2019 15:09:22 +0200 Subject: [U-Boot] `uclass_find_device_by_name` fails to find the device Message-ID: <7fbb0aa6-c19e-2610-23e3-9e9e85585054@vaisala.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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. ``` lists.c: 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 DTSs. 3. Changing the comparation in `uclass.c:uclass_find_device_by_name` to ignore the part after `@` for device names. 4. What else? Regads, Nandor