]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
gpiolib: sanitize the return value of gpio_chip::set_config()
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Mon, 10 Feb 2025 10:51:57 +0000 (11:51 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 29 May 2025 09:13:09 +0000 (11:13 +0200)
[ Upstream commit dcf8f3bffa2de2c7f3b5771b63605194ccd2286f ]

The return value of the set_config() callback may be propagated to
user-space. If a bad driver returns a positive number, it may confuse
user programs. Tighten the API contract and check for positive numbers
returned by GPIO controllers.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20250210-gpio-sanitize-retvals-v1-3-12ea88506cb2@linaro.org
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpio/gpiolib.c
include/linux/gpio/driver.h

index 0c00ed2ab4315030f7e0bfb127c74a0e976cd17a..960ca0ad45fc872b2fd135db10e91d85e2b17b5a 100644 (file)
@@ -2577,6 +2577,9 @@ int gpio_do_set_config(struct gpio_desc *desc, unsigned long config)
                return -ENOTSUPP;
 
        ret = guard.gc->set_config(guard.gc, gpio_chip_hwgpio(desc), config);
+       if (ret > 0)
+               ret = -EBADE;
+
 #ifdef CONFIG_GPIO_CDEV
        /*
         * Special case - if we're setting debounce period, we need to store
index 2dd7cb9cc270a68ddedbcdd5d44e0d0f88dfa785..5ce6b2167f808b51b0e9e8fd810101fa5516c7c2 100644 (file)
@@ -347,7 +347,8 @@ struct gpio_irq_chip {
  * @set: assigns output value for signal "offset"
  * @set_multiple: assigns output values for multiple signals defined by "mask"
  * @set_config: optional hook for all kinds of settings. Uses the same
- *     packed config format as generic pinconf.
+ *     packed config format as generic pinconf. Must return 0 on success and
+ *     a negative error number on failure.
  * @to_irq: optional hook supporting non-static gpiod_to_irq() mappings;
  *     implementation may not sleep
  * @dbg_show: optional routine to show contents in debugfs; default code