Re: [PATCH v6 3/9] gpio: aggregator: add aggr_alloc()/aggr_free()

From: Bartosz Golaszewski
Date: Thu Mar 20 2025 - 11:51:50 EST


On Sat, Mar 15, 2025 at 5:41 PM Koichiro Den <koichiro.den@xxxxxxxxxxxxx> wrote:
>
> Prepare for the upcoming configfs interface. These functions will be
> used by both the existing sysfs interface and the new configfs
> interface, reducing code duplication.
>
> No functional change.
>
> Signed-off-by: Koichiro Den <koichiro.den@xxxxxxxxxxxxx>
> ---
> drivers/gpio/gpio-aggregator.c | 58 +++++++++++++++++++++-------------
> 1 file changed, 36 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c
> index e026deb4ac64..2692a31e01ac 100644
> --- a/drivers/gpio/gpio-aggregator.c
> +++ b/drivers/gpio/gpio-aggregator.c
> @@ -36,12 +36,41 @@
> struct gpio_aggregator {
> struct gpiod_lookup_table *lookups;
> struct platform_device *pdev;
> + int id;
> char args[];
> };
>
> static DEFINE_MUTEX(gpio_aggregator_lock); /* protects idr */
> static DEFINE_IDR(gpio_aggregator_idr);
>
> +static int aggr_alloc(struct gpio_aggregator **aggr, size_t arg_size)
> +{
> + struct gpio_aggregator *new __free(kfree) = NULL;
> + int ret;
> +
> + new = kzalloc(sizeof(*new) + arg_size, GFP_KERNEL);

Please prefer declaring the auto variable and initializing it at the
same time. Should be:

struct gpio_aggregator *new __free(kfree) = kzalloc(...);

> + if (!new)
> + return -ENOMEM;
> +
> + mutex_lock(&gpio_aggregator_lock);

If adding new code, please use lock guards.

Bart