diff options
| author | Matthias Kaehlcke <mka@chromium.org> | 2017-09-08 19:14:33 -0400 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-09-08 21:26:48 -0400 |
| commit | c32ee3d9abd284b4fcaacc250b101f93829c7bae (patch) | |
| tree | 14da37d4c3debe116e378f3de20099babf0de1c3 /include | |
| parent | e9ef073a0796e46c24f037237291efe56fc28ad9 (diff) | |
bitops: avoid integer overflow in GENMASK(_ULL)
GENMASK(_ULL) performs a left-shift of ~0UL(L), which technically
results in an integer overflow. clang raises a warning if the overflow
occurs in a preprocessor expression. Clear the low-order bits through a
substraction instead of the left-shift to avoid the overflow.
(akpm: no change in .text size in my testing)
Link: http://lkml.kernel.org/r/20170803212020.24939-1-mka@chromium.org
Signed-off-by: Matthias Kaehlcke <mka@chromium.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include')
| -rw-r--r-- | include/linux/bitops.h | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/include/linux/bitops.h b/include/linux/bitops.h index a83c822c35c2..8fbe259b197c 100644 --- a/include/linux/bitops.h +++ b/include/linux/bitops.h | |||
| @@ -19,10 +19,11 @@ | |||
| 19 | * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000. | 19 | * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000. |
| 20 | */ | 20 | */ |
| 21 | #define GENMASK(h, l) \ | 21 | #define GENMASK(h, l) \ |
| 22 | (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h)))) | 22 | (((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h)))) |
| 23 | 23 | ||
| 24 | #define GENMASK_ULL(h, l) \ | 24 | #define GENMASK_ULL(h, l) \ |
| 25 | (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h)))) | 25 | (((~0ULL) - (1ULL << (l)) + 1) & \ |
| 26 | (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h)))) | ||
| 26 | 27 | ||
| 27 | extern unsigned int __sw_hweight8(unsigned int w); | 28 | extern unsigned int __sw_hweight8(unsigned int w); |
| 28 | extern unsigned int __sw_hweight16(unsigned int w); | 29 | extern unsigned int __sw_hweight16(unsigned int w); |
