Skip to contentSkip to conversation

gpiolib: Propagate emulated drive errors when setting arrays

PATCH Applied Baek Kyu, Kim 2 participants 2 messages Oct 20 – Oct 22 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpiolib: Propagate emulated drive errors when setting arrays

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")

---
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(-)
drivers/gpio/gpiolib.c +6 -2
index 1438f97d0634..9decee5a95c7 100644
@@ -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

Signature · 1 line
2.55.0
#1 lore raw
Quoted 10 lines · Kim

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().

[...]

Applied, thanks!

[1/1] gpiolib: Propagate emulated drive errors when setting arrays

      https://git.kernel.org/brgl/c/15665047024e30f9c2227563d03034061c99ac2c

Best regards,

Signature · 1 line
Bartosz Golaszewski <[email protected]>