Skip to content

Commit d95da99

Browse files
cpackham-atlnzlinusw
authored andcommitted
gpiolib: Preserve desc->flags when setting state
desc->flags may already have values set by of_gpiochip_add() so make sure that this isn't undone when setting the initial direction. Cc: [email protected] Fixes: 3edfb7b ("gpiolib: Show correct direction from the beginning") Signed-off-by: Chris Packham <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Linus Walleij <[email protected]>
1 parent 238644c commit d95da99

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

drivers/gpio/gpiolib.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,12 +1394,17 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
13941394
for (i = 0; i < chip->ngpio; i++) {
13951395
struct gpio_desc *desc = &gdev->descs[i];
13961396

1397-
if (chip->get_direction && gpiochip_line_is_valid(chip, i))
1398-
desc->flags = !chip->get_direction(chip, i) ?
1399-
(1 << FLAG_IS_OUT) : 0;
1400-
else
1401-
desc->flags = !chip->direction_input ?
1402-
(1 << FLAG_IS_OUT) : 0;
1397+
if (chip->get_direction && gpiochip_line_is_valid(chip, i)) {
1398+
if (!chip->get_direction(chip, i))
1399+
set_bit(FLAG_IS_OUT, &desc->flags);
1400+
else
1401+
clear_bit(FLAG_IS_OUT, &desc->flags);
1402+
} else {
1403+
if (!chip->direction_input)
1404+
set_bit(FLAG_IS_OUT, &desc->flags);
1405+
else
1406+
clear_bit(FLAG_IS_OUT, &desc->flags);
1407+
}
14031408
}
14041409

14051410
acpi_gpiochip_add(chip);

0 commit comments

Comments
 (0)