diff options
author | Vinod Koul <vkoul@kernel.org> | 2019-06-28 15:07:21 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2019-06-29 04:43:45 -0400 |
commit | 8f9fab480c7a87b10bb5440b5555f370272a5d59 (patch) | |
tree | a7980854d30c6713bfc9ca225fb1f79fc6274327 | |
parent | 1a5f439c7c02837d943e528d46501564d4226757 (diff) |
linux/kernel.h: fix overflow for DIV_ROUND_UP_ULL
DIV_ROUND_UP_ULL adds the two arguments and then invokes
DIV_ROUND_DOWN_ULL. But on a 32bit system the addition of two 32 bit
values can overflow. DIV_ROUND_DOWN_ULL does it correctly and stashes
the addition into a unsigned long long so cast the result to unsigned
long long here to avoid the overflow condition.
[akpm@linux-foundation.org: DIV_ROUND_UP_ULL must be an rval]
Link: http://lkml.kernel.org/r/20190625100518.30753-1-vkoul@kernel.org
Signed-off-by: Vinod Koul <vkoul@kernel.org>
Reviewed-by: Andrew Morton <akpm@linux-foundation.org>
Cc: Bjorn Andersson <bjorn.andersson@linaro.org>
Cc: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | include/linux/kernel.h | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 74b1ee9027f5..0c9bc231107f 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
@@ -93,7 +93,8 @@ | |||
93 | #define DIV_ROUND_DOWN_ULL(ll, d) \ | 93 | #define DIV_ROUND_DOWN_ULL(ll, d) \ |
94 | ({ unsigned long long _tmp = (ll); do_div(_tmp, d); _tmp; }) | 94 | ({ unsigned long long _tmp = (ll); do_div(_tmp, d); _tmp; }) |
95 | 95 | ||
96 | #define DIV_ROUND_UP_ULL(ll, d) DIV_ROUND_DOWN_ULL((ll) + (d) - 1, (d)) | 96 | #define DIV_ROUND_UP_ULL(ll, d) \ |
97 | DIV_ROUND_DOWN_ULL((unsigned long long)(ll) + (d) - 1, (d)) | ||
97 | 98 | ||
98 | #if BITS_PER_LONG == 32 | 99 | #if BITS_PER_LONG == 32 |
99 | # define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP_ULL(ll, d) | 100 | # define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP_ULL(ll, d) |