aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio/gpiolib.c
diff options
context:
space:
mode:
authorBartosz Golaszewski <[email protected]>2025-02-26 10:12:31 +0000
committerBartosz Golaszewski <[email protected]>2025-02-27 07:57:50 +0000
commit8a5680bffb2f681688b5788751c767fc380ff9b7 (patch)
treed2e432302e63a907e3225529a7585891adca0198 /drivers/gpio/gpiolib.c
parentgpiolib: use a more explicit retval logic in gpiochip_get_direction() (diff)
downloadkernel-8a5680bffb2f681688b5788751c767fc380ff9b7.tar.gz
kernel-8a5680bffb2f681688b5788751c767fc380ff9b7.zip
gpiolib: don't double-check the gc->get callback's existence
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 <[email protected]> Closes: https://lore.kernel.org/all/[email protected]/ Reviewed-by: Andy Shevchenko <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Bartosz Golaszewski <[email protected]>
Diffstat (limited to 'drivers/gpio/gpiolib.c')
-rw-r--r--drivers/gpio/gpiolib.c6
1 files changed, 2 insertions, 4 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 49bdae208744..d0108cf2ee0b 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -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