[U-Boot] [PATCH 1/6] dm: core: Add a way to set a device name
Bin Meng
bmeng.cn at gmail.com
Fri Jul 31 11:08:09 CEST 2015
On Fri, Jul 31, 2015 at 3:40 AM, Simon Glass <sjg at chromium.org> wrote:
> Some devices are bound entirely by probing and do not have the benefit of
> a device tree to give them a name. This is very common with PCI and USB. In
> most cases this is fine, but we should add an official way to set a device
> name. This should be called in the device's bind() method.
>
> Signed-off-by: Simon Glass <sjg at chromium.org>
> ---
>
> drivers/core/device.c | 10 ++++++++++
> include/dm/device.h | 15 +++++++++++++++
> 2 files changed, 25 insertions(+)
>
> diff --git a/drivers/core/device.c b/drivers/core/device.c
> index caaf231..bbe7a94 100644
> --- a/drivers/core/device.c
> +++ b/drivers/core/device.c
> @@ -603,3 +603,13 @@ bool device_is_last_sibling(struct udevice *dev)
> return false;
> return list_is_last(&dev->sibling_node, &parent->child_head);
> }
> +
> +int device_set_name(struct udevice *dev, const char *name)
> +{
> + name = strdup(name);
> + if (!name)
> + return -ENOMEM;
> + dev->name = name;
> +
> + return 0;
> +}
> diff --git a/include/dm/device.h b/include/dm/device.h
> index 38e23f8..5a04379 100644
> --- a/include/dm/device.h
> +++ b/include/dm/device.h
> @@ -468,6 +468,21 @@ bool device_has_active_children(struct udevice *dev);
> */
> bool device_is_last_sibling(struct udevice *dev);
>
> +/**
> + * device_set_name() - set the name of a device
> + *
> + * This must be called in the device's bind() method and no later. Normally
> + * this is unnecessary but for probed devices which don't get a useful name
> + * this function can be helpful.
> + *
> + * @dev: Device to update
> + * @name: New name (this string is allocated new memory and attached to
> + * the device)
> + * @return 0 if OK, -ENOMEM if there is not enough memory to allocate the
> + * string
> + */
> +int device_set_name(struct udevice *dev, const char *name);
> +
> /* device resource management */
> typedef void (*dr_release_t)(struct udevice *dev, void *res);
> typedef int (*dr_match_t)(struct udevice *dev, void *res, void *match_data);
> --
Reviewed-by: Bin Meng <bmeng.cn at gmail.com>
More information about the U-Boot
mailing list