diff options
Diffstat (limited to 'include/linux/overflow.h')
-rw-r--r-- | include/linux/overflow.h | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/include/linux/overflow.h b/include/linux/overflow.h index 6534a727cadb..659045046468 100644 --- a/include/linux/overflow.h +++ b/include/linux/overflow.h | |||
@@ -36,6 +36,12 @@ | |||
36 | #define type_max(T) ((T)((__type_half_max(T) - 1) + __type_half_max(T))) | 36 | #define type_max(T) ((T)((__type_half_max(T) - 1) + __type_half_max(T))) |
37 | #define type_min(T) ((T)((T)-type_max(T)-(T)1)) | 37 | #define type_min(T) ((T)((T)-type_max(T)-(T)1)) |
38 | 38 | ||
39 | /* | ||
40 | * Avoids triggering -Wtype-limits compilation warning, | ||
41 | * while using unsigned data types to check a < 0. | ||
42 | */ | ||
43 | #define is_non_negative(a) ((a) > 0 || (a) == 0) | ||
44 | #define is_negative(a) (!(is_non_negative(a))) | ||
39 | 45 | ||
40 | #ifdef COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW | 46 | #ifdef COMPILER_HAS_GENERIC_BUILTIN_OVERFLOW |
41 | /* | 47 | /* |
@@ -227,10 +233,10 @@ | |||
227 | typeof(d) _d = d; \ | 233 | typeof(d) _d = d; \ |
228 | u64 _a_full = _a; \ | 234 | u64 _a_full = _a; \ |
229 | unsigned int _to_shift = \ | 235 | unsigned int _to_shift = \ |
230 | _s >= 0 && _s < 8 * sizeof(*d) ? _s : 0; \ | 236 | is_non_negative(_s) && _s < 8 * sizeof(*d) ? _s : 0; \ |
231 | *_d = (_a_full << _to_shift); \ | 237 | *_d = (_a_full << _to_shift); \ |
232 | (_to_shift != _s || *_d < 0 || _a < 0 || \ | 238 | (_to_shift != _s || is_negative(*_d) || is_negative(_a) || \ |
233 | (*_d >> _to_shift) != _a); \ | 239 | (*_d >> _to_shift) != _a); \ |
234 | }) | 240 | }) |
235 | 241 | ||
236 | /** | 242 | /** |