All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpio: make gpio_chip_guard accept const gpio_desc
@ 2026-06-19  8:50 Archit More
  2026-06-19  8:57 ` Bartosz Golaszewski
  0 siblings, 1 reply; 2+ messages in thread
From: Archit More @ 2026-06-19  8:50 UTC (permalink / raw)
  To: linux-gpio; +Cc: linux-kernel, linus.walleij, brgl, Archit More

Make gpio_chip_guard accept a const struct gpio_desc pointer,
allowing gpiod_get_raw_value_commit() and gpiod_to_irq() to use
the helper instead of open-coding SRCU-protected chip lookups.

This removes duplicated code and eliminates the FIXME comments
about gpio_chip_guard being unusable with const descriptors.

Signed-off-by: Archit More <architmore303@gmail.com>
---
 drivers/gpio/gpiolib.c | 28 ++++++++--------------------
 drivers/gpio/gpiolib.h |  2 +-
 2 files changed, 9 insertions(+), 21 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 1e6dce430dca..3ee924b2ab94 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -3406,20 +3406,13 @@ static int gpio_chip_get_value(struct gpio_chip *gc, const struct gpio_desc *des
 
 static int gpiod_get_raw_value_commit(const struct gpio_desc *desc)
 {
-	struct gpio_device *gdev;
-	struct gpio_chip *gc;
 	int value;
 
-	/* FIXME Unable to use gpio_chip_guard due to const desc. */
-	gdev = desc->gdev;
-
-	guard(srcu)(&gdev->srcu);
-
-	gc = srcu_dereference(gdev->chip, &gdev->srcu);
-	if (!gc)
+	CLASS(gpio_chip_guard, guard)(desc);
+	if (!guard.gc)
 		return -ENODEV;
 
-	value = gpio_chip_get_value(gc, desc);
+	value = gpio_chip_get_value(guard.gc, desc);
 	value = value < 0 ? value : !!value;
 	trace_gpio_value(desc_to_gpio(desc), 1, value);
 	return value;
@@ -4126,8 +4119,6 @@ EXPORT_SYMBOL_GPL(gpiod_is_shared);
  */
 int gpiod_to_irq(const struct gpio_desc *desc)
 {
-	struct gpio_device *gdev;
-	struct gpio_chip *gc;
 	int offset;
 	int ret;
 
@@ -4135,16 +4126,13 @@ int gpiod_to_irq(const struct gpio_desc *desc)
 	if (ret <= 0)
 		return -EINVAL;
 
-	gdev = desc->gdev;
-	/* FIXME Cannot use gpio_chip_guard due to const desc. */
-	guard(srcu)(&gdev->srcu);
-	gc = srcu_dereference(gdev->chip, &gdev->srcu);
-	if (!gc)
+	CLASS(gpio_chip_guard, guard)(desc);
+	if (!guard.gc)
 		return -ENODEV;
 
 	offset = gpiod_hwgpio(desc);
-	if (gc->to_irq) {
-		ret = gc->to_irq(gc, offset);
+	if (guard.gc->to_irq) {
+		ret = guard.gc->to_irq(guard.gc, offset);
 		if (ret)
 			return ret;
 
@@ -4152,7 +4140,7 @@ int gpiod_to_irq(const struct gpio_desc *desc)
 		return -ENXIO;
 	}
 #ifdef CONFIG_GPIOLIB_IRQCHIP
-	if (gc->irq.chip) {
+	if (guard.gc->irq.chip) {
 		/*
 		 * Avoid race condition with other code, which tries to lookup
 		 * an IRQ before the irqchip has been properly registered,
diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h
index dc4cb61a9318..841b7f8dba6c 100644
--- a/drivers/gpio/gpiolib.h
+++ b/drivers/gpio/gpiolib.h
@@ -244,7 +244,7 @@ DEFINE_CLASS(gpio_chip_guard,
 
 		_guard;
 	     }),
-	     struct gpio_desc *desc)
+	    const struct gpio_desc *desc)
 
 int gpiod_request(struct gpio_desc *desc, const char *label);
 int gpiod_request_commit(struct gpio_desc *desc, const char *label);
-- 
2.34.1


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

* Re: [PATCH] gpio: make gpio_chip_guard accept const gpio_desc
  2026-06-19  8:50 [PATCH] gpio: make gpio_chip_guard accept const gpio_desc Archit More
@ 2026-06-19  8:57 ` Bartosz Golaszewski
  0 siblings, 0 replies; 2+ messages in thread
From: Bartosz Golaszewski @ 2026-06-19  8:57 UTC (permalink / raw)
  To: Archit More; +Cc: linux-kernel, linus.walleij, brgl, linux-gpio

On Fri, 19 Jun 2026 10:50:36 +0200, Archit More <architmore303@gmail.com> said:
> Make gpio_chip_guard accept a const struct gpio_desc pointer,
> allowing gpiod_get_raw_value_commit() and gpiod_to_irq() to use
> the helper instead of open-coding SRCU-protected chip lookups.
>
> This removes duplicated code and eliminates the FIXME comments
> about gpio_chip_guard being unusable with const descriptors.
>
> Signed-off-by: Archit More <architmore303@gmail.com>
> ---

This was already done in commit aa7e8b7ef031 ("gpio: core: fix const-correctness
of gpio_chip_guard"). Please always base your work on top of current linux-next.

Bart

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

end of thread, other threads:[~2026-06-19  8:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-19  8:50 [PATCH] gpio: make gpio_chip_guard accept const gpio_desc Archit More
2026-06-19  8:57 ` Bartosz Golaszewski

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.