[PATCH v2] gpiolib: reset lookup flags for each hogged line

From: Jinseob Kim

Date: Wed Nov 04 2026 - 07:04:52 EST


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")
Signed-off-by: Jinseob Kim <kimjinseob88@xxxxxxxxx>
---
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/20261103224339.1180-1-kimjinseob88@xxxxxxxxx/
Review: https://lore.kernel.org/linux-gpio/qboynvhfmvltsuopwotpf3sqdwho3qobxmw5qldooedjqodfgy@x4l6hscj5unx/

drivers/gpio/gpiolib.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index fbdeda2f2..db613770d 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -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