* [PATCH v1] gpiolib: fix trace on missing gpiochip->get_direction callback
@ 2026-04-09 13:27 Frank Wunderlich
2026-04-09 14:23 ` Bartosz Golaszewski
0 siblings, 1 reply; 3+ messages in thread
From: Frank Wunderlich @ 2026-04-09 13:27 UTC (permalink / raw)
To: Linus Walleij, Bartosz Golaszewski
Cc: Frank Wunderlich, linux-gpio, linux-kernel, Daniel Golle
From: Frank Wunderlich <frank-w@public-files.de>
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@public-files.de>
---
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
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v1] gpiolib: fix trace on missing gpiochip->get_direction callback 2026-04-09 13:27 [PATCH v1] gpiolib: fix trace on missing gpiochip->get_direction callback Frank Wunderlich @ 2026-04-09 14:23 ` Bartosz Golaszewski 2026-04-09 20:42 ` Aw: " Frank Wunderlich 0 siblings, 1 reply; 3+ messages in thread From: Bartosz Golaszewski @ 2026-04-09 14:23 UTC (permalink / raw) To: Frank Wunderlich Cc: Frank Wunderlich, linux-gpio, linux-kernel, Daniel Golle, Linus Walleij, Bartosz Golaszewski On Thu, 9 Apr 2026 15:27:23 +0200, Frank Wunderlich <linux@fw-web.de> said: > From: Frank Wunderlich <frank-w@public-files.de> > > 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@public-files.de> > --- > 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 ^ permalink raw reply related [flat|nested] 3+ messages in thread
* Aw: Re: [PATCH v1] gpiolib: fix trace on missing gpiochip->get_direction callback 2026-04-09 14:23 ` Bartosz Golaszewski @ 2026-04-09 20:42 ` Frank Wunderlich 0 siblings, 0 replies; 3+ messages in thread From: Frank Wunderlich @ 2026-04-09 20:42 UTC (permalink / raw) To: brgl, linux; +Cc: linux-gpio, linux-kernel, daniel, linusw, brgl Hi > Gesendet: Donnerstag, 9. April 2026 um 16:23 > Von: "Bartosz Golaszewski" <brgl@kernel.org> > > 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; 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 > Thanks, > Bart ^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-04-09 20:42 UTC | newest] Thread overview: 3+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-04-09 13:27 [PATCH v1] gpiolib: fix trace on missing gpiochip->get_direction callback Frank Wunderlich 2026-04-09 14:23 ` Bartosz Golaszewski 2026-04-09 20:42 ` Aw: " Frank Wunderlich
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox