On Tue, Jan 12, 2021 at 03:06:34PM -0700, Nathan Chancellor wrote: > On Tue, Jan 12, 2021 at 01:53:30PM -0800, Nick Desaulniers wrote: > > On Tue, Jan 12, 2021 at 1:37 PM Nathan Chancellor > > <natechancel...@gmail.com> wrote: > > > > > > > if real_ptr is an unsigned long, do we want to use `__ffs(real_ptr) + > > > > 1` here rather than ffs which takes an int? It seems the kernel is > > > > missing a definition of ffsl. :( > > > > > > Why the + 1? I think if we use __ffs (which it seems like we should), I > > > think that needs to become > > > > This came up recently in an internal code review; ffs and __ffs differ > > in output by one. See also the definition of ffs for alpha in > > arch/alpha/include/asm/bitops.h. > > Interesting, thanks for bringing it up! Looks like ffs returns 1-32 and > __ffs returns 0-31. I think that we want __ffs here because we are > shifting (1UL << 32 overflows on 32-bit architectures) and the code in > LLVM appears to agree. LeastSignificantSetBitIndex evaluates to > __builtin_ctzl, which is the asm-generic implementation of __ffs.
Sounds good. With __ffs, consider your v2: Acked-by: Kees Cook <keesc...@chromium.org> -- Kees Cook