]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
gpiolib: use a more explicit retval logic in gpiochip_get_direction()
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Wed, 26 Feb 2025 10:12:30 +0000 (11:12 +0100)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Thu, 27 Feb 2025 07:57:50 +0000 (08:57 +0100)
We have existing macros for direction settings so we don't need to rely
on the magic value of 1 in the retval check. Use readable logic that
explicitly says we expect INPUT, OUTPUT or a negative errno and nothing
else in gpiochip_get_direction().

Fixes: e623c4303ed1 ("gpiolib: sanitize the return value of gpio_chip::get_direction()")
Suggested-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Closes: https://lore.kernel.org/all/Z7yfTggRrk3K6srs@black.fi.intel.com/
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20250226-retval-fixes-v2-2-c8dc57182441@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
drivers/gpio/gpiolib.c

index 9de28bc20b20a93a95e5a44ff544c1f5cc3c7615..49bdae2087440d03ea1caa13989f30af709741fe 100644 (file)
@@ -352,7 +352,10 @@ static int gpiochip_get_direction(struct gpio_chip *gc, unsigned int offset)
                return -EOPNOTSUPP;
 
        ret = gc->get_direction(gc, offset);
-       if (ret > 1)
+       if (ret < 0)
+               return ret;
+
+       if (ret != GPIO_LINE_DIRECTION_OUT && ret != GPIO_LINE_DIRECTION_IN)
                ret = -EBADE;
 
        return ret;