All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Dennis Gilmore <dennis@ausil.us>,
	Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Lukas Auer <lukas.auer@aisec.fraunhofer.de>,
	Tom Rini <trini@konsulko.com>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>,
	Michal Simek <michal.simek@xilinx.com>,
	Daniel Schwierzeck <daniel.schwierzeck@gmail.com>,
	Steffen Jaeckel <jaeckel-floss@eyet-services.de>,
	Simon Glass <sjg@chromium.org>,
	Patrick Delaunay <patrick.delaunay@foss.st.com>,
	Tim Harvey <tharvey@gateworks.com>, Marek Vasut <marex@denx.de>,
	Pavel Herrmann <morpheus.ibis@gmail.com>
Subject: [PATCH v4 06/33] dm: core: Rename and fix uclass_get_by_name_len()
Date: Sun,  6 Mar 2022 05:49:49 -0700	[thread overview]
Message-ID: <20220306125016.3133737-7-sjg@chromium.org> (raw)
In-Reply-To: <20220306125016.3133737-1-sjg@chromium.org>

It seems that namelen is more common in U-Boot. Rename this function to
fit in better. Also fix a bug where it breaks the operation of
uclass_get_by_name() and add a test.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reported-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
Reported-by: Tim Harvey <tharvey@gateworks.com>
---

Changes in v4:
- Correct bug in this function and add test
- Use new sphynx Return style

Changes in v3:
- Add new patch to rename uclass_get_by_name_len()

 drivers/core/uclass.c | 7 ++++---
 include/dm/uclass.h   | 6 +++---
 test/dm/core.c        | 2 ++
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index 2578803b7a..4b9b54f0f1 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -180,14 +180,15 @@ void uclass_set_priv(struct uclass *uc, void *priv)
 	uc->priv_ = priv;
 }
 
-enum uclass_id uclass_get_by_name_len(const char *name, int len)
+enum uclass_id uclass_get_by_namelen(const char *name, int len)
 {
 	int i;
 
 	for (i = 0; i < UCLASS_COUNT; i++) {
 		struct uclass_driver *uc_drv = lists_uclass_lookup(i);
 
-		if (uc_drv && !strncmp(uc_drv->name, name, len))
+		if (uc_drv && !strncmp(uc_drv->name, name, len) &&
+		    strlen(uc_drv->name) == len)
 			return i;
 	}
 
@@ -196,7 +197,7 @@ 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));
+	return uclass_get_by_namelen(name, strlen(name));
 }
 
 int dev_get_uclass_index(struct udevice *dev, struct uclass **ucp)
diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index 7f33c34214..d1bb981e27 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -173,13 +173,13 @@ int uclass_get(enum uclass_id key, struct uclass **ucp);
 const char *uclass_get_name(enum uclass_id id);
 
 /**
- * uclass_get_by_name_len() - Look up a uclass by its partial driver name
+ * uclass_get_by_namelen() - Look up a uclass by its driver name
  *
  * @name: Name to look up
- * @len: Length of the partial name
+ * @len: Length of @name (the uclass driver name must have the same length)
  * Return: the associated uclass ID, or UCLASS_INVALID if not found
  */
-enum uclass_id uclass_get_by_name_len(const char *name, int len);
+enum uclass_id uclass_get_by_namelen(const char *name, int len);
 
 /**
  * uclass_get_by_name() - Look up a uclass by its driver name
diff --git a/test/dm/core.c b/test/dm/core.c
index 0ce0b3c4a2..2c73ecf54a 100644
--- a/test/dm/core.c
+++ b/test/dm/core.c
@@ -1161,6 +1161,8 @@ static int dm_test_uclass_names(struct unit_test_state *uts)
 	ut_asserteq_str("test", uclass_get_name(UCLASS_TEST));
 	ut_asserteq(UCLASS_TEST, uclass_get_by_name("test"));
 
+	ut_asserteq(UCLASS_SPI, uclass_get_by_name("spi"));
+
 	return 0;
 }
 DM_TEST(dm_test_uclass_names, UT_TESTF_SCAN_PDATA);
-- 
2.35.1.616.g0bdcbb4464-goog


  parent reply	other threads:[~2022-03-06 12:52 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-06 12:49 [PATCH v4 00/33] Initial implementation of standard boot Simon Glass
2022-03-06 12:49 ` [PATCH v4 01/33] lib: Move string tests to the string module Simon Glass
2022-03-06 12:49 ` [PATCH v4 02/33] test: Add tests for trailing_strtol() Simon Glass
2022-03-06 12:49 ` [PATCH v4 03/33] lib: Correct comment formatting to avoid sphinx problems Simon Glass
2022-03-06 12:49 ` [PATCH v4 04/33] lib: Fix a few bugs in trailing_strtoln() Simon Glass
2022-03-06 12:49 ` [PATCH v4 05/33] lib: Add a way to find the postiion of a trailing number Simon Glass
2022-03-06 12:49 ` Simon Glass [this message]
2022-03-06 12:49 ` [PATCH v4 07/33] dm: core: Allow finding a uclass device by partial name Simon Glass
2022-03-06 12:49 ` [PATCH v4 08/33] test: fastboot: Avoid using mmc1 Simon Glass
2022-03-06 12:49 ` [PATCH v4 09/33] test: dm: Restart USB before assuming it is stopped Simon Glass
2022-03-06 12:49 ` [PATCH v4 10/33] dm: blk: Add a function to return the device type Simon Glass
2022-03-06 12:49 ` [PATCH v4 11/33] fs: Add a function to set the filesystem type Simon Glass
2022-03-06 12:49 ` [PATCH v4 12/33] bootstd: Add the concept of a bootflow Simon Glass
2022-03-06 12:49 ` [PATCH v4 13/33] bootstd: Add the bootstd uclass and core implementation Simon Glass
2022-03-12 14:35   ` Ilias Apalodimas
2022-03-12 17:58     ` Simon Glass
2022-03-06 12:49 ` [PATCH v4 14/33] bootstd: Add the bootdev uclass Simon Glass
2022-03-06 12:49 ` [PATCH v4 15/33] bootstd: Add the bootmeth uclass and helpers Simon Glass
2022-03-06 12:49 ` [PATCH v4 16/33] bootstd: Add support for bootflows Simon Glass
2022-03-06 12:50 ` [PATCH v4 17/33] bootstd: Add a bootdev command Simon Glass
2022-03-06 12:50 ` [PATCH v4 19/33] bootstd: Add a bootmeth command Simon Glass
2022-03-06 12:50 ` [PATCH v4 21/33] bootstd: mmc: Add a bootdev driver Simon Glass
2022-03-06 12:50 ` [PATCH v4 22/33] bootstd: ethernet: " Simon Glass
2022-03-06 12:50 ` [PATCH v4 23/33] bootstd: Add an implementation of distro PXE boot Simon Glass
2022-03-06 12:50 ` [PATCH v4 24/33] bootstd: Add an implementation of EFI boot Simon Glass
2022-03-06 12:50 ` [PATCH v4 25/33] bootstd: Add a system bootdev for strange boot methods Simon Glass
2022-03-06 12:50 ` [PATCH v4 27/33] bootstd: Add a sandbox bootmeth driver Simon Glass
2022-03-06 12:50 ` [PATCH v4 28/33] bootstd: sandbox: Add a hostfs bootdev Simon Glass
2022-03-06 12:50 ` [PATCH v4 30/33] bootstd: usb: Add a bootdev driver Simon Glass
2022-03-06 12:50 ` [PATCH v4 31/33] bootstd: Add tests for bootstd including all uclasses Simon Glass
2022-03-06 12:50 ` [PATCH v4 32/33] bootstd: Add setup for the bootflow tests Simon Glass
2022-03-06 12:50 ` [PATCH v4 33/33] bootstd: doc: Add documentation Simon Glass
2022-03-13 15:47 ` [PATCH v4 00/33] Initial implementation of standard boot Mark Kettenis
2022-03-13 22:23   ` Simon Glass
2022-03-23 14:05 ` Tom Rini
2022-03-23 18:45   ` Simon Glass
2022-03-23 19:21     ` Michael Nazzareno Trimarchi
2022-03-23 19:30       ` Tom Rini
2022-03-23 19:57         ` Michael Nazzareno Trimarchi
2022-03-23 20:07           ` Tom Rini
2022-03-25 14:36             ` Michael Nazzareno Trimarchi
2022-03-25 14:50               ` Tom Rini
2022-03-26 19:56                 ` Simon Glass
2022-03-26 19:58                   ` Tom Rini
2022-03-26 20:51                     ` Simon Glass
2022-03-27 11:00                       ` Michael Nazzareno Trimarchi
2022-03-29  1:36                       ` Tom Rini
2022-03-23 23:15       ` Mark Kettenis
2022-03-24  2:18         ` Simon Glass
2022-03-23 20:09     ` Tom Rini
2022-03-24  2:13       ` Simon Glass
2022-03-24 14:46         ` Tom Rini
2022-03-24 18:33           ` Simon Glass
2022-03-24 19:27             ` Tom Rini
2022-03-24 20:04               ` Simon Glass
2022-03-24 21:16                 ` Tom Rini

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=20220306125016.3133737-7-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=daniel.schwierzeck@gmail.com \
    --cc=dennis@ausil.us \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jaeckel-floss@eyet-services.de \
    --cc=lukas.auer@aisec.fraunhofer.de \
    --cc=marex@denx.de \
    --cc=michal.simek@xilinx.com \
    --cc=morpheus.ibis@gmail.com \
    --cc=patrick.delaunay@foss.st.com \
    --cc=tharvey@gateworks.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /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.