Re: [PATCH v3 04/10] gpio: aggregator: refactor the code to add GPIO desc in the forwarder

Andy Shevchenko
2025-04-17T17:16:55Z

On Wed, Apr 16, 2025 at 04:08:12PM +0200, Thomas Richard wrote:
> Create a dedicated function to add a GPIO desc in the forwarder. Instead of
> passing an array of GPIO desc, now the GPIO desc are passed on by one to
> the forwarder.

...

> +static int gpiochip_fwd_add_gpio_desc(struct gpiochip_fwd *fwd,
> + struct gpio_desc *desc,
> + unsigned int offset)
> +{
> + struct gpio_chip *parent = gpiod_to_chip(desc);
> + struct gpio_chip *chip = &fwd->chip;
> +
> + if (offset > chip->ngpio)

>= ?

> + return -EINVAL;

> + if (fwd->descs[offset])
> + return -EEXIST;

Not sure we need this. I would rather think that something inside struct
gpiochip_fwd should track this. OTOH, I understand that you want to have
sparse lists perhaps. I;m wondering why GPIO valid mask can't be used for
this purposes?

> + /*
> + * If any of the GPIO lines are sleeping, then the entire forwarder
> + * will be sleeping.
> + * If any of the chips support .set_config(), then the forwarder will
> + * support setting configs.
> + */
> + if (gpiod_cansleep(desc))
> + chip->can_sleep = true;
> +
> + if (parent && parent->set_config)
> + chip->set_config = gpio_fwd_set_config;
> +
> + fwd->descs[offset] = desc;
> +
> + dev_dbg(chip->parent, "%u => gpio %d irq %d\n", offset,
> + desc_to_gpio(desc), gpiod_to_irq(desc));
> +
> + return 0;
> +}

The bottom line is that I'm fine with this change without additional checks,
add them when function will be used not only in the original loop.

--
With Best Regards,
Andy Shevchenko