]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
gpiolib: don't double-check the gc->get callback's existence
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Wed, 26 Feb 2025 10:12:31 +0000 (11:12 +0100)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Thu, 27 Feb 2025 07:57:50 +0000 (08:57 +0100)
gpiochip_get() is called only in two places: in gpio_chip_get_value()
and in gpiochip_get_multiple() where the existence of the gc->get()
callback is already checked. It makes sense to unduplicate the check by
moving it one level up the stack.

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

index 49bdae2087440d03ea1caa13989f30af709741fe..d0108cf2ee0bf7ef990515d686bef633a517e69f 100644 (file)
@@ -3195,9 +3195,7 @@ static int gpiochip_get(struct gpio_chip *gc, unsigned int offset)
 
        lockdep_assert_held(&gc->gpiodev->srcu);
 
-       if (!gc->get)
-               return -EIO;
-
+       /* Make sure this is called after checking for gc->get(). */
        ret = gc->get(gc, offset);
        if (ret > 1)
                ret = -EBADE;
@@ -3207,7 +3205,7 @@ static int gpiochip_get(struct gpio_chip *gc, unsigned int offset)
 
 static int gpio_chip_get_value(struct gpio_chip *gc, const struct gpio_desc *desc)
 {
-       return gpiochip_get(gc, gpio_chip_hwgpio(desc));
+       return gc->get ? gpiochip_get(gc, gpio_chip_hwgpio(desc)) : -EIO;
 }
 
 /* I/O calls are only valid after configuration completed; the relevant