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

Bartosz Golaszewski
2024-10-14T07:45:31Z

On Mon, Oct 14, 2024 at 3:58 AM Kent Gibson <warthog618@gmail.com> wrote:
>
> On Thu, Oct 10, 2024 at 11:10:23AM +0200, Bartosz Golaszewski wrote:
> > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
> >
> > 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@linaro.org>
> > ---
> > 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?

Bart

>
> > if (test_bit(FLAG_IS_OUT, &dflags))
> > info->flags |= GPIO_V2_LINE_FLAG_OUTPUT;
> > @@ -2502,7 +2506,7 @@ static int lineinfo_get_v1(struct gpio_chardev_data *cdev, void __user *ip,
> > return -EBUSY;
> > }
> >