[PATCH] lib: count_zeros: fix 32/64-bit inconsistency in count_trailing_zeros()
Jason Gunthorpe
jgg at nvidia.com
Fri Mar 13 10:18:55 PDT 2026
On Thu, Mar 12, 2026 at 07:08:16PM -0400, Yury Norov wrote:
> Based on 'sizeof(x) == 4' condition, in 32-bit case the function is wired
> to ffs(), while in 64-bit case to __ffs(). The difference is substantial:
> ffs(x) == __ffs(x) + 1. Also, ffs(0) == 0, while __ffs(0) is undefined.
>
> The 32-bit behaviour is inconsistent with the function description, so it
> needs to get fixed.
>
> There are 9 individual users for the function in 6 different subsystems.
> Some arches and drivers are 64-bit only:
> - arch/loongarch/kvm/intc/eiointc.c;
> - drivers/hv/mshv_vtl_main.c;
> - kernel/liveupdate/kexec_handover.c;
>
> The others are:
> - ib_umem_find_best_pgsz(): as per comment, __ffs() should be correct;
So long as 32 bit works the same as 64 bit it is correct for ib
Jason
More information about the kexec
mailing list