public inbox for stable@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] gpiolib: normalize the return value of gc->get() on behalf of buggy drivers
@ 2026-02-19  9:51 Bartosz Golaszewski
  2026-02-19 16:59 ` Dmitry Torokhov
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2026-02-19  9:51 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Dmitry Torokhov
  Cc: linux-gpio, linux-kernel, stable, Bartosz Golaszewski

Commit 86ef402d805d ("gpiolib: sanitize the return value of
gpio_chip::get()") started checking the return value of the .get()
callback in struct gpio_chip. Now - almost a year later - it turns out
that there are quite a few drivers in tree that can break with this
change. Partially revert it: normalize the return value in GPIO core but
also emit a warning.

Cc: stable@vger.kernel.org
Fixes: 86ef402d805d ("gpiolib: sanitize the return value of gpio_chip::get()")
Reported-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Closes: https://lore.kernel.org/all/aZSkqGTqMp_57qC7@google.com/
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
---
Changes in v2:
- it's gpio_chip::get() that needs normalizing, not gpio_chip::set()
- Link to v1: https://patch.msgid.link/20260219-gpiolib-set-normalize-v1-1-f0d53a009db4@oss.qualcomm.com
---
 drivers/gpio/gpiolib.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index c52200eaaaff82b12f22dd1ee8459bdd8ec10d81..c9cd751e7de2307fc5994eb682c53f2b3ce39233 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -3268,8 +3268,12 @@ static int gpiochip_get(struct gpio_chip *gc, unsigned int offset)
 
 	/* Make sure this is called after checking for gc->get(). */
 	ret = gc->get(gc, offset);
-	if (ret > 1)
-		ret = -EBADE;
+	if (ret > 1) {
+		gpiochip_warn(gc,
+			"invalid return value from gc->get(): %d, consider fixing the driver\n",
+			ret);
+		ret = !!ret;
+	}
 
 	return ret;
 }

---
base-commit: 50f68cc7be0a2cbf54d8f6aaf17df32fb01acc3f
change-id: 20260219-gpiolib-set-normalize-1080e2eda113

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] gpiolib: normalize the return value of gc->get() on behalf of buggy drivers
  2026-02-19  9:51 [PATCH v2] gpiolib: normalize the return value of gc->get() on behalf of buggy drivers Bartosz Golaszewski
@ 2026-02-19 16:59 ` Dmitry Torokhov
  2026-02-19 17:32 ` Linus Walleij
  2026-02-23 10:49 ` Bartosz Golaszewski
  2 siblings, 0 replies; 4+ messages in thread
From: Dmitry Torokhov @ 2026-02-19 16:59 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Linus Walleij, Bartosz Golaszewski, linux-gpio, linux-kernel,
	stable

On Thu, Feb 19, 2026 at 10:51:33AM +0100, Bartosz Golaszewski wrote:
> Commit 86ef402d805d ("gpiolib: sanitize the return value of
> gpio_chip::get()") started checking the return value of the .get()
> callback in struct gpio_chip. Now - almost a year later - it turns out
> that there are quite a few drivers in tree that can break with this
> change. Partially revert it: normalize the return value in GPIO core but
> also emit a warning.
> 
> Cc: stable@vger.kernel.org
> Fixes: 86ef402d805d ("gpiolib: sanitize the return value of gpio_chip::get()")
> Reported-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Closes: https://lore.kernel.org/all/aZSkqGTqMp_57qC7@google.com/
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
> ---
> Changes in v2:
> - it's gpio_chip::get() that needs normalizing, not gpio_chip::set()
> - Link to v1: https://patch.msgid.link/20260219-gpiolib-set-normalize-v1-1-f0d53a009db4@oss.qualcomm.com
> ---
>  drivers/gpio/gpiolib.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index c52200eaaaff82b12f22dd1ee8459bdd8ec10d81..c9cd751e7de2307fc5994eb682c53f2b3ce39233 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -3268,8 +3268,12 @@ static int gpiochip_get(struct gpio_chip *gc, unsigned int offset)
>  
>  	/* Make sure this is called after checking for gc->get(). */
>  	ret = gc->get(gc, offset);
> -	if (ret > 1)
> -		ret = -EBADE;
> +	if (ret > 1) {
> +		gpiochip_warn(gc,
> +			"invalid return value from gc->get(): %d, consider fixing the driver\n",
> +			ret);
> +		ret = !!ret;
> +	}
>  
>  	return ret;
>  }

Thank you Bartosz. I guess this could turn out to be pretty noisy but
maybe that will make users report it faster ;)

Reviewed-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

-- 
Dmitry

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] gpiolib: normalize the return value of gc->get() on behalf of buggy drivers
  2026-02-19  9:51 [PATCH v2] gpiolib: normalize the return value of gc->get() on behalf of buggy drivers Bartosz Golaszewski
  2026-02-19 16:59 ` Dmitry Torokhov
@ 2026-02-19 17:32 ` Linus Walleij
  2026-02-23 10:49 ` Bartosz Golaszewski
  2 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2026-02-19 17:32 UTC (permalink / raw)
  To: Bartosz Golaszewski
  Cc: Bartosz Golaszewski, Dmitry Torokhov, linux-gpio, linux-kernel,
	stable

On Thu, Feb 19, 2026 at 10:51 AM Bartosz Golaszewski
<bartosz.golaszewski@oss.qualcomm.com> wrote:

> Commit 86ef402d805d ("gpiolib: sanitize the return value of
> gpio_chip::get()") started checking the return value of the .get()
> callback in struct gpio_chip. Now - almost a year later - it turns out
> that there are quite a few drivers in tree that can break with this
> change. Partially revert it: normalize the return value in GPIO core but
> also emit a warning.
>
> Cc: stable@vger.kernel.org
> Fixes: 86ef402d805d ("gpiolib: sanitize the return value of gpio_chip::get()")
> Reported-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
> Closes: https://lore.kernel.org/all/aZSkqGTqMp_57qC7@google.com/
> Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

Reviewed-by: Linus Walleij <linusw@kernel.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH v2] gpiolib: normalize the return value of gc->get() on behalf of buggy drivers
  2026-02-19  9:51 [PATCH v2] gpiolib: normalize the return value of gc->get() on behalf of buggy drivers Bartosz Golaszewski
  2026-02-19 16:59 ` Dmitry Torokhov
  2026-02-19 17:32 ` Linus Walleij
@ 2026-02-23 10:49 ` Bartosz Golaszewski
  2 siblings, 0 replies; 4+ messages in thread
From: Bartosz Golaszewski @ 2026-02-23 10:49 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, Dmitry Torokhov,
	Bartosz Golaszewski
  Cc: linux-gpio, linux-kernel, stable


On Thu, 19 Feb 2026 10:51:33 +0100, Bartosz Golaszewski wrote:
> Commit 86ef402d805d ("gpiolib: sanitize the return value of
> gpio_chip::get()") started checking the return value of the .get()
> callback in struct gpio_chip. Now - almost a year later - it turns out
> that there are quite a few drivers in tree that can break with this
> change. Partially revert it: normalize the return value in GPIO core but
> also emit a warning.
> 
> [...]

Applied, thanks!

[1/1] gpiolib: normalize the return value of gc->get() on behalf of buggy drivers
      https://git.kernel.org/brgl/c/ec2cceadfae72304ca19650f9cac4b2a97b8a2fc

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-02-23 10:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-19  9:51 [PATCH v2] gpiolib: normalize the return value of gc->get() on behalf of buggy drivers Bartosz Golaszewski
2026-02-19 16:59 ` Dmitry Torokhov
2026-02-19 17:32 ` Linus Walleij
2026-02-23 10:49 ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox