Skip to contentSkip to conversation

gpiolib: reset lookup flags for each hogged line

PATCH Applied Jinseob Kim 2 participants 2 messages Nov 4 – Nov 5 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 gpiolib: reset lookup flags for each hogged line

gpiochip_add_hog() initializes lflags once before iterating over the GPIO specifiers. In the non-OF path, an active-low line sets GPIO_ACTIVE_LOW, but a later active-high line does not clear it. A single firmware hog with mixed polarities therefore configures later active-high lines as active-low, including inverting their initial output value.

Initialize the lookup flags for each line before translating its flags. The OF helper already overwrites the flags for each specifier; the non-OF path must also start with a fresh value.

Codex assisted with identifying the issue and developing the fix.

Fixes 802c51a83e9a ("gpiolib: fix hogs with multiple lines")

---
Changes in v2:
- Split the functional fix from its KUnit regression test as requested.
- Keep only the lookup-flag reset in gpiolib.c for gpio/for-current.
- Move build/runtime details out of the permanent commit message.

Target: brgl/linux gpio/for-current at c2d0710318b8cd57d0ef6088d0ee4bbc1e827fd3. The KUnit test is sent separately for the v7.5 development cycle.

Testing on this target: actual UML/KUnit, before 8 pass / 1 fail; after 9 pass / 0 fail, with the same config and test source. GCC W=1 and Clang W=1/private Sparse C=2 builds completed. No physical GPIO or runtime OF hardware validation was performed.

Previous version: https://lore.kernel.org/linux-gpio/[email protected]/
Review: https://lore.kernel.org/linux-gpio/qboynvhfmvltsuopwotpf3sqdwho3qobxmw5qldooedjqodfgy@x4l6hscj5unx/

 drivers/gpio/gpiolib.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpio/gpiolib.c +2 -1
index fbdeda2f2..db613770d 100644
@@ -975,7 +975,6 @@ int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)
 	 */
 	u32 cells = 2;
 
-	lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
 	dflags = GPIOD_ASIS;
 	name = NULL;
 
@@ -1014,6 +1013,8 @@ int gpiochip_add_hog(struct gpio_chip *gc, struct fwnode_handle *fwnode)
 	fwnode_property_read_string(fwnode, "line-name", &name);
 
 	for (unsigned int i = 0; i < num_hogs; i++) {
+		lflags = GPIO_LOOKUP_FLAGS_DEFAULT;
+
 		if (is_of_node(fwnode)) {
 			/*
 			 * OF-nodes need some additional special handling for

base-commit: c2d0710318b8cd57d0ef6088d0ee4bbc1e827fd3

#1 lore raw
Quoted 11 lines · Jinseob Kim

gpiochip_add_hog() initializes lflags once before iterating over the GPIO specifiers. In the non-OF path, an active-low line sets GPIO_ACTIVE_LOW, but a later active-high line does not clear it. A single firmware hog with mixed polarities therefore configures later active-high lines as active-low, including inverting their initial output value.

Initialize the lookup flags for each line before translating its flags. The OF helper already overwrites the flags for each specifier; the non-OF path must also start with a fresh value.

[...]

Applied, thanks!

[1/1] gpiolib: reset lookup flags for each hogged line

      https://git.kernel.org/brgl/c/c20464a78162cf8b3a1c9dc7e0d764e535bfe582

Best regards,

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