From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Date: Tue, 4 Nov 2014 11:44:14 +0100 From: Peter Zijlstra To: Maxime COQUELIN Cc: gong.chen@linux.intel.com, Ingo Molnar , " Paul E. McKenney" , tytso@mit.edu, linux-kernel@vger.kernel.org, stable@vger.kernel.org, kernel@stlinux.com, eric.paire@st.com Subject: Re: [PATCH v2] bitops: Fix shift overflow in GENMASK macros Message-ID: <20141104104414.GL3337@twins.programming.kicks-ass.net> References: <1415095437-28723-1-git-send-email-maxime.coquelin@st.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1415095437-28723-1-git-send-email-maxime.coquelin@st.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: 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. My bad for not explicitly doing that when suggesting the alternative.