All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: Patrick Delaunay <patrick.delaunay@foss.st.com>
Cc: U-Boot Mailing List <u-boot@lists.denx.de>,
	 U-Boot STM32 <uboot-stm32@st-md-mailman.stormreply.com>
Subject: Re: [PATCH v2 2/3] dm: compare full name in uclass_get_by_name
Date: Thu, 27 Jan 2022 08:05:47 -0700	[thread overview]
Message-ID: <CAPnjgZ3bvw_9JEBbOiRcxidiRY36uhzjDBzZRyg7nLgsHehY=A@mail.gmail.com> (raw)
In-Reply-To: <20220117164919.v2.2.I85a4f70465cef5ef600f264706dca84c55c7efdb@changeid>

Hi Patrick,

On Mon, 17 Jan 2022 at 08:49, Patrick Delaunay
<patrick.delaunay@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@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

  reply	other threads:[~2022-01-27 15:06 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-17 15:49 [PATCH v2 0/3] sandbox: test: activate tests for the command LOG Patrick Delaunay
2022-01-17 15:49 ` [PATCH v2 1/3] dm: fix up documentation for uclass_get_by_name_len Patrick Delaunay
2022-01-27 15:05   ` Simon Glass
2022-01-17 15:49 ` [PATCH v2 2/3] dm: compare full name in uclass_get_by_name Patrick Delaunay
2022-01-27 15:05   ` Simon Glass [this message]
2022-01-17 15:49 ` [PATCH v2 3/3] sandbox: test: activate tests for the command LOG Patrick Delaunay
2022-01-27 15:05   ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPnjgZ3bvw_9JEBbOiRcxidiRY36uhzjDBzZRyg7nLgsHehY=A@mail.gmail.com' \
    --to=sjg@chromium.org \
    --cc=patrick.delaunay@foss.st.com \
    --cc=u-boot@lists.denx.de \
    --cc=uboot-stm32@st-md-mailman.stormreply.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.