mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/chenhuacai/linux-loongson
synced 2025-09-03 01:28:04 +00:00
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 <linus.walleij@linaro.org> Link: https://lore.kernel.org/r/20250210-gpio-sanitize-retvals-v1-4-12ea88506cb2@linaro.org Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
This commit is contained in:
parent
dcf8f3bffa
commit
86ef402d80
@ -3115,9 +3115,25 @@ void gpiod_toggle_active_low(struct gpio_desc *desc)
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(gpiod_toggle_active_low);
|
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)
|
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
|
/* 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;
|
int i, value;
|
||||||
|
|
||||||
for_each_set_bit(i, mask, gc->ngpio) {
|
for_each_set_bit(i, mask, gc->ngpio) {
|
||||||
value = gc->get(gc, i);
|
value = gpiochip_get(gc, i);
|
||||||
if (value < 0)
|
if (value < 0)
|
||||||
return value;
|
return value;
|
||||||
__assign_bit(i, bits, value);
|
__assign_bit(i, bits, value);
|
||||||
|
Loading…
Reference in New Issue
Block a user