]>
Commit | Line | Data |
---|---|---|
6fa88700 GKH |
1 | From a2783e3dab88b3062ed1612187b90c7fc36d67a9 Mon Sep 17 00:00:00 2001 |
2 | From: Matthias Kaehlcke <mka@chromium.org> | |
3 | Date: Fri, 8 Sep 2017 16:14:33 -0700 | |
4 | Subject: [PATCH 12/76] bitops: avoid integer overflow in GENMASK(_ULL) | |
5 | ||
6 | commit c32ee3d9abd284b4fcaacc250b101f93829c7bae upstream. | |
7 | ||
8 | GENMASK(_ULL) performs a left-shift of ~0UL(L), which technically | |
9 | results in an integer overflow. clang raises a warning if the overflow | |
10 | occurs in a preprocessor expression. Clear the low-order bits through a | |
11 | substraction instead of the left-shift to avoid the overflow. | |
12 | ||
13 | (akpm: no change in .text size in my testing) | |
14 | ||
15 | Link: http://lkml.kernel.org/r/20170803212020.24939-1-mka@chromium.org | |
16 | Signed-off-by: Matthias Kaehlcke <mka@chromium.org> | |
17 | Signed-off-by: Andrew Morton <akpm@linux-foundation.org> | |
18 | Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> | |
19 | Signed-off-by: Ben Hutchings <ben@decadent.org.uk> | |
20 | Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> | |
21 | --- | |
22 | include/linux/bitops.h | 5 +++-- | |
23 | 1 file changed, 3 insertions(+), 2 deletions(-) | |
24 | ||
25 | diff --git a/include/linux/bitops.h b/include/linux/bitops.h | |
26 | index a83c822c35c2..8fbe259b197c 100644 | |
27 | --- a/include/linux/bitops.h | |
28 | +++ b/include/linux/bitops.h | |
29 | @@ -19,10 +19,11 @@ | |
30 | * GENMASK_ULL(39, 21) gives us the 64bit vector 0x000000ffffe00000. | |
31 | */ | |
32 | #define GENMASK(h, l) \ | |
33 | - (((~0UL) << (l)) & (~0UL >> (BITS_PER_LONG - 1 - (h)))) | |
34 | + (((~0UL) - (1UL << (l)) + 1) & (~0UL >> (BITS_PER_LONG - 1 - (h)))) | |
35 | ||
36 | #define GENMASK_ULL(h, l) \ | |
37 | - (((~0ULL) << (l)) & (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h)))) | |
38 | + (((~0ULL) - (1ULL << (l)) + 1) & \ | |
39 | + (~0ULL >> (BITS_PER_LONG_LONG - 1 - (h)))) | |
40 | ||
41 | extern unsigned int __sw_hweight8(unsigned int w); | |
42 | extern unsigned int __sw_hweight16(unsigned int w); | |
43 | -- | |
44 | 2.21.0 | |
45 |