Re: [PATCH v2 1/3] lib/find_bit: introduce FIND_FIRST_BIT() macro

From: Andy Shevchenko
Date: Wed Aug 24 2022 - 13:45:51 EST


On Wed, Aug 24, 2022 at 4:19 PM Yury Norov <yury.norov@xxxxxxxxx> wrote:
> On Wed, Aug 24, 2022 at 12:10:02PM +0300, Andy Shevchenko wrote:
> > On Wed, Aug 24, 2022 at 4:51 AM Yury Norov <yury.norov@xxxxxxxxx> wrote:

...

> > > +#define FIND_FIRST_BIT(EXPRESSION, size) \
> > > +({ \
> > > + unsigned long idx, val, sz = (size); \
> > > + \
> > > + for (idx = 0; idx * BITS_PER_LONG < sz; idx++) { \
> >
> > I think we can do slightly better:
> >
> > for (unsigned long idx = 0; idx < sz; idx += BITS_PER_LONG) {
> > unsigned long val;
>
> This will blow up the EXPRESSION. We can mitigate it on user side:

I'm not sure I understand how EXPRESSION is involved in all this. What
I proposed is to replace the for-loop one-by-one to
one-by-BITS_PER_LONG. But okay, I have re-read the above patch and now
I see what you are doing, basically you use internal variables of the
macro in the EXPRESSION. Hmm...

--
With Best Regards,
Andy Shevchenko