Skip to contentSkip to conversation

gpio: bd9571mwv: normalize return value of gpio_get

PATCH Applied Dmitry Torokhov 3 participants 11 messages Feb 18 – Feb 23

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

PATCH 1/7 gpio: bd9571mwv: normalize return value of gpio_get

The GPIO get callback is expected to return 0 or 1 (or a negative error code). Ensure that the value returned by bd9571mwv_gpio_get() is normalized to the [0, 1] range.

---
 drivers/gpio/gpio-bd9571mwv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-bd9571mwv.c +1 -1
index 7c95bb36511e..cc5b1746f2fe 100644
@@ -69,7 +69,7 @@ static int bd9571mwv_gpio_get(struct gpio_chip *chip, unsigned int offset)
 	if (ret < 0)
 		return ret;
 
-	return val & BIT(offset);
+	return !!(val & BIT(offset));
 }
 
 static int bd9571mwv_gpio_set(struct gpio_chip *chip, unsigned int offset,
Signature · 1 line
2.53.0.335.g19a08e0c02-goog
#1 lore raw

PATCH 2/7 gpio: cgbc: normalize return value of gpio_get

The GPIO get callback is expected to return 0 or 1 (or a negative error code). Ensure that the value returned by cgbc_gpio_get() is normalized to the [0, 1] range.

---
 drivers/gpio/gpio-cgbc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpio/gpio-cgbc.c +2 -2
index 0efa1b61001a..84b5ed3c6e22 100644
@@ -47,8 +47,8 @@ static int cgbc_gpio_get(struct gpio_chip *chip, unsigned int offset)
 
 	if (ret)
 		return ret;
-	else
-		return (int)(val & (u8)BIT(offset));
+
+	return !!(val & BIT(offset));
 }
 
 static int __cgbc_gpio_set(struct gpio_chip *chip, unsigned int offset,
Signature · 1 line
2.53.0.335.g19a08e0c02-goog
#2 lore raw

PATCH 3/7 gpio: da9055: normalize return value of gpio_get

In reply to Dmitry Torokhov

The GPIO get callback is expected to return 0 or 1 (or a negative error code). Ensure that the value returned by da9055_gpio_get() is normalized to the [0, 1] range.

---
 drivers/gpio/gpio-da9055.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-da9055.c +1 -1
index a09bd6eb93cf..1949a6ea8ec6 100644
@@ -55,7 +55,7 @@ static int da9055_gpio_get(struct gpio_chip *gc, unsigned offset)
 			return ret;
 	}
 
-	return ret & (1 << offset);
+	return !!(ret & (1 << offset));
 
 }
 
Signature · 1 line
2.53.0.335.g19a08e0c02-goog
#3 lore raw

PATCH 4/7 gpio: lp873x: normalize return value of gpio_get

In reply to Dmitry Torokhov

The GPIO get callback is expected to return 0 or 1 (or a negative error code). Ensure that the value returned by lp873x_gpio_get() is normalized to the [0, 1] range.

---
 drivers/gpio/gpio-lp873x.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-lp873x.c +1 -1
index 5376708a81bf..f4413fa5a811 100644
@@ -55,7 +55,7 @@ static int lp873x_gpio_get(struct gpio_chip *chip, unsigned int offset)
 	if (ret < 0)
 		return ret;
 
-	return val & BIT(offset * BITS_PER_GPO);
+	return !!(val & BIT(offset * BITS_PER_GPO));
 }
 
 static int lp873x_gpio_set(struct gpio_chip *chip, unsigned int offset,
Signature · 1 line
2.53.0.335.g19a08e0c02-goog
#4 lore raw

PATCH 5/7 gpio: stp-xway: normalize return value of gpio_get

In reply to Dmitry Torokhov

The GPIO get callback is expected to return 0 or 1 (or a negative error code). Ensure that the value returned by xway_stp_get() is normalized to the [0, 1] range.

---
 drivers/gpio/gpio-stp-xway.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-stp-xway.c +1 -1
index 493c027afdd6..78d6c78d4aab 100644
@@ -102,7 +102,7 @@ static int xway_stp_get(struct gpio_chip *gc, unsigned int gpio)
 {
 	struct xway_stp *chip = gpiochip_get_data(gc);
 
-	return (xway_stp_r32(chip->virt, XWAY_STP_CPU0) & BIT(gpio));
+	return !!(xway_stp_r32(chip->virt, XWAY_STP_CPU0) & BIT(gpio));
 }
 
 /**
Signature · 1 line
2.53.0.335.g19a08e0c02-goog
#5 lore raw

PATCH 6/7 gpio: tps65086: normalize return value of gpio_get

In reply to Dmitry Torokhov

The GPIO get callback is expected to return 0 or 1 (or a negative error code). Ensure that the value returned by tps65086_gpio_get() is normalized to the [0, 1] range.

---
 drivers/gpio/gpio-tps65086.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-tps65086.c +1 -1
index 84b17b83476f..df770ecf28bc 100644
@@ -50,7 +50,7 @@ static int tps65086_gpio_get(struct gpio_chip *chip, unsigned offset)
 	if (ret < 0)
 		return ret;
 
-	return val & BIT(4 + offset);
+	return !!(val & BIT(4 + offset));
 }
 
 static int tps65086_gpio_set(struct gpio_chip *chip, unsigned int offset,
Signature · 1 line
2.53.0.335.g19a08e0c02-goog
#6 lore raw

PATCH 7/7 gpio: viperboard: normalize return value of gpio_get

In reply to Dmitry Torokhov

The GPIO get callback is expected to return 0 or 1 (or a negative error code). Ensure that the value returned by vprbrd_gpiob_get() in the output case is normalized to the [0, 1] range.

---
 drivers/gpio/gpio-viperboard.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-viperboard.c +1 -1
index 15e495c109d2..89087fd48a81 100644
@@ -288,7 +288,7 @@ static int vprbrd_gpiob_get(struct gpio_chip *chip,
 
 	/* if io is set to output, just return the saved value */
 	if (gpio->gpiob_out & (1 << offset))
-		return gpio->gpiob_val & (1 << offset);
+		return !!(gpio->gpiob_val & (1 << offset));
 
 	mutex_lock(&vb->lock);
 
Signature · 1 line
2.53.0.335.g19a08e0c02-goog
#7 lore raw
In reply to Dmitry Torokhov
Quoted 24 lines · Dmitry Torokhov

The GPIO get callback is expected to return 0 or 1 (or a negative error code). Ensure that the value returned by bd9571mwv_gpio_get() is normalized to the [0, 1] range.

---
 drivers/gpio/gpio-bd9571mwv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-bd9571mwv.c +1 -2
index 7c95bb36511e..cc5b1746f2fe 100644
@@ -69,7 +69,7 @@ static int bd9571mwv_gpio_get(struct gpio_chip *chip, unsigned int offset)
        if (ret < 0)
                return ret;
 
-       return val & BIT(offset);
+       return !!(val & BIT(offset));
 }
 
 static int bd9571mwv_gpio_set(struct gpio_chip *chip, unsigned int offset,
--
Quoted 2 lines

2.53.0.335.g19a08e0c02-goog

Thanks for doing this. I think it would make sense to backport them all the way to commit 86ef402d805d ("gpiolib: sanitize the return value of gpio_chip::get()")?

Bartosz

#8 lore raw
Quoted 24 lines · Bartosz Golaszewski
Quoted 22 lines · Dmitry Torokhov

The GPIO get callback is expected to return 0 or 1 (or a negative error code). Ensure that the value returned by bd9571mwv_gpio_get() is normalized to the [0, 1] range.

---
 drivers/gpio/gpio-bd9571mwv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-bd9571mwv.c +1 -1
index 7c95bb36511e..cc5b1746f2fe 100644
@@ -69,7 +69,7 @@ static int bd9571mwv_gpio_get(struct gpio_chip *chip, unsigned int offset)
        if (ret < 0)
                return ret;
 
-       return val & BIT(offset);
+       return !!(val & BIT(offset));
 }
 
Quoted 8 lines
Quoted 4 lines
drivers/gpio/gpio-bd9571mwv.c +0 -1
 static int bd9571mwv_gpio_set(struct gpio_chip *chip, unsigned int offset,
--

2.53.0.335.g19a08e0c02-goog

Thanks for doing this. I think it would make sense to backport them all the way to commit 86ef402d805d ("gpiolib: sanitize the return value of gpio_chip::get()")?

I do not think this is workable since the breakages are not limited to dtivers/gpio/.

I would recommend reverting the patch for stable, but keeping it for 7.0 and working with maintainers outside of drivers/gpio to make sure the fixes land in this release cycle.

This way you will ensure that new drivers are not adding tech debt while not punishing existing users who might not be running latest and greatest kernel.

Thanks.

Signature · 1 line
Dmitry
#9 lore raw
Quoted 38 lines · Dmitry Torokhov
Quoted 24 lines · Bartosz Golaszewski
Quoted 22 lines · Dmitry Torokhov

The GPIO get callback is expected to return 0 or 1 (or a negative error code). Ensure that the value returned by bd9571mwv_gpio_get() is normalized to the [0, 1] range.

---
 drivers/gpio/gpio-bd9571mwv.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpio/gpio-bd9571mwv.c +1 -1
index 7c95bb36511e..cc5b1746f2fe 100644
@@ -69,7 +69,7 @@ static int bd9571mwv_gpio_get(struct gpio_chip *chip, unsigned int offset)
        if (ret < 0)
                return ret;
 
-       return val & BIT(offset);
+       return !!(val & BIT(offset));
 }
 
Quoted 8 lines
Quoted 4 lines
drivers/gpio/gpio-bd9571mwv.c +0 -1
 static int bd9571mwv_gpio_set(struct gpio_chip *chip, unsigned int offset,
--

2.53.0.335.g19a08e0c02-goog

Thanks for doing this. I think it would make sense to backport them all the way to commit 86ef402d805d ("gpiolib: sanitize the return value of gpio_chip::get()")?

I do not think this is workable since the breakages are not limited to dtivers/gpio/.

Quoted 8 lines

I would recommend reverting the patch for stable, but keeping it for 7.0 and working with maintainers outside of drivers/gpio to make sure the fixes land in this release cycle.

This way you will ensure that new drivers are not adding tech debt while not punishing existing users who might not be running latest and greatest kernel.

Sigh... I sent a patch[1]. Let's get it upstream and not diverge between mainline and stable.

Thanks for the slew of fixes.

Bartosz

[1] https://lore.kernel.org/all/20260219-gpiolib-set-normalize-v1-1-f0d53a009db4@oss.qualcomm.com/

#10 lore raw
In reply to Dmitry Torokhov
Quoted 5 lines · Dmitry Torokhov

The GPIO get callback is expected to return 0 or 1 (or a negative error code). Ensure that the value returned by bd9571mwv_gpio_get() is normalized to the [0, 1] range.

Applied, thanks!

[1/7] gpio: bd9571mwv: normalize return value of gpio_get

      https://git.kernel.org/brgl/c/c43778680546dd379b3d8219c177b1a34ba87002
[2/7] gpio: cgbc: normalize return value of gpio_get
      https://git.kernel.org/brgl/c/49621f1c97788216f2f10f1a9e903f216e289f5d
[3/7] gpio: da9055: normalize return value of gpio_get
      https://git.kernel.org/brgl/c/4d720b0d68e9a251d60804eace42aac800d7a79f
[4/7] gpio: lp873x: normalize return value of gpio_get
      https://git.kernel.org/brgl/c/5a32ebabb6819fafce99e7bc6575ca568af6d22a
[5/7] gpio: stp-xway: normalize return value of gpio_get
      https://git.kernel.org/brgl/c/e62b94a690c8cd7050c3d308e01ee1b24ee9bb0b
[6/7] gpio: tps65086: normalize return value of gpio_get
      https://git.kernel.org/brgl/c/9eb7ecfd20f868421e44701274896ba9e136daae
[7/7] gpio: viperboard: normalize return value of gpio_get
      https://git.kernel.org/brgl/c/c08381ad56a9cc111f893b2b21400ceb468cc698

Best regards,

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