All of lore.kernel.org
 help / color / mirror / Atom feed
From: Samuel Holland <samuel@sholland.org>
To: Lukasz Majewski <lukma@denx.de>,
	Sean Anderson <seanga2@gmail.com>, Simon Glass <sjg@chromium.org>
Cc: Samuel Holland <samuel@sholland.org>,
	Dario Binacchi <dario.binacchi@amarulasolutions.com>,
	Michal Suchanek <msuchanek@suse.de>,
	u-boot@lists.denx.de, Marek Vasut <marex@denx.de>
Subject: [PATCH v2 2/2] reset: Allow reset_get_by_name() with NULL name
Date: Sat, 21 Jan 2023 18:02:52 -0600	[thread overview]
Message-ID: <20230122000252.53642-2-samuel@sholland.org> (raw)
In-Reply-To: <20230122000252.53642-1-samuel@sholland.org>

This allows devm_reset_control_get(dev, NULL) to work and get the first
reset control, which is common in code ported from Linux.

Signed-off-by: Samuel Holland <samuel@sholland.org>
---

Changes in v2:
 - Move index error check inside if statement
 - Update function comment
 - Add unit test

 drivers/reset/reset-uclass.c | 12 +++++++-----
 include/reset.h              |  3 ++-
 test/dm/reset.c              |  3 +--
 3 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/drivers/reset/reset-uclass.c b/drivers/reset/reset-uclass.c
index bcef46039c..b972faf013 100644
--- a/drivers/reset/reset-uclass.c
+++ b/drivers/reset/reset-uclass.c
@@ -147,16 +147,18 @@ int reset_get_bulk(struct udevice *dev, struct reset_ctl_bulk *bulk)
 int reset_get_by_name(struct udevice *dev, const char *name,
 		     struct reset_ctl *reset_ctl)
 {
-	int index;
+	int index = 0;
 
 	debug("%s(dev=%p, name=%s, reset_ctl=%p)\n", __func__, dev, name,
 	      reset_ctl);
 	reset_ctl->dev = NULL;
 
-	index = dev_read_stringlist_search(dev, "reset-names", name);
-	if (index < 0) {
-		debug("fdt_stringlist_search() failed: %d\n", index);
-		return index;
+	if (name) {
+		index = dev_read_stringlist_search(dev, "reset-names", name);
+		if (index < 0) {
+			debug("fdt_stringlist_search() failed: %d\n", index);
+			return index;
+		}
 	}
 
 	return reset_get_by_index(dev, index, reset_ctl);
diff --git a/include/reset.h b/include/reset.h
index 965f02e0ce..036a786d2a 100644
--- a/include/reset.h
+++ b/include/reset.h
@@ -238,7 +238,8 @@ int reset_get_bulk(struct udevice *dev, struct reset_ctl_bulk *bulk);
  *
  * @dev:	The client device.
  * @name:	The name of the reset signal to request, within the client's
- *		list of reset signals.
+ *		list of reset signals, or NULL to request the first reset
+ *		signal in the list.
  * @reset_ctl:	A pointer to a reset control struct to initialize.
  * Return: 0 if OK, or a negative error code.
  */
diff --git a/test/dm/reset.c b/test/dm/reset.c
index 9c00452336..e2d6f45623 100644
--- a/test/dm/reset.c
+++ b/test/dm/reset.c
@@ -35,8 +35,7 @@ static int dm_test_reset_base(struct unit_test_state *uts)
 
 	/* Get the same reset port in 2 different ways and compare */
 	ut_assertok(reset_get_by_index(dev, 0, &reset_method1));
-	ut_assertok(reset_get_by_index_nodev(dev_ofnode(dev), 0,
-					     &reset_method1_1));
+	ut_assertok(reset_get_by_name(dev, NULL, &reset_method1_1));
 	ut_assertok(reset_get_by_index(dev, 1, &reset_method2));
 	ut_assertok(reset_get_by_index_nodev(dev_ofnode(dev), 1,
 					     &reset_method2_1));
-- 
2.37.4


  reply	other threads:[~2023-01-22  0:03 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-22  0:02 [PATCH v2 1/2] clk: Allow clk_get_by_name() with NULL name Samuel Holland
2023-01-22  0:02 ` Samuel Holland [this message]
2023-01-23 18:49   ` [PATCH v2 2/2] reset: Allow reset_get_by_name() " Simon Glass
2023-01-23 18:42 ` [PATCH v2 1/2] clk: Allow clk_get_by_name() " Simon Glass
2023-02-12 17:51 ` Sean Anderson
2023-02-12 19:57 ` Sean Anderson

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=20230122000252.53642-2-samuel@sholland.org \
    --to=samuel@sholland.org \
    --cc=dario.binacchi@amarulasolutions.com \
    --cc=lukma@denx.de \
    --cc=marex@denx.de \
    --cc=msuchanek@suse.de \
    --cc=seanga2@gmail.com \
    --cc=sjg@chromium.org \
    --cc=u-boot@lists.denx.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.