[PATCH] gpiolib: normalize the return value of gc->set() on behalf of buggy drivers

Bartosz Golaszewski posted 1 patch 1 month, 1 week ago
drivers/gpio/gpiolib.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
[PATCH] gpiolib: normalize the return value of gc->set() on behalf of buggy drivers
Posted by Bartosz Golaszewski 1 month, 1 week ago
Commit 86ef402d805d ("gpiolib: sanitize the return value of
gpio_chip::get()") started checking the return value of the .set()
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>
---
 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..9f7a1a1ebd8365fe933c989caf9e8c544fd9ba0f 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2914,8 +2914,12 @@ static int gpiochip_set(struct gpio_chip *gc, unsigned int offset, int value)
 		return -EOPNOTSUPP;
 
 	ret = gc->set(gc, offset, value);
-	if (ret > 0)
-		ret = -EBADE;
+	if (ret > 0) {
+		gpiochip_warn(gc,
+			"invalid return value from gc->set(): %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>
Re: [PATCH] gpiolib: normalize the return value of gc->set() on behalf of buggy drivers
Posted by Dmitry Torokhov 1 month, 1 week ago
On February 19, 2026 12:52:37 AM PST, 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 .set()
>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>
>---
> 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..9f7a1a1ebd8365fe933c989caf9e8c544fd9ba0f 100644
>--- a/drivers/gpio/gpiolib.c
>+++ b/drivers/gpio/gpiolib.c
>@@ -2914,8 +2914,12 @@ static int gpiochip_set(struct gpio_chip *gc, unsigned int offset, int value)
> 		return -EOPNOTSUPP;
> 
> 	ret = gc->set(gc, offset, value);
>-	if (ret > 0)
>-		ret = -EBADE;
>+	if (ret > 0) {
>+		gpiochip_warn(gc,
>+			"invalid return value from gc->set(): %d, consider fixing the driver\n",
>+			ret);
>+		ret = !!ret;
>+	}
> 
> 	return ret;
> }

You want to patch gpiochip_get(). It could be that set() is similarly troublesome, but the report is about get() not working.

Thanks. 
Hi Bartosz, 
-- 
Dmitry
Re: [PATCH] gpiolib: normalize the return value of gc->set() on behalf of buggy drivers
Posted by Bartosz Golaszewski 1 month, 1 week ago
On Thu, 19 Feb 2026 09:57:58 +0100, Dmitry Torokhov
<dmitry.torokhov@gmail.com> said:
> On February 19, 2026 12:52:37 AM PST, 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 .set()
>>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>
>>---
>> 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..9f7a1a1ebd8365fe933c989caf9e8c544fd9ba0f 100644
>>--- a/drivers/gpio/gpiolib.c
>>+++ b/drivers/gpio/gpiolib.c
>>@@ -2914,8 +2914,12 @@ static int gpiochip_set(struct gpio_chip *gc, unsigned int offset, int value)
>> 		return -EOPNOTSUPP;
>>
>> 	ret = gc->set(gc, offset, value);
>>-	if (ret > 0)
>>-		ret = -EBADE;
>>+	if (ret > 0) {
>>+		gpiochip_warn(gc,
>>+			"invalid return value from gc->set(): %d, consider fixing the driver\n",
>>+			ret);
>>+		ret = !!ret;
>>+	}
>>
>> 	return ret;
>> }
>
> You want to patch gpiochip_get(). It could be that set() is similarly troublesome, but the report is about get() not working.
>

Gah! I shouldn't send patches before enough coffee. I don't think gpiochip_set()
need the same patching though, it would be very weird for anyone to return
anything else than 0 or -errno.

Thanks, I'll send a v2.

Bart