Skip to contentSkip to conversation

gpiolib: normalize the return value of gc->get() on behalf of buggy drivers

PATCH Applied Bartosz Golaszewski 3 participants 4 messages Feb 19 – Feb 23

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 gpiolib: normalize the return value of gc->get() on behalf of buggy drivers

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.

Fixes 86ef402d805d ("gpiolib: sanitize the return value of gpio_chip::get()")

---
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(-)
drivers/gpio/gpiolib.c +6 -2
index c52200eaaaff82b12f22dd1ee8459bdd8ec10d81..c9cd751e7de2307fc5994eb682c53f2b3ce39233 100644
@@ -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,

Signature · 1 line
Bartosz Golaszewski <[email protected]>
Reviewed-by on v2 1/1
#1 lore raw
Quoted 29 lines · 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.

Fixes 86ef402d805d ("gpiolib: sanitize the return value of gpio_chip::get()")

---
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(-)
drivers/gpio/gpiolib.c +0 -1
index c52200eaaaff82b12f22dd1ee8459bdd8ec10d81..c9cd751e7de2307fc5994eb682c53f2b3ce39233 100644
@@ -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)

drivers/gpio/gpiolib.c static int gpiochip_get(struct gpio_chip *gc, unsigned int offset) · line 3279

Quoted 10 lines
drivers/gpio/gpiolib.c +6 -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 ;)

Signature · 1 line
Dmitry
maintainer Reviewed-by on v2 1/1
#2 lore raw
In reply to Bartosz Golaszewski
Quoted 7 lines · 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.

Quoted 5 lines
Fixes 86ef402d805d ("gpiolib: sanitize the return value of gpio_chip::get()")

Yours,
Linus Walleij

author Applied
#3 lore raw
In reply to Bartosz Golaszewski
Quoted 8 lines · 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.

[...]

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,

Signature · 1 line
Bartosz Golaszewski <[email protected]>