Skip to contentSkip to conversation

gpio: improve the API contract for setting direction

PATCH Superseded Bartosz Golaszewski 2 participants 2 messages Jan 24, 2024 GPIO

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: improve the API contract for setting direction

From: Bartosz Golaszewski <[email protected]>

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.

---
 include/linux/gpio/driver.h | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
include/linux/gpio/driver.h +6 -4
index 9a5c6c76e653..c1c516b8a880 100644
@@ -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, or returns a negative
+ *	error number. This can be omitted on input-only or output-only gpio
+ *	chips.
+ * @direction_output: configures signal "offset" as output, or returns
+ *	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
Signature · 1 line
2.40.1
#1 lore raw
Quoted 25 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

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.

---
 include/linux/gpio/driver.h | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
include/linux/gpio/driver.h +0 -3
index 9a5c6c76e653..c1c516b8a880 100644
@@ -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

include/linux/gpio/driver.h struct gpio_irq_chip { · line 346

Quoted 10 lines
include/linux/gpio/driver.h +6 -1
- *	This can be omitted on input-only or output-only gpio chips.
+ * @direction_input: configures signal "offset" as input, or returns a negative
+ *	error number. This can be omitted on input-only or output-only gpio
+ *	chips.
+ * @direction_output: configures signal "offset" as output, or returns
+ *	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

Also specify 0 on success, as per @get_multiple?

It would be good to revise the documentation for all the ops, but this is a start.

Cheers,
Kent.