Re: [PATCH v1] gpiolib: fix trace on missing gpiochip->get_direction callback

From: Bartosz Golaszewski

Date: Thu Apr 09 2026 - 10:29:47 EST


On Thu, 9 Apr 2026 15:27:23 +0200, Frank Wunderlich <linux@xxxxxxxxx> said:
> From: Frank Wunderlich <frank-w@xxxxxxxxxxxxxxx>
>
> 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()")
> Signed-off-by: Frank Wunderlich <frank-w@xxxxxxxxxxxxxxx>
> ---
> drivers/gpio/gpiolib.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 86a171e96b0e..302cbd7989f3 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -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);
> --
> 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?

diff --git a/drivers/pinctrl/mediatek/pinctrl-moore.c
b/drivers/pinctrl/mediatek/pinctrl-moore.c
index 70f608347a5f6..071ba849e5322 100644
--- a/drivers/pinctrl/mediatek/pinctrl-moore.c
+++ b/drivers/pinctrl/mediatek/pinctrl-moore.c
@@ -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