Re: [PATCH] word-at-a-time: avoid undefined behaviour in zero_bytemask macro

From: Will Deacon
Date: Thu May 01 2014 - 05:04:53 EST


Hi Peter,

On Wed, Apr 30, 2014 at 10:22:19PM +0100, H. Peter Anvin wrote:
> On 04/23/2014 09:52 AM, Will Deacon wrote:
> > diff --git a/include/asm-generic/word-at-a-time.h b/include/asm-generic/word-at-a-time.h
> > index d3909effd725..d96deb443f18 100644
> > --- a/include/asm-generic/word-at-a-time.h
> > +++ b/include/asm-generic/word-at-a-time.h
> > @@ -50,11 +50,7 @@ static inline bool has_zero(unsigned long val, unsigned long *data, const struct
> > }
> >
> > #ifndef zero_bytemask
> > -#ifdef CONFIG_64BIT
> > -#define zero_bytemask(mask) (~0ul << fls64(mask))
> > -#else
> > -#define zero_bytemask(mask) (~0ul << fls(mask))
> > -#endif /* CONFIG_64BIT */
> > -#endif /* zero_bytemask */
> > +#define zero_bytemask(mask) (~0ul << __fls(mask) << 1)
> > +#endif
> >
> > #endif /* _ASM_WORD_AT_A_TIME_H */
> >
>
> Why not:
>
> #define zero_bytemask(mask) (~1ul << __fls(mask))

Yup, that'll work too -- it produces an identical disassembly for arm64.

Will
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/