Skip to contentSkip to conversation

gpiolib: fix trace on missing gpiochip->get_direction callback

PATCH In review Frank Wunderlich 3 participants 3 messages Apr 9

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpiolib: fix trace on missing gpiochip->get_direction callback

From: Frank Wunderlich <[email protected]>

if gpio_chip.get_direction callback is not implemented (e.g. pinctrl-moore) there is a bunch of traces because of this.

Just remove the WARN_ON to avoid traces and restore previous behaviour but keep the sanitization active.

Fixes 471e998c0e31 ("gpiolib: remove redundant callback check")
Fixes e623c4303ed1 ("gpiolib: sanitize the return value of gpio_chip::get_direction()")
---
 drivers/gpio/gpiolib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpiolib.c +1 -1
index 86a171e96b0e..302cbd7989f3 100644
@@ -420,7 +420,7 @@ static int gpiochip_get_direction(struct gpio_chip *gc, unsigned int offset)
 
 	lockdep_assert_held(&gc->gpiodev->srcu);
 
-	if (WARN_ON(!gc->get_direction))
+	if (!gc->get_direction)
 		return -EOPNOTSUPP;
 
 	ret = gc->get_direction(gc, offset);
Signature · 1 line
2.43.0
#1 lore raw
Quoted 29 lines · Frank Wunderlich

From: Frank Wunderlich <[email protected]>

if gpio_chip.get_direction callback is not implemented (e.g. pinctrl-moore) there is a bunch of traces because of this.

Just remove the WARN_ON to avoid traces and restore previous behaviour but keep the sanitization active.

Fixes 471e998c0e31 ("gpiolib: remove redundant callback check")
Fixes e623c4303ed1 ("gpiolib: sanitize the return value of gpio_chip::get_direction()")
---
 drivers/gpio/gpiolib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpiolib.c +1 -2
index 86a171e96b0e..302cbd7989f3 100644
@@ -420,7 +420,7 @@ static int gpiochip_get_direction(struct gpio_chip *gc, unsigned int offset)
 
 	lockdep_assert_held(&gc->gpiodev->srcu);
 
-	if (WARN_ON(!gc->get_direction))
+	if (!gc->get_direction)
 		return -EOPNOTSUPP;
 
 	ret = gc->get_direction(gc, offset);
--
Quoted 3 lines

2.43.0

I prefer GPIO drivers to just implement get_direction(). Looking at the code it should be pretty straightforward for this driver.

Can you test if the following works for you?

(quoted diff) +0 -0

b/drivers/pinctrl/mediatek/pinctrl-moore.c
index 70f608347a5f6..071ba849e5322 100644

drivers/pinctrl/mediatek/pinctrl-moore.c +0 -0
@@ -520,6 +520,23 @@ static int mtk_gpio_direction_output(struct

gpio_chip *chip, unsigned int gpio,
return pinctrl_gpio_direction_output(chip, gpio);
}

+static int mtk_gpio_get_direction(struct gpio_chip *chip, unsigned int offset) +{
+ struct mtk_pinctrl *hw = gpiochip_get_data(chip);
+ const struct mtk_pin_desc *desc;
+ int ret, dir;
+
+ desc = (const struct mtk_pin_desc *)&hw->soc->pins[offset];
+ if (!desc->name)
+ return -ENOTSUPP;
+
+ ret = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DIR, &dir);
+ if (ret)
+ return ret;
+
+ return dir ? GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN;
+}
+
static int mtk_gpio_to_irq(struct gpio_chip *chip, unsigned int offset) {
struct mtk_pinctrl *hw = gpiochip_get_data(chip);
@@ -566,6 +583,7 @@ static int mtk_build_gpiochip(struct mtk_pinctrl *hw)
chip->parent = hw->dev;
chip->request = gpiochip_generic_request;
chip->free = gpiochip_generic_free;
+ chip->get_direction = mtk_gpio_get_direction;
chip->direction_input = pinctrl_gpio_direction_input;
chip->direction_output = mtk_gpio_direction_output;
chip->get = mtk_gpio_get;

Thanks,
Bart

#2 lore raw

Hi

Quoted 39 lines

Gesendet: Donnerstag, 9. April 2026 um 16:23
Von: "Bartosz Golaszewski" <[email protected]>

I prefer GPIO drivers to just implement get_direction(). Looking at the code it should be pretty straightforward for this driver.

Can you test if the following works for you?

drivers/pinctrl/mediatek/pinctrl-moore.c +17 -0
index 70f608347a5f6..071ba849e5322 100644
@@ -520,6 +520,23 @@ static int mtk_gpio_direction_output(struct
 gpio_chip *chip, unsigned int gpio,
 	return pinctrl_gpio_direction_output(chip, gpio);
 }
 
+static int mtk_gpio_get_direction(struct gpio_chip *chip, unsigned int offset)
+{
+	struct mtk_pinctrl *hw = gpiochip_get_data(chip);
+	const struct mtk_pin_desc *desc;
+	int ret, dir;
+
+	desc = (const struct mtk_pin_desc *)&amp;hw->soc->pins[offset];
+	if (!desc->name)
+		return -ENOTSUPP;
+
+	ret = mtk_hw_get_value(hw, desc, PINCTRL_PIN_REG_DIR, &amp;dir);
+	if (ret)
+		return ret;
+
+	return dir ? GPIO_LINE_DIRECTION_OUT : GPIO_LINE_DIRECTION_IN;
+}
+
 static int mtk_gpio_to_irq(struct gpio_chip *chip, unsigned int offset)
 {
drivers/pinctrl/mediatek/pinctrl-moore.c +0 -0
 	struct mtk_pinctrl *hw = gpiochip_get_data(chip);

drivers/pinctrl/mediatek/pinctrl-moore.c static int mtk_build_gpiochip(struct mtk_pinctrl *hw) · line 589

Quoted 7 lines
drivers/pinctrl/mediatek/pinctrl-moore.c +1 -0
@@ -566,6 +583,7 @@ static int mtk_build_gpiochip(struct mtk_pinctrl *hw)
 	chip->parent		= hw->dev;
 	chip->request		= gpiochip_generic_request;
 	chip->free		= gpiochip_generic_free;
+	chip->get_direction	= mtk_gpio_get_direction;
 	chip->direction_input	= pinctrl_gpio_direction_input;
 	chip->direction_output	= mtk_gpio_direction_output;
 	chip->get		= mtk_gpio_get;

it looks good on a quick test, just reverted my patch and applied yours and got no trace

root@bpi-r4:~# cat /sys/kernel/debug/gpio 
gpiochip0: 84 GPIOs, parent: platform/1001f000.pinctrl, pinctrl_moore:
 gpio-0   (                    |tx-disable          ) in  lo 
 gpio-1   (                    |mod-def0            ) in  hi IRQ ACTIVE LOW
 gpio-2   (                    |los                 ) in  hi IRQ 
 gpio-12  (                    |cd                  ) in  lo IRQ ACTIVE LOW
 gpio-13  (                    |reset               ) in  hi IRQ ACTIVE LOW
 gpio-14  (                    |WPS                 ) in  hi IRQ ACTIVE LOW
 gpio-21  (                    |tx-disable          ) out hi 
 gpio-69  (                    |mod-def0            ) in  lo IRQ ACTIVE LOW
 gpio-70  (                    |los                 ) in  hi IRQ 

gpiochip1: 16 GPIOs, parent: i2c/3-0020, 3-0020, can sleep:

 gpio-14  (                    |blue:activity       ) out lo 
 gpio-15  (                    |red:fault           ) out lo 

output seems correct.

regards Frank

Quoted 2 lines

Thanks,
Bart