2024-02-19 17:38:49

by Emil Renner Berthing

[permalink] [raw]
Subject: [PATCH v1] gpiolib: Handle no pin_ranges in gpiochip_generic_config()

Similar to gpiochip_generic_request() and gpiochip_generic_free() the
gpiochip_generic_config() function needs to handle the case where there
are no pinctrl pins mapped to the GPIOs, usually through the gpio-ranges
device tree property.

Commit f34fd6ee1be8 ("gpio: dwapb: Use generic request, free and
set_config") set the .set_config callback to gpiochip_generic_config()
in the dwapb GPIO driver so the GPIO API can set pinctrl configuration
for the corresponding pins. Most boards using the dwapb driver do not
set the gpio-ranges device tree property though, and in this case
gpiochip_generic_config() would return -EPROPE_DEFER rather than the
previous -ENOTSUPP return value. This in turn makes
gpio_set_config_with_argument_optional() fail and propagate the error to
any driver requesting GPIOs.

Fixes: 2956b5d94a76 ("pinctrl / gpio: Introduce .set_config() callback for GPIO chips")
Reported-by: Jisheng Zhang <[email protected]>
Closes: https://lore.kernel.org/linux-gpio/ZdC_g3U4l0CJIWzh@xhacker/
Tested-by: Jisheng Zhang <[email protected]>
Signed-off-by: Emil Renner Berthing <[email protected]>
---
Hi Linus,

I didn't add your rb since I don't think
if (IS_ENABLED(CONFIG_PINCTRL) && list_empty(&gc->gpiodev->pin_ranges))
will work when the pin_ranges member is only there then when
CONFIG_PINCTRL is defined and it seemed like your rb was on the
condition that I used that.

/Emil

drivers/gpio/gpiolib.c | 5 +++++
1 file changed, 5 insertions(+)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 8b3a0f45b574..e434e8cc1229 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2042,6 +2042,11 @@ EXPORT_SYMBOL_GPL(gpiochip_generic_free);
int gpiochip_generic_config(struct gpio_chip *gc, unsigned int offset,
unsigned long config)
{
+#ifdef CONFIG_PINCTRL
+ if (list_empty(&gc->gpiodev->pin_ranges))
+ return -ENOTSUPP;
+#endif
+
return pinctrl_gpio_set_config(gc, offset, config);
}
EXPORT_SYMBOL_GPL(gpiochip_generic_config);
--
2.43.0



2024-02-20 08:41:48

by Linus Walleij

[permalink] [raw]
Subject: Re: [PATCH v1] gpiolib: Handle no pin_ranges in gpiochip_generic_config()

On Mon, Feb 19, 2024 at 6:25 PM Emil Renner Berthing
<[email protected]> wrote:

> Similar to gpiochip_generic_request() and gpiochip_generic_free() the
> gpiochip_generic_config() function needs to handle the case where there
> are no pinctrl pins mapped to the GPIOs, usually through the gpio-ranges
> device tree property.
>
> Commit f34fd6ee1be8 ("gpio: dwapb: Use generic request, free and
> set_config") set the .set_config callback to gpiochip_generic_config()
> in the dwapb GPIO driver so the GPIO API can set pinctrl configuration
> for the corresponding pins. Most boards using the dwapb driver do not
> set the gpio-ranges device tree property though, and in this case
> gpiochip_generic_config() would return -EPROPE_DEFER rather than the
> previous -ENOTSUPP return value. This in turn makes
> gpio_set_config_with_argument_optional() fail and propagate the error to
> any driver requesting GPIOs.
>
> Fixes: 2956b5d94a76 ("pinctrl / gpio: Introduce .set_config() callback for GPIO chips")
> Reported-by: Jisheng Zhang <[email protected]>
> Closes: https://lore.kernel.org/linux-gpio/ZdC_g3U4l0CJIWzh@xhacker/
> Tested-by: Jisheng Zhang <[email protected]>
> Signed-off-by: Emil Renner Berthing <[email protected]>

Reviewed-by: Linus Walleij <[email protected]>

> I didn't add your rb since I don't think
> if (IS_ENABLED(CONFIG_PINCTRL) && list_empty(&gc->gpiodev->pin_ranges))
> will work when the pin_ranges member is only there then when
> CONFIG_PINCTRL is defined and it seemed like your rb was on the
> condition that I used that.

I was wrong about that!

Yours,
Linus Walleij

2024-02-20 14:40:08

by Bartosz Golaszewski

[permalink] [raw]
Subject: Re: [PATCH v1] gpiolib: Handle no pin_ranges in gpiochip_generic_config()

On Mon, Feb 19, 2024 at 6:25 PM Emil Renner Berthing
<[email protected]> wrote:
>
> Similar to gpiochip_generic_request() and gpiochip_generic_free() the
> gpiochip_generic_config() function needs to handle the case where there
> are no pinctrl pins mapped to the GPIOs, usually through the gpio-ranges
> device tree property.
>
> Commit f34fd6ee1be8 ("gpio: dwapb: Use generic request, free and
> set_config") set the .set_config callback to gpiochip_generic_config()
> in the dwapb GPIO driver so the GPIO API can set pinctrl configuration
> for the corresponding pins. Most boards using the dwapb driver do not
> set the gpio-ranges device tree property though, and in this case
> gpiochip_generic_config() would return -EPROPE_DEFER rather than the
> previous -ENOTSUPP return value. This in turn makes
> gpio_set_config_with_argument_optional() fail and propagate the error to
> any driver requesting GPIOs.
>
> Fixes: 2956b5d94a76 ("pinctrl / gpio: Introduce .set_config() callback for GPIO chips")
> Reported-by: Jisheng Zhang <[email protected]>
> Closes: https://lore.kernel.org/linux-gpio/ZdC_g3U4l0CJIWzh@xhacker/
> Tested-by: Jisheng Zhang <[email protected]>
> Signed-off-by: Emil Renner Berthing <[email protected]>
> ---

Applied, thanks!

Bart