Skip to contentSkip to conversation

gpio: amd-fch: ionly return allowed values from amd_fch_gpio_get()

PATCH Applied Dmitry Torokhov 2 participants 2 messages Feb 17 – Feb 18

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

PATCH 1/1 gpio: amd-fch: ionly return allowed values from amd_fch_gpio_get()

As of 86ef402d805d ("gpiolib: sanitize the return value of gpio_chip::get()") gpiolib requires drivers implementing GPIOs to only return 0, 1 or negative error for the get() callbacks. Ensure that amd-fch complies with this requirement.

Fixes 86ef402d805d ("gpiolib: sanitize the return value of gpio_chip::get()")
Reported-and-tested-by Tj <[email protected]>
---
 drivers/gpio/gpio-amd-fch.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/gpio/gpio-amd-fch.c +4 -3
index e6c6c3ec7656..9f329938202b 100644
@@ -8,6 +8,7 @@
  *
  */
 
+#include <linux/bitfield.h>
 #include <linux/err.h>
 #include <linux/io.h>
 #include <linux/kernel.h>
@@ -120,15 +121,15 @@ static int amd_fch_gpio_get(struct gpio_chip *gc,
 			    unsigned int offset)
 {
 	unsigned long flags;
-	int ret;
+	u32 val;
 	struct amd_fch_gpio_priv *priv = gpiochip_get_data(gc);
 	void __iomem *ptr = amd_fch_gpio_addr(priv, offset);
 
 	spin_lock_irqsave(&priv->lock, flags);
-	ret = (readl_relaxed(ptr) & AMD_FCH_GPIO_FLAG_READ);
+	val = readl_relaxed(ptr);
 	spin_unlock_irqrestore(&priv->lock, flags);
 
-	return ret;
+	return FIELD_GET(AMD_FCH_GPIO_FLAG_READ, val);
 }
 
 static int amd_fch_gpio_request(struct gpio_chip *chip,
Signature · 5 lines
2.53.0.310.g728cabbaf7-goog


-- 
Dmitry
#1 lore raw
Quoted 6 lines · Dmitry Torokhov

As of 86ef402d805d ("gpiolib: sanitize the return value of gpio_chip::get()") gpiolib requires drivers implementing GPIOs to only return 0, 1 or negative error for the get() callbacks. Ensure that amd-fch complies with this requirement.

Applied, thanks!

[1/1] gpio: amd-fch: ionly return allowed values from amd_fch_gpio_get()

      https://git.kernel.org/brgl/c/fbd03587ba732c612b8a569d1cf5bed72bd3a27c

Best regards,

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