]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
gpiolib: Check gc->get_direction() before calling gpiod_get_direction()
authorChristophe Leroy (CS GROUP) <chleroy@kernel.org>
Wed, 29 Jul 2026 09:47:20 +0000 (11:47 +0200)
committerBartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
Fri, 31 Jul 2026 08:32:47 +0000 (10:32 +0200)
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>
Link: https://patch.msgid.link/ad89f92f91d004e63dd5599bb58e9581f373a601.1785318183.git.chleroy@kernel.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
drivers/gpio/gpiolib.c

index c433a095907fe6ea0fb0a3e1234bcf1f37042cde..ef8ccaf17c9cee387bee377c0cb674242b79bd51 100644 (file)
@@ -5420,7 +5420,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);