Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751910AbdHBWwh (ORCPT ); Wed, 2 Aug 2017 18:52:37 -0400 Received: from mail-pg0-f41.google.com ([74.125.83.41]:36620 "EHLO mail-pg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751748AbdHBWwe (ORCPT ); Wed, 2 Aug 2017 18:52:34 -0400 From: Matthias Kaehlcke To: zijun_hu , Andrew Morton , Catalin Marinas , Will Deacon , Mark Rutland , Laura Abbott Cc: linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Doug Anderson , Nick Desaulniers , Greg Hackmann , Matthias Kaehlcke Subject: [PATCH 1/2] bitops: Avoid integer overflow warning in GENMASK_ULL Date: Wed, 2 Aug 2017 15:51:58 -0700 Message-Id: <20170802225159.159536-1-mka@chromium.org> X-Mailer: git-send-email 2.14.0.rc1.383.gd1ce394fe2-goog Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 957 Lines: 26 GENMASK_ULL performs a left-shift of (~0ULL), which technically results in an integer overflow. clang raises a warning about this if the overflow occurs in a preprocessor expression. To avoid the overflow first perform a right-shift to clear the bits that are shifted out. Signed-off-by: Matthias Kaehlcke --- include/linux/bitops.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/bitops.h b/include/linux/bitops.h index a83c822c35c2..21dfe63001e3 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h @@ -22,7 +22,7 @@ (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h)))) #define GENMASK_ULL(h, l) \ - (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h)))) + ((((~0ULL) >> (l)) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h)))) extern unsigned int __sw_hweight8(unsigned int w); extern unsigned int __sw_hweight16(unsigned int w); -- 2.14.0.rc1.383.gd1ce394fe2-goog