diff options
| author | Bartosz Golaszewski <[email protected]> | 2025-02-10 10:51:58 +0000 |
|---|---|---|
| committer | Bartosz Golaszewski <[email protected]> | 2025-02-24 08:58:58 +0000 |
| commit | 86ef402d805d606a10e6da8e5a64a51f6f5fb7e2 (patch) | |
| tree | a93b72be9683e9193f31f4f756996b48e926c721 /drivers/gpio/gpiolib.c | |
| parent | gpiolib: sanitize the return value of gpio_chip::set_config() (diff) | |
| download | kernel-86ef402d805d606a10e6da8e5a64a51f6f5fb7e2.tar.gz kernel-86ef402d805d606a10e6da8e5a64a51f6f5fb7e2.zip | |
gpiolib: sanitize the return value of gpio_chip::get()
As per the API contract, the get() callback is only allowed to return 0,
1 or a negative error number. Add a wrapper around the callback calls
that filters out anything else.
Reviewed-by: Linus Walleij <[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.c | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 67a735d57942..1a3f527aba0e 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -3115,9 +3115,25 @@ void gpiod_toggle_active_low(struct gpio_desc *desc) } EXPORT_SYMBOL_GPL(gpiod_toggle_active_low); +static int gpiochip_get(struct gpio_chip *gc, unsigned int offset) +{ + int ret; + + lockdep_assert_held(&gc->gpiodev->srcu); + + if (!gc->get) + return -EIO; + + ret = gc->get(gc, offset); + if (ret > 1) + ret = -EBADE; + + return ret; +} + static int gpio_chip_get_value(struct gpio_chip *gc, const struct gpio_desc *desc) { - return gc->get ? gc->get(gc, gpio_chip_hwgpio(desc)) : -EIO; + return gpiochip_get(gc, gpio_chip_hwgpio(desc)); } /* I/O calls are only valid after configuration completed; the relevant @@ -3174,7 +3190,7 @@ static int gpio_chip_get_multiple(struct gpio_chip *gc, int i, value; for_each_set_bit(i, mask, gc->ngpio) { - value = gc->get(gc, i); + value = gpiochip_get(gc, i); if (value < 0) return value; __assign_bit(i, bits, value); |
