Commit 69920338 authored by Bartosz Golaszewski's avatar Bartosz Golaszewski
Browse files

gpiolib: sanitize the return value of gpio_chip::request()



The return value of the request() 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: default avatarLinus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20250210-gpio-sanitize-retvals-v1-2-12ea88506cb2@linaro.org


Signed-off-by: default avatarBartosz Golaszewski <bartosz.golaszewski@linaro.org>
parent 2d13f801
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -2349,6 +2349,8 @@ static int gpiod_request_commit(struct gpio_desc *desc, const char *label)
			ret = guard.gc->request(guard.gc, offset);
		else
			ret = -EINVAL;
		if (ret > 0)
			ret = -EBADE;
		if (ret)
			goto out_clear_bit;
	}
+2 −1
Original line number Diff line number Diff line
@@ -329,7 +329,8 @@ struct gpio_irq_chip {
 * @fwnode: optional fwnode providing this controller's properties
 * @owner: helps prevent removal of modules exporting active GPIOs
 * @request: optional hook for chip-specific activation, such as
 *	enabling module power and clock; may sleep
 *	enabling module power and clock; may sleep; must return 0 on success
 *	or negative error number on failure
 * @free: optional hook for chip-specific deactivation, such as
 *	disabling module power and clock; may sleep
 * @get_direction: returns direction for signal "offset", 0=out, 1=in,