summaryrefslogtreecommitdiffstats
path: root/include/linux
diff options
context:
space:
mode:
authorVinod Koul <vkoul@kernel.org>2019-06-28 12:07:21 -0700
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2019-07-21 09:03:11 +0200
commit2656ee5a5ad59300bbe183d0833867a582910dcc (patch)
treec49b4837b593a50cc449142b8a29d4f4b6180303 /include/linux
parent9c875e8556d4176d476ea55f1fe747a40b37bec8 (diff)
downloadlinux-stable-2656ee5a5ad59300bbe183d0833867a582910dcc.tar.gz
linux-stable-2656ee5a5ad59300bbe183d0833867a582910dcc.tar.bz2
linux-stable-2656ee5a5ad59300bbe183d0833867a582910dcc.zip
linux/kernel.h: fix overflow for DIV_ROUND_UP_ULL
[ Upstream commit 8f9fab480c7a87b10bb5440b5555f370272a5d59 ] 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> Signed-off-by: Sasha Levin <sashal@kernel.org>
Diffstat (limited to 'include/linux')
-rw-r--r--include/linux/kernel.h3
1 files changed, 2 insertions, 1 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 3d83ebb302cf..f6f94e54ab96 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -118,7 +118,8 @@
#define DIV_ROUND_DOWN_ULL(ll, d) \
({ unsigned long long _tmp = (ll); do_div(_tmp, d); _tmp; })
-#define DIV_ROUND_UP_ULL(ll, d) DIV_ROUND_DOWN_ULL((ll) + (d) - 1, (d))
+#define DIV_ROUND_UP_ULL(ll, d) \
+ DIV_ROUND_DOWN_ULL((unsigned long long)(ll) + (d) - 1, (d))
#if BITS_PER_LONG == 32
# define DIV_ROUND_UP_SECTOR_T(ll,d) DIV_ROUND_UP_ULL(ll, d)