Re: [PATCH v3 08/10] gpio: aggregator: handle runtime registration of gpio_desc in gpiochip_fwd

Andy Shevchenko
2025-04-17T17:38:39Z

On Wed, Apr 16, 2025 at 04:08:16PM +0200, Thomas Richard wrote:
> Add request() callback to check if the GPIO descriptor was well registered
> in the gpiochip_fwd before to use it. This is done to handle the case
> where GPIO descriptor is added at runtime in the forwarder.
>
> If at least one GPIO descriptor was not added before the forwarder
> registration, we assume the forwarder can sleep as if a GPIO is added at
> runtime it may sleep.

...

> +int gpio_fwd_request(struct gpio_chip *chip, unsigned int offset)
> +{
> + struct gpiochip_fwd *fwd = gpiochip_get_data(chip);
> +
> + return fwd->descs[offset] ? 0 : -ENODEV;

ENODEV? Hmm... Why has that error code been chosen?

> +}

...

> int gpio_fwd_register(struct gpiochip_fwd *fwd)
> {
> struct gpio_chip *chip = &fwd->chip;
> + unsigned int ndescs = 0, i;

Slightly better (from maintenance perspective) to decouple assignment as it's
not a standalone function that just counts them. So it means some code may
appear in between and in long-term someone might screw up with the initial
value for that.

> int error;

ndescs = 0;

> + for (i = 0; i < chip->ngpio; i++)
> + if (fwd->descs[i])
> + ndescs++;
> +
> + /*
> + * Some gpio_desc were not registers. They will be registered at runtime

registered

> + * but we have to suppose they can sleep.
> + */
> + if (ndescs != chip->ngpio)
> + chip->can_sleep = true;

--
With Best Regards,
Andy Shevchenko