Re: [PATCH v3] bitops: Fix shift overflow in GENMASK macros

2014-11-06 Thread Maxime Coquelin
On 11/05/2014 05:44 PM, Peter Zijlstra wrote: On Wed, Nov 05, 2014 at 04:47:14PM +0100, Maxime Coquelin wrote: On 11/05/2014 12:10 PM, Rasmus Villemoes wrote: On Tue, Nov 04 2014, Maxime COQUELIN wrote: -#define GENMASK(h, l) (((U32_C(1) << ((h) - (l) + 1)) - 1) << (l)) -#define GE

Re: [PATCH v3] bitops: Fix shift overflow in GENMASK macros

2014-11-05 Thread Peter Zijlstra
On Wed, Nov 05, 2014 at 04:47:14PM +0100, Maxime Coquelin wrote: > > On 11/05/2014 12:10 PM, Rasmus Villemoes wrote: > >On Tue, Nov 04 2014, Maxime COQUELIN wrote: > > > >>-#define GENMASK(h, l) (((U32_C(1) << ((h) - (l) + 1)) - 1) << > >>(l)) > >>-#define GENMASK_ULL(h, l) (((U64_

Re: [PATCH v3] bitops: Fix shift overflow in GENMASK macros

2014-11-05 Thread Maxime Coquelin
On 11/05/2014 12:10 PM, Rasmus Villemoes wrote: On Tue, Nov 04 2014, Maxime COQUELIN wrote: -#define GENMASK(h, l) (((U32_C(1) << ((h) - (l) + 1)) - 1) << (l)) -#define GENMASK_ULL(h, l) (((U64_C(1) << ((h) - (l) + 1)) - 1) << (l)) +#define GENMASK(h, l) \ + ((~0UL >> (BIT

Re: [PATCH v3] bitops: Fix shift overflow in GENMASK macros

2014-11-05 Thread Rasmus Villemoes
On Tue, Nov 04 2014, Maxime COQUELIN wrote: > -#define GENMASK(h, l)(((U32_C(1) << ((h) - (l) + 1)) - 1) << > (l)) > -#define GENMASK_ULL(h, l)(((U64_C(1) << ((h) - (l) + 1)) - 1) << (l)) > +#define GENMASK(h, l) \ > + ((~0UL >> (BITS_PER_LONG - ((h) - (l) + 1))) << (l))

Re: [PATCH v3] bitops: Fix shift overflow in GENMASK macros

2014-11-04 Thread Peter Zijlstra
On Tue, Nov 04, 2014 at 11:58:17AM +0100, Maxime COQUELIN wrote: > On some 32 bits architectures, including x86, GENMASK(31, 0) returns 0 > instead of the expected ~0UL. > > This is the same on some 64 bits architectures with GENMASK_ULL(63, 0). > > This is due to an overflow in the shift operand

[PATCH v3] bitops: Fix shift overflow in GENMASK macros

2014-11-04 Thread Maxime COQUELIN
On some 32 bits architectures, including x86, GENMASK(31, 0) returns 0 instead of the expected ~0UL. This is the same on some 64 bits architectures with GENMASK_ULL(63, 0). This is due to an overflow in the shift operand, 1 << 32 for GENMASK, 1 << 64 for GENMASK_ULL. Fixes: 10ef6b0dffe404bcc54e9