public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] bitops: Avoid integer overflow warning in GENMASK_ULL
@ 2017-08-02 22:51 Matthias Kaehlcke
  2017-08-02 22:51 ` [PATCH 2/2] arm64: Define PAGE_OFFSET using GENMASK_ULL Matthias Kaehlcke
  2017-08-03 13:24 ` [PATCH 1/2] bitops: Avoid integer overflow warning in GENMASK_ULL Yury Norov
  0 siblings, 2 replies; 13+ messages in thread
From: Matthias Kaehlcke @ 2017-08-02 22:51 UTC (permalink / raw)
  To: zijun_hu, Andrew Morton, Catalin Marinas, Will Deacon,
	Mark Rutland, Laura Abbott
  Cc: linux-kernel, linux-arm-kernel, Doug Anderson, Nick Desaulniers,
	Greg Hackmann, Matthias Kaehlcke

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 <mka@chromium.org>
---
 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

^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2017-08-04  2:27 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-02 22:51 [PATCH 1/2] bitops: Avoid integer overflow warning in GENMASK_ULL Matthias Kaehlcke
2017-08-02 22:51 ` [PATCH 2/2] arm64: Define PAGE_OFFSET using GENMASK_ULL Matthias Kaehlcke
2017-08-02 23:13   ` Nick Desaulniers
2017-08-02 23:19     ` Nick Desaulniers
2017-08-02 23:44       ` Matthias Kaehlcke
2017-08-03 13:20   ` Yury Norov
2017-08-03 17:11     ` [PATCH] arm64: avoid overflow in VA_START and PAGE_OFFSET Nick Desaulniers
2017-08-03 17:20       ` Ard Biesheuvel
2017-08-03 17:53         ` Nick Desaulniers
2017-08-03 18:03           ` [PATCH v2] " Nick Desaulniers
2017-08-04  2:26   ` [PATCH 2/2] arm64: Define PAGE_OFFSET using GENMASK_ULL kbuild test robot
2017-08-03 13:24 ` [PATCH 1/2] bitops: Avoid integer overflow warning in GENMASK_ULL Yury Norov
2017-08-03 17:03   ` Matthias Kaehlcke

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox