linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>,
	linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Bartosz Golaszewski <brgl@bgdev.pl>,
	Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v1 3/7] gpiolib: Move validate_desc() and Co upper in the code
Date: Tue, 15 Apr 2025 14:10:02 +0300	[thread overview]
Message-ID: <20250415111124.1539366-4-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20250415111124.1539366-1-andriy.shevchenko@linux.intel.com>

Move validate_desc() and Co upper in the code to be able to use
in the further changes.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/gpio/gpiolib.c | 62 +++++++++++++++++++++---------------------
 1 file changed, 31 insertions(+), 31 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 8ea5ddf4704d..1fdf4d2ceb36 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -356,6 +356,37 @@ static int gpiochip_find_base_unlocked(u16 ngpio)
 	}
 }
 
+/*
+ * This descriptor validation needs to be inserted verbatim into each
+ * function taking a descriptor, so we need to use a preprocessor
+ * macro to avoid endless duplication. If the desc is NULL it is an
+ * optional GPIO and calls should just bail out.
+ */
+static int validate_desc(const struct gpio_desc *desc, const char *func)
+{
+	if (!desc)
+		return 0;
+
+	if (IS_ERR(desc)) {
+		pr_warn("%s: invalid GPIO (errorpointer: %pe)\n", func, desc);
+		return PTR_ERR(desc);
+	}
+
+	return 1;
+}
+
+#define VALIDATE_DESC(desc) do { \
+	int __valid = validate_desc(desc, __func__); \
+	if (__valid <= 0) \
+		return __valid; \
+	} while (0)
+
+#define VALIDATE_DESC_VOID(desc) do { \
+	int __valid = validate_desc(desc, __func__); \
+	if (__valid <= 0) \
+		return; \
+	} while (0)
+
 static int gpiochip_get_direction(struct gpio_chip *gc, unsigned int offset)
 {
 	int ret;
@@ -2433,37 +2464,6 @@ static int gpiod_request_commit(struct gpio_desc *desc, const char *label)
 	return ret;
 }
 
-/*
- * This descriptor validation needs to be inserted verbatim into each
- * function taking a descriptor, so we need to use a preprocessor
- * macro to avoid endless duplication. If the desc is NULL it is an
- * optional GPIO and calls should just bail out.
- */
-static int validate_desc(const struct gpio_desc *desc, const char *func)
-{
-	if (!desc)
-		return 0;
-
-	if (IS_ERR(desc)) {
-		pr_warn("%s: invalid GPIO (errorpointer: %pe)\n", func, desc);
-		return PTR_ERR(desc);
-	}
-
-	return 1;
-}
-
-#define VALIDATE_DESC(desc) do { \
-	int __valid = validate_desc(desc, __func__); \
-	if (__valid <= 0) \
-		return __valid; \
-	} while (0)
-
-#define VALIDATE_DESC_VOID(desc) do { \
-	int __valid = validate_desc(desc, __func__); \
-	if (__valid <= 0) \
-		return; \
-	} while (0)
-
 int gpiod_request(struct gpio_desc *desc, const char *label)
 {
 	int ret = -EPROBE_DEFER;
-- 
2.47.2


  parent reply	other threads:[~2025-04-15 11:12 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-15 11:09 [PATCH v1 0/7] gpiolib: Some cleanups Andy Shevchenko
2025-04-15 11:10 ` [PATCH v1 1/7] gpiolib: Print actual error when descriptor contains an error pointer Andy Shevchenko
2025-04-16  8:40   ` Linus Walleij
2025-04-15 11:10 ` [PATCH v1 2/7] gpiolib: Revert "Don't WARN on gpiod_put() for optional GPIO" Andy Shevchenko
2025-04-16  8:41   ` Linus Walleij
2025-04-15 11:10 ` Andy Shevchenko [this message]
2025-04-16  8:42   ` [PATCH v1 3/7] gpiolib: Move validate_desc() and Co upper in the code Linus Walleij
2025-04-15 11:10 ` [PATCH v1 4/7] gpiolib: Call validate_desc() when VALIDATE_DESC() can't be used Andy Shevchenko
2025-04-16  8:44   ` Linus Walleij
2025-04-16  9:17     ` Andy Shevchenko
2025-04-16  9:54       ` Andy Shevchenko
2025-04-15 11:10 ` [PATCH v1 5/7] gpiolib: Make taking gpio_lookup_lock consistent Andy Shevchenko
2025-04-16  8:45   ` Linus Walleij
2025-04-15 11:10 ` [PATCH v1 6/7] gpiolib: Convert to use guard()() for gpio_machine_hogs_mutex Andy Shevchenko
2025-04-16  8:45   ` Linus Walleij
2025-04-15 11:10 ` [PATCH v1 7/7] gpiolib: Remove redundant assignment of return variable Andy Shevchenko
2025-04-16  8:47   ` Linus Walleij

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=20250415111124.1539366-4-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=bartosz.golaszewski@linaro.org \
    --cc=brgl@bgdev.pl \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.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;
as well as URLs for NNTP newsgroup(s).