[PATCH] dm: core: fix uclass_get_by_name
Simon Glass
sjg at chromium.org
Wed Feb 16 20:00:11 CET 2022
Hi Tim,
On Wed, 16 Feb 2022 at 08:57, Tim Harvey <tharvey at gateworks.com> wrote:
>
> When calling uclass_get_by_name we want to do a full match on the uclass
> name, not a partial match.
>
> Signed-off-by: Tim Harvey <tharvey at gateworks.com>
> ---
> drivers/core/uclass.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
>
There was already a patch for this from someone and I believe I left
some comments on it. Please take a look. We should add a test also,
that catches the bad behaviour.
> diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
> index 2578803b7a4d..82efefae5265 100644
> --- a/drivers/core/uclass.c
> +++ b/drivers/core/uclass.c
> @@ -196,7 +196,16 @@ enum uclass_id uclass_get_by_name_len(const char *name, int len)
>
> enum uclass_id uclass_get_by_name(const char *name)
> {
> - return uclass_get_by_name_len(name, strlen(name));
> + int i;
> +
> + for (i = 0; i < UCLASS_COUNT; i++) {
> + struct uclass_driver *uc_drv = lists_uclass_lookup(i);
> +
> + if (uc_drv && !strcmp(uc_drv->name, name))
> + return i;
> + }
> +
> + return UCLASS_INVALID;
> }
>
> int dev_get_uclass_index(struct udevice *dev, struct uclass **ucp)
> --
> 2.17.1
>
Regards,
SImon
More information about the U-Boot
mailing list