From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Message-ID: <5458AEC5.5020606@st.com> Date: Tue, 4 Nov 2014 11:47:33 +0100 From: Maxime Coquelin MIME-Version: 1.0 To: Peter Zijlstra Cc: , Ingo Molnar , "Paul E. McKenney" , , , , , Subject: Re: [PATCH v2] bitops: Fix shift overflow in GENMASK macros References: <1415095437-28723-1-git-send-email-maxime.coquelin@st.com> <20141104104414.GL3337@twins.programming.kicks-ass.net> In-Reply-To: <20141104104414.GL3337@twins.programming.kicks-ass.net> Content-Type: text/plain; charset="windows-1252"; format=flowed Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: On 11/04/2014 11:44 AM, Peter Zijlstra wrote: > On Tue, Nov 04, 2014 at 11:03:57AM +0100, 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) >> +#define GENMASK_ULL(h, l) ((~0ULL >> (BITS_PER_LONG_LONG - (h - l + 1))) << l) > OK, so you need to keep the (h) and (l) bits, macro arguments should be > wrapped in seemingly superfluous braces in order to preserve precedence > on expansion. You're right, I should have seen this.. > > My bad for not explicitly doing that when suggesting the alternative. Not a problem, v3 is coming. Maxime