mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: "open list:BAREBOX" <barebox@lists.infradead.org>
Subject: [PATCH 1/2] reset: add __reset_control_get()
Date: Fri, 25 Oct 2024 10:58:02 +0200	[thread overview]
Message-ID: <20241025-reset-bulk-v1-1-52380683ed7b@pengutronix.de> (raw)
In-Reply-To: <20241025-reset-bulk-v1-0-52380683ed7b@pengutronix.de>

reset_control_get_optional() is implemented as a static inline function
which calls reset_control_get() first and then handles the _optional
part.

Change this to implement a __reset_control_get() taking a bool optional
argument. This is done as a preparation to implement
__reset_control_bulk_get() in the next step which can reuse
__reset_control_get().

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/reset/core.c  | 11 ++++++++---
 include/linux/reset.h | 13 +++++++++----
 2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/drivers/reset/core.c b/drivers/reset/core.c
index 94bfad2067..679deee3c1 100644
--- a/drivers/reset/core.c
+++ b/drivers/reset/core.c
@@ -359,7 +359,7 @@ gpio_reset_control_get(struct device *dev, const char *id)
  *
  * Use of id names is optional.
  */
-struct reset_control *reset_control_get(struct device *dev, const char *id)
+struct reset_control *__reset_control_get(struct device *dev, const char *id, bool optional)
 {
 	struct reset_control *rstc;
 
@@ -368,7 +368,7 @@ struct reset_control *reset_control_get(struct device *dev, const char *id)
 
 	rstc = of_reset_control_get(dev->of_node, id);
 	if (IS_ERR(rstc))
-		return ERR_CAST(rstc);
+		goto err;
 
 	/*
 	 * If there is no dedicated reset controller device, check if we have
@@ -377,7 +377,7 @@ struct reset_control *reset_control_get(struct device *dev, const char *id)
 	if (!rstc) {
 		rstc = gpio_reset_control_get(dev, id);
 		if (IS_ERR(rstc))
-			return ERR_CAST(rstc);
+			goto err;
 	}
 
 	if (!rstc)
@@ -386,6 +386,11 @@ struct reset_control *reset_control_get(struct device *dev, const char *id)
 	rstc->dev = dev;
 
 	return rstc;
+err:
+	if (optional && rstc == ERR_PTR(-ENOENT))
+		return NULL;
+
+	return ERR_CAST(rstc);
 }
 EXPORT_SYMBOL_GPL(reset_control_get);
 
diff --git a/include/linux/reset.h b/include/linux/reset.h
index 7db3d3162a..183d7d55a0 100644
--- a/include/linux/reset.h
+++ b/include/linux/reset.h
@@ -13,7 +13,7 @@ int reset_control_reset(struct reset_control *rstc);
 int reset_control_assert(struct reset_control *rstc);
 int reset_control_deassert(struct reset_control *rstc);
 
-struct reset_control *reset_control_get(struct device *dev, const char *id);
+struct reset_control *__reset_control_get(struct device *dev, const char *id, bool optional);
 struct reset_control *of_reset_control_get(struct device_node *node,
 					   const char *id);
 void reset_control_put(struct reset_control *rstc);
@@ -57,7 +57,7 @@ of_reset_control_get(struct device_node *node, const char *id)
 }
 
 static inline struct reset_control *
-reset_control_get(struct device *dev, const char *id)
+__reset_control_get(struct device *dev, const char *id, bool optional)
 {
 	return NULL;
 }
@@ -96,8 +96,13 @@ static inline struct reset_control *reset_control_array_get(struct device *dev)
 static inline struct reset_control *reset_control_get_optional(struct device *dev,
 							       const char *id)
 {
-	struct reset_control *rstc = reset_control_get(dev, id);
-	return rstc == ERR_PTR(-ENOENT) ? NULL : rstc;
+	return __reset_control_get(dev, id, true);
+}
+
+static inline struct reset_control *reset_control_get(struct device *dev,
+						      const char *id)
+{
+	return __reset_control_get(dev, id, false);
 }
 
 #endif

-- 
2.39.5




  reply	other threads:[~2024-10-25  9:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-25  8:58 [PATCH 0/2] reset: implement reset_control_bulk_get() Sascha Hauer
2024-10-25  8:58 ` Sascha Hauer [this message]
2024-10-25  8:58 ` [PATCH 2/2] " Sascha Hauer
2024-10-28 12:12 ` [PATCH 0/2] " Sascha Hauer

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=20241025-reset-bulk-v1-1-52380683ed7b@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox