* [PATCH v2] gpiolib: Preserve desc->flags when setting state
@ 2019-07-04 4:20 Chris Packham
2019-07-05 21:55 ` Linus Walleij
0 siblings, 1 reply; 2+ messages in thread
From: Chris Packham @ 2019-07-04 4:20 UTC (permalink / raw)
To: linus.walleij, bgolaszewski, ricardo.ribalda
Cc: linux-gpio, linux-kernel, Chris Packham
desc->flags may already have values set by of_gpiochip_add() so make
sure that this isn't undone when setting the initial direction.
Fixes: 3edfb7bd76bd1cba ("gpiolib: Show correct direction from the beginning")
Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
---
Notes:
Changes in v2:
- add braces to avoid ambiguious else warning
drivers/gpio/gpiolib.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index e013d417a936..5ac57264171b 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1392,12 +1392,13 @@ int gpiochip_add_data_with_key(struct gpio_chip *chip, void *data,
for (i = 0; i < chip->ngpio; i++) {
struct gpio_desc *desc = &gdev->descs[i];
- if (chip->get_direction && gpiochip_line_is_valid(chip, i))
- desc->flags = !chip->get_direction(chip, i) ?
- (1 << FLAG_IS_OUT) : 0;
- else
- desc->flags = !chip->direction_input ?
- (1 << FLAG_IS_OUT) : 0;
+ if (chip->get_direction && gpiochip_line_is_valid(chip, i)) {
+ if (!chip->get_direction(chip, i))
+ set_bit(FLAG_IS_OUT, &desc->flags);
+ } else {
+ if (!chip->direction_input)
+ set_bit(FLAG_IS_OUT, &desc->flags);
+ }
}
acpi_gpiochip_add(chip);
--
2.22.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] gpiolib: Preserve desc->flags when setting state
2019-07-04 4:20 [PATCH v2] gpiolib: Preserve desc->flags when setting state Chris Packham
@ 2019-07-05 21:55 ` Linus Walleij
0 siblings, 0 replies; 2+ messages in thread
From: Linus Walleij @ 2019-07-05 21:55 UTC (permalink / raw)
To: Chris Packham
Cc: Bartosz Golaszewski, Ricardo Ribalda Delgado,
open list:GPIO SUBSYSTEM, linux-kernel
Hi Chris,
thanks for your patch!
On Thu, Jul 4, 2019 at 6:21 AM Chris Packham
<chris.packham@alliedtelesis.co.nz> wrote:
> desc->flags may already have values set by of_gpiochip_add() so make
> sure that this isn't undone when setting the initial direction.
>
> Fixes: 3edfb7bd76bd1cba ("gpiolib: Show correct direction from the beginning")
> Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
> ---
>
> Notes:
> Changes in v2:
> - add braces to avoid ambiguious else warning
This is almost the solution!
> - if (chip->get_direction && gpiochip_line_is_valid(chip, i))
> - desc->flags = !chip->get_direction(chip, i) ?
> - (1 << FLAG_IS_OUT) : 0;
> - else
> - desc->flags = !chip->direction_input ?
> - (1 << FLAG_IS_OUT) : 0;
> + if (chip->get_direction && gpiochip_line_is_valid(chip, i)) {
> + if (!chip->get_direction(chip, i))
> + set_bit(FLAG_IS_OUT, &desc->flags);
You need to clear_bit() in the reverse case. We just learned we can't
assume anything about the flags here, like just assign them.
> + } else {
> + if (!chip->direction_input)
> + set_bit(FLAG_IS_OUT, &desc->flags);
Same here.
Yours,
Linus Walleij
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2019-07-05 21:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-04 4:20 [PATCH v2] gpiolib: Preserve desc->flags when setting state Chris Packham
2019-07-05 21:55 ` Linus Walleij
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).