gpio: improve the API contract for setting direction
authorBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Thu, 25 Jan 2024 08:35:07 +0000 (09:35 +0100)
committerBartosz Golaszewski <bartosz.golaszewski@linaro.org>
Mon, 29 Jan 2024 10:45:49 +0000 (11:45 +0100)
If a GPIO driver returns a positive integer from one of the direction
setter callbacks, we'll end up propagating it to user-space. Whether we
should sanitize the values returned by callbacks is a different question
but let's first improve the documentation and fortify the contract with
GPIO providers.

Reported-by: José Guilherme de Castro Rodrigues <joseguilhermebh@hotmail.com>
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
Reviewed-by: Kent Gibson <warthog618@gmail.com>
include/linux/gpio/driver.h

index 363d06c7b637c926e89d1fbe302518070ed3820d..3a37d058cfcfef67be44311d5538dd403c06064c 100644 (file)
@@ -335,10 +335,12 @@ struct gpio_irq_chip {
  *     (same as GPIO_LINE_DIRECTION_OUT / GPIO_LINE_DIRECTION_IN),
  *     or negative error. It is recommended to always implement this
  *     function, even on input-only or output-only gpio chips.
- * @direction_input: configures signal "offset" as input, or returns error
- *     This can be omitted on input-only or output-only gpio chips.
- * @direction_output: configures signal "offset" as output, or returns error
- *     This can be omitted on input-only or output-only gpio chips.
+ * @direction_input: configures signal "offset" as input, returns 0 on success
+ *     or a negative error number. This can be omitted on input-only or
+ *     output-only gpio chips.
+ * @direction_output: configures signal "offset" as output, returns 0 on
+ *     success or a negative error number. This can be omitted on input-only
+ *     or output-only gpio chips.
  * @get: returns value for signal "offset", 0=low, 1=high, or negative error
  * @get_multiple: reads values for multiple signals defined by "mask" and
  *     stores them in "bits", returns 0 on success or negative error