[PATCH 2/2] gpiolib: propagate errors from gpiod_set_(raw_)?value
Ahmad Fatoum
a.fatoum at barebox.org
Mon Mar 23 01:58:30 PDT 2026
Now that gpio_chip::set returns an error code, make gpiod_set_value
propagate it. gpio_set_value continues to return void.
Besides aligning us with Linux and making driver porting easier,
this will also allow more robustness in future, especially for slow GPIO
devices where failure in setting a GPIO is more likely.
Signed-off-by: Ahmad Fatoum <a.fatoum at barebox.org>
---
drivers/gpio/gpiolib.c | 26 ++++++++++++++++----------
include/linux/gpio/consumer.h | 7 ++++---
2 files changed, 20 insertions(+), 13 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 37a98995f2e8..9646f5bdb3de 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -292,12 +292,14 @@ EXPORT_SYMBOL_GPL(gpiod_set_config);
* Set the raw value of the GPIO, i.e. the value of its physical line without
* regard for its ACTIVE_LOW status.
*/
-void gpiod_set_raw_value(struct gpio_desc *desc, int value)
+int gpiod_set_raw_value(struct gpio_desc *desc, int value)
{
- VALIDATE_DESC_VOID(desc);
+ VALIDATE_DESC(desc);
- if (desc->chip->ops->set)
- desc->chip->ops->set(desc->chip, gpiodesc_chip_offset(desc), value);
+ if (!desc->chip->ops->set)
+ return -ENOSYS;
+
+ return desc->chip->ops->set(desc->chip, gpiodesc_chip_offset(desc), value);
}
EXPORT_SYMBOL(gpiod_set_raw_value);
@@ -323,10 +325,10 @@ EXPORT_SYMBOL(gpio_set_value);
* Set the logical value of the GPIO, i.e. taking its ACTIVE_LOW,
* OPEN_DRAIN and OPEN_SOURCE flags into account.
*/
-void gpiod_set_value(struct gpio_desc *desc, int value)
+int gpiod_set_value(struct gpio_desc *desc, int value)
{
- VALIDATE_DESC_VOID(desc);
- gpiod_set_raw_value(desc, gpio_adjust_value(desc, value));
+ VALIDATE_DESC(desc);
+ return gpiod_set_raw_value(desc, gpio_adjust_value(desc, value));
}
EXPORT_SYMBOL_GPL(gpiod_set_value);
@@ -1191,14 +1193,18 @@ static int gpiod_set_array_value_complex(bool raw,
struct gpio_array *array_info,
unsigned long *value_bitmap)
{
+ int ret, err = 0;
int i;
BUG_ON(array_info != NULL);
- for (i = 0; i < array_size; i++)
- gpiod_set_value(desc_array[i], test_bit(i, value_bitmap));
+ for (i = 0; i < array_size; i++) {
+ ret = gpiod_set_value(desc_array[i], test_bit(i, value_bitmap));
+ if (ret)
+ err = ret;
+ }
- return 0;
+ return err;
}
/**
diff --git a/include/linux/gpio/consumer.h b/include/linux/gpio/consumer.h
index a425145351b0..0bfa5c354040 100644
--- a/include/linux/gpio/consumer.h
+++ b/include/linux/gpio/consumer.h
@@ -119,8 +119,8 @@ int gpiod_direction_input(struct gpio_desc *desc);
int gpiod_direction_output_raw(struct gpio_desc *desc, int value);
int gpiod_direction_output(struct gpio_desc *desc, int value);
-void gpiod_set_raw_value(struct gpio_desc *desc, int value);
-void gpiod_set_value(struct gpio_desc *desc, int value);
+int gpiod_set_raw_value(struct gpio_desc *desc, int value);
+int gpiod_set_value(struct gpio_desc *desc, int value);
int gpiod_get_raw_value(const struct gpio_desc *desc);
int gpiod_get_value(const struct gpio_desc *desc);
@@ -175,10 +175,11 @@ static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value)
WARN_ON(desc);
}
-static inline void gpiod_set_value(struct gpio_desc *desc, int value)
+static inline int gpiod_set_value(struct gpio_desc *desc, int value)
{
/* GPIO can never have been requested */
WARN_ON(desc);
+ return 0;
}
static inline int gpiod_get_raw_value(const struct gpio_desc *desc)
--
2.47.3
More information about the barebox
mailing list