[PATCH v2 2/3] dm: compare full name in uclass_get_by_name
Simon Glass
sjg at chromium.org
Thu Jan 27 16:05:47 CET 2022
Hi Patrick,
On Mon, 17 Jan 2022 at 08:49, Patrick Delaunay
<patrick.delaunay at foss.st.com> wrote:
>
> Change uclass_get_by_name to use a strict string compare function
> "strcmp" with the parameter 'name'.
>
> This patch avoids issues when strlen(name)<strlen(uc_drv->name) as
> the function uclass_get_by_name() no more use uclass_get_by_name_len(),
> which limit the check with "strncmp" and length of name.
>
> This problem is detected by the sandbox test for log filter:
> in log_get_cat_by_name(), uclass_get_by_name("spi") = UCLASS_SPI_EMUL
> for "spi_emul", it is not the expected result = UCLASS_SPI
> for a search by name.
> But it is the expected result for search with partial name
> uclass_get_by_name_len("spi", 3).
>
> Signed-off-by: Patrick Delaunay <patrick.delaunay at foss.st.com>
> ---
>
> (no changes since v1)
>
> drivers/core/uclass.c | 11 ++++++++++-
> 1 file changed, 10 insertions(+), 1 deletion(-)
To save code space, could we avoid copying the function and instead
use len == -1 to mean to check the whole thing?
>
> diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
> index 336ea8d243..32b6cef167 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.25.1
>
Regards,
Simon
More information about the U-Boot
mailing list