[U-Boot] [RFC PATCH] dm: ensure device names are unique

Simon Glass sjg at chromium.org
Thu Apr 28 06:50:16 CEST 2016


Hi Stephen,

On 26 April 2016 at 15:30, Stephen Warren <swarren at wwwdotorg.org> wrote:
> It is possible for HW to contain multiple instances of the same device. In
> this case, the name passed to device_bind() may not be unique across all
> devices within its uclass. One example is a system with multiple identical
> PCI Ethernet devices. Another might be a system with multiple identical
> I2C GPIO expanders, each connected to a separate I2C bus, yet using the
> same I2C address on that bus and hence having the same DT node name.
>
> Enhance the code to detect this situation, and append a sequence number so
> the device name to ensure uniqueness.
>
> Signed-off-by: Stephen Warren <swarren at nvidia.com>
> ---
> Some possible issues with this patch:
>
> 1) Doing this in bind() rather than probe() means dev->seq isn't
> available, so can't be used to generate the unique name. This process
> should be done during bind() rather than probe() though, since devices can
> be seen (e.g. by running "dm tree") before they're probed. Perhaps the
> uclass_resolve_seq() should be called by bind() not probe().
>
> 2) uclass_find_device_by_name() needs to look up the uclass pointer again
> even though device_bind() already knows it.
>
> 3) Iterating over the list to find the count of devices in the uclass is a
> bit annoying. Should the uclass maintain this count so it doesn't need to
> be re-calculated each time?
> ---
> drivers/core/device-remove.c | 4 ++++
> drivers/core/device.c | 23 ++++++++++++++++++++++-
> include/dm/device.h | 3 +++
> 3 files changed, 29 insertions(+), 1 deletion(-)

I would rather that the caller handles this. But failing this perhaps a new
function that does it? Is this for the Ethernet use case?

Regards,
Simon


More information about the U-Boot mailing list