* [PATCH] gpiolib: Check gc->get_direction() before calling gpiod_get_direction()
@ 2026-07-29 9:47 Christophe Leroy (CS GROUP)
2026-07-31 8:32 ` Bartosz Golaszewski
0 siblings, 1 reply; 2+ messages in thread
From: Christophe Leroy (CS GROUP) @ 2026-07-29 9:47 UTC (permalink / raw)
To: RAGUENES Jean Noel, Linus Walleij, Bartosz Golaszewski
Cc: Christophe Leroy (CS GROUP), linux-gpio, linux-kernel
According to 'struct gpio_chip' documentation in linux/gpio/driver.h,
implementing .get_direction() is recommended but not mandatory.
Most places verify that gc->get_direction() exists before calling
gpiod_get_direction(), but gpiolib_dbg_show() doesn't.
Until commit 471e998c0e31 ("gpiolib: remove redundant callback check")
it was also verified by gpiod_get_direction() itself so calling it at
all time from gpiolib_dbg_show() was not an issue. But after the check
in gpiod_get_direction() has been removed, calling it inconditionaly
leads to a big fat warning in gpiochip_get_direction().
In gpiod_get_direction(), verify that gc->get_direction() exists
before calling gpiod_get_direction().
Fixes: 471e998c0e31 ("gpiolib: remove redundant callback check")
Signed-off-by: Christophe Leroy (CS GROUP) <chleroy@kernel.org>
---
drivers/gpio/gpiolib.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index e5fb60111151..6abf73bf056a 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -5417,7 +5417,8 @@ static void gpiolib_dbg_show(struct seq_file *s, struct gpio_chip *gc)
flags = READ_ONCE(desc->flags);
is_irq = test_bit(GPIOD_FLAG_USED_AS_IRQ, &flags);
if (is_irq || test_bit(GPIOD_FLAG_REQUESTED, &flags)) {
- gpiod_get_direction(desc);
+ if (gc->get_direction)
+ gpiod_get_direction(desc);
is_out = test_bit(GPIOD_FLAG_IS_OUT, &flags);
value = gpio_chip_get_value(gc, desc);
active_low = test_bit(GPIOD_FLAG_ACTIVE_LOW, &flags);
--
2.54.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] gpiolib: Check gc->get_direction() before calling gpiod_get_direction()
2026-07-29 9:47 [PATCH] gpiolib: Check gc->get_direction() before calling gpiod_get_direction() Christophe Leroy (CS GROUP)
@ 2026-07-31 8:32 ` Bartosz Golaszewski
0 siblings, 0 replies; 2+ messages in thread
From: Bartosz Golaszewski @ 2026-07-31 8:32 UTC (permalink / raw)
To: RAGUENES Jean Noel, Linus Walleij, Bartosz Golaszewski,
Christophe Leroy (CS GROUP)
Cc: Bartosz Golaszewski, linux-gpio, linux-kernel
On Wed, 29 Jul 2026 11:47:20 +0200, Christophe Leroy (CS GROUP) wrote:
> According to 'struct gpio_chip' documentation in linux/gpio/driver.h,
> implementing .get_direction() is recommended but not mandatory.
> Most places verify that gc->get_direction() exists before calling
> gpiod_get_direction(), but gpiolib_dbg_show() doesn't.
>
> Until commit 471e998c0e31 ("gpiolib: remove redundant callback check")
> it was also verified by gpiod_get_direction() itself so calling it at
> all time from gpiolib_dbg_show() was not an issue. But after the check
> in gpiod_get_direction() has been removed, calling it inconditionaly
> leads to a big fat warning in gpiochip_get_direction().
>
> [...]
Applied, thanks!
[1/1] gpiolib: Check gc->get_direction() before calling gpiod_get_direction()
https://git.kernel.org/brgl/c/d761c7e38a000603a9d16270a1af770a0e8efb5e
Best regards,
--
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-07-31 8:32 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-29 9:47 [PATCH] gpiolib: Check gc->get_direction() before calling gpiod_get_direction() Christophe Leroy (CS GROUP)
2026-07-31 8:32 ` Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®