Re: [PATCH v2 2/6] gpio: cdev: prepare gpio_desc_to_lineinfo() for being called from atomic

From: Kent Gibson
Date: Mon Oct 14 2024 - 04:34:52 EST


On Mon, Oct 14, 2024 at 09:45:19AM +0200, Bartosz Golaszewski wrote:
> On Mon, Oct 14, 2024 at 3:58 AM Kent Gibson <warthog618@xxxxxxxxx> wrote:
> >
> > On Thu, Oct 10, 2024 at 11:10:23AM +0200, Bartosz Golaszewski wrote:
> > > From: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx>
> > >
> > > In order to prepare gpio_desc_to_lineinfo() to being called from atomic
> > > context, add a new argument - bool atomic - which, if set, indicates
> > > that no sleeping functions must be called (currently: only
> > > pinctrl_gpio_can_use_line()).
> > >
> > > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@xxxxxxxxxx>
> > > ---
> > > unsigned long dflags;
> > > const char *label;
> > > @@ -2402,9 +2402,13 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *desc,
> > > test_bit(FLAG_USED_AS_IRQ, &dflags) ||
> > > test_bit(FLAG_EXPORT, &dflags) ||
> > > test_bit(FLAG_SYSFS, &dflags) ||
> > > - !gpiochip_line_is_valid(guard.gc, info->offset) ||
> > > - !pinctrl_gpio_can_use_line(guard.gc, info->offset))
> > > + !gpiochip_line_is_valid(guard.gc, info->offset))
> > > info->flags |= GPIO_V2_LINE_FLAG_USED;
> > > +
> > > + if (!atomic) {
> > > + if (!pinctrl_gpio_can_use_line(guard.gc, info->offset))
> > > + info->flags |= GPIO_V2_LINE_FLAG_USED;
> > > + }
> > >
> >
> > Should be else if.
> >
>
> If we're not atomic, let's call pinctrl_gpio_can_use_line() and update
> the flag accordingly. If we're in atomic, just don't do it. In any
> case do the rest. Looks good to me, am I missing something?
>

Previously the preceding if short circuits and doesn't perform the
pinctl check if ANY of the preceding checks are true.
The pinctrl check should be in an else-if to get the same behaviour.

I am refering to the if (!atomic), btw, not the if in its body.
(that is why my comment is placed after the closing bracket)

Cheers,
Kent.