Re: [PATCH] gpio: aggregator: Fix calling into sleeping GPIO controllers

From: Geert Uytterhoeven
Date: Tue Feb 01 2022 - 15:54:25 EST


Hi Andy,

On Tue, Feb 1, 2022 at 9:35 PM Andy Shevchenko
<andy.shevchenko@xxxxxxxxx> wrote:
> On Tue, Feb 1, 2022 at 10:09 PM Geert Uytterhoeven
> <geert+renesas@xxxxxxxxx> wrote:
> > If the parent GPIO controller is a sleeping controller (e.g. a GPIO
> > controller connected to I2C), getting or setting a GPIO triggers a
> > might_sleep() warning. This happens because the GPIO Aggregator takes
> > the can_sleep flag into account only for its internal locking, not for
> > calling into the parent GPIO controller.
> >
> > Fix this by using the gpiod_[gs]et*_cansleep() APIs when calling into a
> > sleeping GPIO controller.
>
> Reviewed-by: Andy Shevchenko <andy.shevchenko@xxxxxxxxx>

Thanks!

> > +++ b/drivers/gpio/gpio-aggregator.c
> > @@ -278,7 +278,8 @@ static int gpio_fwd_get(struct gpio_chip *chip, unsigned int offset)
> > {
> > struct gpiochip_fwd *fwd = gpiochip_get_data(chip);
> >
> > - return gpiod_get_value(fwd->descs[offset]);
>
> > + return chip->can_sleep ? gpiod_get_value_cansleep(fwd->descs[offset])
> > + : gpiod_get_value(fwd->descs[offset]);
>
> This indentation kills the perfectionist in me :-)

Why? The above is aligned perfectly ("?" just above ":")?

> What about:
>
> return chip->can_sleep ?
> gpiod_get_value_cansleep(fwd->descs[offset]) :
> gpiod_get_value(fwd->descs[offset]);
>
> ?
>
> Or as variant
>
> struct gpio_desc *desc = fwd->descs[offset];
>
> return chip->can_sleep ? gpiod_get_value_cansleep(desc) :
> gpiod_get_value(desc);
>
> ?

IMHO, those are ugly as hell ;-)

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds