diff mbox series

gpiolib: don't bail out if get_direction() fails in gpiochip_add_data()

Message ID 20250219144356.258635-1-brgl@bgdev.pl
State New
Headers show
Series gpiolib: don't bail out if get_direction() fails in gpiochip_add_data() | expand

Commit Message

Bartosz Golaszewski Feb. 19, 2025, 2:43 p.m. UTC
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Since commit 9d846b1aebbe ("gpiolib: check the return value of
gpio_chip::get_direction()") we check the return value of the
get_direction() callback as per its API contract. Some drivers have been
observed to fail to register now as they may call get_direction() in
gpiochip_add_data() in contexts where it has always silently failed.
Until we audit all drivers, replace the bail-out to a kernel log
warning.

Fixes: 9d846b1aebbe ("gpiolib: check the return value of gpio_chip::get_direction()")
Reported-by: Mark Brown <broonie@kernel.org>
Closes: https://lore.kernel.org/all/Z7VFB1nST6lbmBIo@finisterre.sirena.org.uk/
Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
Closes: https://lore.kernel.org/all/dfe03f88-407e-4ef1-ad30-42db53bbd4e4@samsung.com/
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 drivers/gpio/gpiolib.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

Comments

Marek Szyprowski Feb. 20, 2025, 9:17 a.m. UTC | #1
On 19.02.2025 15:43, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
>
> Since commit 9d846b1aebbe ("gpiolib: check the return value of
> gpio_chip::get_direction()") we check the return value of the
> get_direction() callback as per its API contract. Some drivers have been
> observed to fail to register now as they may call get_direction() in
> gpiochip_add_data() in contexts where it has always silently failed.
> Until we audit all drivers, replace the bail-out to a kernel log
> warning.
>
> Fixes: 9d846b1aebbe ("gpiolib: check the return value of gpio_chip::get_direction()")
> Reported-by: Mark Brown <broonie@kernel.org>
> Closes: https://lore.kernel.org/all/Z7VFB1nST6lbmBIo@finisterre.sirena.org.uk/
> Reported-by: Marek Szyprowski <m.szyprowski@samsung.com>
> Closes: https://lore.kernel.org/all/dfe03f88-407e-4ef1-ad30-42db53bbd4e4@samsung.com/
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>

This fixes the issue observed on RPi boards without any changes to 
gpio/pinctrl driver.

> ---
>   drivers/gpio/gpiolib.c | 10 +++++++++-
>   1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index 704452fd94bb..48cf1bb23e24 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -1060,7 +1060,15 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
>   		if (gc->get_direction && gpiochip_line_is_valid(gc, desc_index)) {
>   			ret = gc->get_direction(gc, desc_index);
>   			if (ret < 0)
> -				goto err_cleanup_desc_srcu;
> +				/*
> +				 * FIXME: Bail-out here once all GPIO drivers
> +				 * are updated to not return errors in
> +				 * situations that can be considered normal
> +				 * operation.
> +				 */
> +				dev_warn(&gdev->dev,
> +					 "%s: get_direction failed: %d\n",
> +					 __func__, ret);
>   
>   			assign_bit(FLAG_IS_OUT, &desc->flags, !ret);
>   		} else {

Best regards
Bartosz Golaszewski Feb. 20, 2025, 1:09 p.m. UTC | #2
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>


On Wed, 19 Feb 2025 15:43:56 +0100, Bartosz Golaszewski wrote:
> Since commit 9d846b1aebbe ("gpiolib: check the return value of
> gpio_chip::get_direction()") we check the return value of the
> get_direction() callback as per its API contract. Some drivers have been
> observed to fail to register now as they may call get_direction() in
> gpiochip_add_data() in contexts where it has always silently failed.
> Until we audit all drivers, replace the bail-out to a kernel log
> warning.
> 
> [...]

Applied, thanks!

[1/1] gpiolib: don't bail out if get_direction() fails in gpiochip_add_data()
      commit: 96fa9ec477ff60bed87e1441fd43e003179f3253

Best regards,
diff mbox series

Patch

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 704452fd94bb..48cf1bb23e24 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1060,7 +1060,15 @@  int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data,
 		if (gc->get_direction && gpiochip_line_is_valid(gc, desc_index)) {
 			ret = gc->get_direction(gc, desc_index);
 			if (ret < 0)
-				goto err_cleanup_desc_srcu;
+				/*
+				 * FIXME: Bail-out here once all GPIO drivers
+				 * are updated to not return errors in
+				 * situations that can be considered normal
+				 * operation.
+				 */
+				dev_warn(&gdev->dev,
+					 "%s: get_direction failed: %d\n",
+					 __func__, ret);
 
 			assign_bit(FLAG_IS_OUT, &desc->flags, !ret);
 		} else {