From: Ahmad Fatoum <a.fatoum@barebox.org>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 2/2] gpiolib: propagate errors from gpiod_set_(raw_)?value
Date: Mon, 23 Mar 2026 09:58:30 +0100 [thread overview]
Message-ID: <20260323085833.4073078-2-a.fatoum@barebox.org> (raw)
In-Reply-To: <20260323085833.4073078-1-a.fatoum@barebox.org>
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@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
prev parent reply other threads:[~2026-03-23 8:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-23 8:58 [PATCH 1/2] gpio: have gpio_chip::set return an error code Ahmad Fatoum
2026-03-23 8:58 ` Ahmad Fatoum [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260323085833.4073078-2-a.fatoum@barebox.org \
--to=a.fatoum@barebox.org \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox