Re: [RFC PATCH 0/2] Helper to isolate least-significant bit
From: Andrew Cooper
Date: Fri Jan 09 2026 - 14:26:23 EST
> diff --git a/arch/alpha/kernel/core_cia.c b/arch/alpha/kernel/core_cia.c
> index 6e577228e175d..b3c273c13c104 100644
> --- a/arch/alpha/kernel/core_cia.c
> +++ b/arch/alpha/kernel/core_cia.c
> @@ -1035,7 +1035,7 @@ cia_decode_ecc_error(struct el_CIA_sysdata_mcheck *cia, const char *msg)
> cia_decode_mem_error(cia, msg);
>
> syn = cia->cia_syn & 0xff;
> - if (syn == (syn & -syn)) {
> + if (syn == ffs_val(syn)) {
> fmt = KERN_CRIT " ECC syndrome %#x -- check bit %d\n";
> i = ffs(syn) - 1;
> } else {
This is a check for multiple bits set, which has a simpler expression to
calculate. (the ffs() in context shows that syn isn't expected to be 0.)
In Xen I added this helper while tiding things up, and it's applicable
to the more common pattern of checking hweight() of a bitmap against 1.
/*
* Calculate if a value has two or more bits set. Always use this in
* preference to an expression of the form 'hweight(x) > 1'.
*/
#define multiple_bits_set(x) \
({ \
typeof(x) _v = (x); \
(_v & (_v - 1)) != 0; \
})
~Andrew