[PATCH] gpiolib: Propagate emulated drive errors when setting arrays
From: Baek Kyu, Kim
Date: Tue Oct 20 2026 - 13:30:43 EST
gpiod_set_array_value_complex() ignores errors from the open-drain and
open-source emulation helpers. If a direction change fails,
GPIO_V2_LINE_SET_VALUES_IOCTL still reports success, including when
updating a single line.
Return the first emulation error after freeing the temporary bitmaps.
Keep updates already made to earlier lines and stop processing the
remaining lines, as for errors from gpiochip_set_multiple().
Fixes: 8ce258f62f90 ("gpiolib: make value setters have return values")
Signed-off-by: Baek Kyu, Kim <pocj8ur4in@xxxxxxxxx>
---
Tested under ARM64 QEMU through GPIO v2 ioctls and libgpiod with a test
GPIO provider. After a successful line request, an emulated direction
change failure is reported as success before the fix and as an error with
the fix. Tests cover single-line writes, both emulated drive modes,
active-low, mixed arrays, retries and partial updates. No physical GPIO
controller was tested.
drivers/gpio/gpiolib.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 1438f97d0634..9decee5a95c7 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -3945,9 +3945,13 @@ int gpiod_set_array_value_complex(bool raw, bool can_sleep,
* open drain and open source outputs are set individually
*/
if (test_bit(GPIOD_FLAG_OPEN_DRAIN, &desc->flags) && !raw) {
- gpio_set_open_drain_value_commit(desc, value);
+ ret = gpio_set_open_drain_value_commit(desc, value);
+ if (ret)
+ goto cleanup_bitmap;
} else if (test_bit(GPIOD_FLAG_OPEN_SOURCE, &desc->flags) && !raw) {
- gpio_set_open_source_value_commit(desc, value);
+ ret = gpio_set_open_source_value_commit(desc, value);
+ if (ret)
+ goto cleanup_bitmap;
} else {
__set_bit(hwgpio, mask);
__assign_bit(hwgpio, bits, value);
base-commit: a0fe269293509acdd93b9cfb3f46636f7b91b33a
--
2.55.0