[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20141104104414.GL3337@twins.programming.kicks-ass.net>
Date: Tue, 4 Nov 2014 11:44:14 +0100
From: Peter Zijlstra <peterz@...radead.org>
To: Maxime COQUELIN <maxime.coquelin@...com>
Cc: gong.chen@...ux.intel.com, Ingo Molnar <mingo@...nel.org>,
" Paul E. McKenney" <paulmck@...ux.vnet.ibm.com>, tytso@....edu,
linux-kernel@...r.kernel.org, stable@...r.kernel.org,
kernel@...inux.com, eric.paire@...com
Subject: Re: [PATCH v2] bitops: Fix shift overflow in GENMASK macros
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.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists