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

From: Andy Shevchenko
Date: Thu Apr 17 2025 - 13:40:44 EST


On Thu, Apr 17, 2025 at 08:38:33PM +0300, Andy Shevchenko wrote:
> On Wed, Apr 16, 2025 at 04:08:16PM +0200, Thomas Richard wrote:

...

> > + 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++;

Btw, note with a mask for them you can just have a bitmap_weight() call instead of all this.

ndescs = bitmap_weight(valid_mask);

--
With Best Regards,
Andy Shevchenko