Re: [RFC PATCH 2/2] treewide, bits: use ffs_val() where it is open-coded

From: Maciej W. Rozycki

Date: Sat Jan 10 2026 - 22:15:24 EST


On Sat, 10 Jan 2026, David Laight wrote:

> > > > diff --git a/arch/mips/dec/ecc-berr.c b/arch/mips/dec/ecc-berr.c
> > > > index 1eb356fdd8323..8934b8b1cf375 100644
> > > > --- a/arch/mips/dec/ecc-berr.c
> > > > +++ b/arch/mips/dec/ecc-berr.c
> > > > @@ -153,7 +153,7 @@ static int dec_ecc_be_backend(struct pt_regs *regs, int is_fixup, int invoker)
> > > > /* Ack now, now we've rewritten (or not). */
> > > > dec_ecc_be_ack();
> > > >
> > > > - if (syn && syn == (syn & -syn)) {
> > > > + if (syn && syn == ffs_val(syn)) {
> > >
> > > It opencodes is_power_of_2().
>
> Badly...

It's 4 MIPS instructions and exactly the same machine code produced as
compiler output from `is_power_of_2'. If you know of a better alternative
I'll be happy to get enlightened, however it's academic anyway, as it's
the ECC memory error handler. If you get here, then you have a bigger
issue than a couple of extra instructions executed per kernel log entry
produced. If you indeed can get rid of them in the first place, that is.

Maciej