linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] gpio: improve gpiod_is_equal()
@ 2025-06-20 12:58 Bartosz Golaszewski
  2025-06-20 12:58 ` [PATCH 1/2] gpio: constify arguments of gpiod_is_equal() Bartosz Golaszewski
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Bartosz Golaszewski @ 2025-06-20 12:58 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski
  Cc: linux-gpio, linux-kernel, Bartosz Golaszewski, Andy Shevchenko

This short series contains small improvements to the gpiod_is_equal()
GPIO descriptor comparator added last cycle.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
Bartosz Golaszewski (2):
      gpio: constify arguments of gpiod_is_equal()
      gpio: make gpiod_is_equal() arguments stricter

 drivers/gpio/gpiolib.c        | 29 +++++++++++++++--------------
 include/linux/gpio/consumer.h |  5 +++--
 2 files changed, 18 insertions(+), 16 deletions(-)
---
base-commit: 2c923c845768a0f0e34b8161d70bc96525385782
change-id: 20250620-gpiod-is-equal-improv-a6f0995e3cc5

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] gpio: constify arguments of gpiod_is_equal()
  2025-06-20 12:58 [PATCH 0/2] gpio: improve gpiod_is_equal() Bartosz Golaszewski
@ 2025-06-20 12:58 ` Bartosz Golaszewski
  2025-06-20 12:58 ` [PATCH 2/2] gpio: make gpiod_is_equal() arguments stricter Bartosz Golaszewski
  2025-06-30  6:58 ` [PATCH 0/2] gpio: improve gpiod_is_equal() Bartosz Golaszewski
  2 siblings, 0 replies; 6+ messages in thread
From: Bartosz Golaszewski @ 2025-06-20 12:58 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski
  Cc: linux-gpio, linux-kernel, Bartosz Golaszewski

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

This function is not meant to modify the GPIO descriptors in any way so
we can safely constify both arguments.

Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/gpio/gpiolib.c        | 2 +-
 include/linux/gpio/consumer.h | 5 +++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 5b0b4fc975435290a03410f1e33fea28dd6fea08..6b4f94c3887fcbe1d90a0ff5800100e9ae7ad5b9 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -286,7 +286,7 @@ EXPORT_SYMBOL_GPL(gpiod_to_gpio_device);
  * Returns:
  * True if the descriptors refer to the same physical pin. False otherwise.
  */
-bool gpiod_is_equal(struct gpio_desc *desc, struct gpio_desc *other)
+bool gpiod_is_equal(const struct gpio_desc *desc, const struct gpio_desc *other)
 {
 	return desc == other;
 }
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index f0b1982da0cc78b85af8bd61474cc2fe0dd73c98..00df68c514051434e6fa67dc2307c6a8ce4ce3df 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -181,7 +181,8 @@ struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
 					      enum gpiod_flags flags,
 					      const char *label);
 
-bool gpiod_is_equal(struct gpio_desc *desc, struct gpio_desc *other);
+bool gpiod_is_equal(const struct gpio_desc *desc,
+		    const struct gpio_desc *other);
 
 #else /* CONFIG_GPIOLIB */
 
@@ -551,7 +552,7 @@ struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
 }
 
 static inline bool
-gpiod_is_equal(struct gpio_desc *desc, struct gpio_desc *other)
+gpiod_is_equal(const struct gpio_desc *desc, const struct gpio_desc *other)
 {
 	WARN_ON(desc || other);
 	return false;

-- 
2.48.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] gpio: make gpiod_is_equal() arguments stricter
  2025-06-20 12:58 [PATCH 0/2] gpio: improve gpiod_is_equal() Bartosz Golaszewski
  2025-06-20 12:58 ` [PATCH 1/2] gpio: constify arguments of gpiod_is_equal() Bartosz Golaszewski
@ 2025-06-20 12:58 ` Bartosz Golaszewski
  2025-06-21 19:12   ` Andy Shevchenko
  2025-06-24 19:25   ` Linus Walleij
  2025-06-30  6:58 ` [PATCH 0/2] gpio: improve gpiod_is_equal() Bartosz Golaszewski
  2 siblings, 2 replies; 6+ messages in thread
From: Bartosz Golaszewski @ 2025-06-20 12:58 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski
  Cc: linux-gpio, linux-kernel, Bartosz Golaszewski, Andy Shevchenko

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

It makes no sense for a GPIO descriptor comparator to return true when
the arguments passed to it are NULL or IS_ERR(). Let's validate both and
return false unless both are valid GPIO descriptors.

Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Link: https://lore.kernel.org/all/Z_aFBfjb17JxOwyk@black.fi.intel.com/
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/gpio/gpiolib.c | 29 +++++++++++++++--------------
 1 file changed, 15 insertions(+), 14 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 6b4f94c3887fcbe1d90a0ff5800100e9ae7ad5b9..7b2174b10219964a3f106562e1685a6d900d56c8 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -278,20 +278,6 @@ struct gpio_device *gpiod_to_gpio_device(struct gpio_desc *desc)
 }
 EXPORT_SYMBOL_GPL(gpiod_to_gpio_device);
 
-/**
- * gpiod_is_equal() - Check if two GPIO descriptors refer to the same pin.
- * @desc: Descriptor to compare.
- * @other: The second descriptor to compare against.
- *
- * Returns:
- * True if the descriptors refer to the same physical pin. False otherwise.
- */
-bool gpiod_is_equal(const struct gpio_desc *desc, const struct gpio_desc *other)
-{
-	return desc == other;
-}
-EXPORT_SYMBOL_GPL(gpiod_is_equal);
-
 /**
  * gpio_device_get_base() - Get the base GPIO number allocated by this device
  * @gdev: GPIO device
@@ -400,6 +386,21 @@ static int validate_desc(const struct gpio_desc *desc, const char *func)
 		return; \
 	} while (0)
 
+/**
+ * gpiod_is_equal() - Check if two GPIO descriptors refer to the same pin.
+ * @desc: Descriptor to compare.
+ * @other: The second descriptor to compare against.
+ *
+ * Returns:
+ * True if the descriptors refer to the same physical pin. False otherwise.
+ */
+bool gpiod_is_equal(const struct gpio_desc *desc, const struct gpio_desc *other)
+{
+	return validate_desc(desc, __func__) > 0 &&
+	       !IS_ERR_OR_NULL(other) && desc == other;
+}
+EXPORT_SYMBOL_GPL(gpiod_is_equal);
+
 static int gpiochip_get_direction(struct gpio_chip *gc, unsigned int offset)
 {
 	int ret;

-- 
2.48.1


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] gpio: make gpiod_is_equal() arguments stricter
  2025-06-20 12:58 ` [PATCH 2/2] gpio: make gpiod_is_equal() arguments stricter Bartosz Golaszewski
@ 2025-06-21 19:12   ` Andy Shevchenko
  2025-06-24 19:25   ` Linus Walleij
  1 sibling, 0 replies; 6+ messages in thread
From: Andy Shevchenko @ 2025-06-21 19:12 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Linus Walleij, linux-gpio, linux-kernel, Bartosz Golaszewski,
	Andy Shevchenko

Fri, Jun 20, 2025 at 02:58:02PM +0200, Bartosz Golaszewski kirjoitti:
> 
> It makes no sense for a GPIO descriptor comparator to return true when
> the arguments passed to it are NULL or IS_ERR(). Let's validate both and
> return false unless both are valid GPIO descriptors.

Acked-by: Andy Shevchenko <andriy.shevchenko@intel.com>

-- 
With Best Regards,
Andy Shevchenko



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] gpio: make gpiod_is_equal() arguments stricter
  2025-06-20 12:58 ` [PATCH 2/2] gpio: make gpiod_is_equal() arguments stricter Bartosz Golaszewski
  2025-06-21 19:12   ` Andy Shevchenko
@ 2025-06-24 19:25   ` Linus Walleij
  1 sibling, 0 replies; 6+ messages in thread
From: Linus Walleij @ 2025-06-24 19:25 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: linux-gpio, linux-kernel, Bartosz Golaszewski, Andy Shevchenko

On Fri, Jun 20, 2025 at 2:58 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote:

> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> It makes no sense for a GPIO descriptor comparator to return true when
> the arguments passed to it are NULL or IS_ERR(). Let's validate both and
> return false unless both are valid GPIO descriptors.
>
> Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> Link: https://lore.kernel.org/all/Z_aFBfjb17JxOwyk@black.fi.intel.com/
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] gpio: improve gpiod_is_equal()
  2025-06-20 12:58 [PATCH 0/2] gpio: improve gpiod_is_equal() Bartosz Golaszewski
  2025-06-20 12:58 ` [PATCH 1/2] gpio: constify arguments of gpiod_is_equal() Bartosz Golaszewski
  2025-06-20 12:58 ` [PATCH 2/2] gpio: make gpiod_is_equal() arguments stricter Bartosz Golaszewski
@ 2025-06-30  6:58 ` Bartosz Golaszewski
  2 siblings, 0 replies; 6+ messages in thread
From: Bartosz Golaszewski @ 2025-06-30  6:58 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski
  Cc: Bartosz Golaszewski, linux-gpio, linux-kernel, Andy Shevchenko

From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>


On Fri, 20 Jun 2025 14:58:00 +0200, Bartosz Golaszewski wrote:
> This short series contains small improvements to the gpiod_is_equal()
> GPIO descriptor comparator added last cycle.
> 
> 

Applied, thanks!

[1/2] gpio: constify arguments of gpiod_is_equal()
      https://git.kernel.org/brgl/linux/c/08ad63bbd681ae4eeb50644564435035c38e5795
[2/2] gpio: make gpiod_is_equal() arguments stricter
      https://git.kernel.org/brgl/linux/c/26981e8906bb5c902e2d34874f64ecfa975d28c8

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2025-06-30  6:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-20 12:58 [PATCH 0/2] gpio: improve gpiod_is_equal() Bartosz Golaszewski
2025-06-20 12:58 ` [PATCH 1/2] gpio: constify arguments of gpiod_is_equal() Bartosz Golaszewski
2025-06-20 12:58 ` [PATCH 2/2] gpio: make gpiod_is_equal() arguments stricter Bartosz Golaszewski
2025-06-21 19:12   ` Andy Shevchenko
2025-06-24 19:25   ` Linus Walleij
2025-06-30  6:58 ` [PATCH 0/2] gpio: improve gpiod_is_equal() Bartosz Golaszewski

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).