Skip to content

Commit

Permalink
linux/kernel.h: fix overflow for DIV_ROUND_UP_ULL
Browse files Browse the repository at this point in the history
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.

[[email protected]: DIV_ROUND_UP_ULL must be an rval]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Vinod Koul <[email protected]>
Reviewed-by: Andrew Morton <[email protected]>
Cc: Bjorn Andersson <[email protected]>
Cc: Randy Dunlap <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
vinodkoul authored and torvalds committed Jun 29, 2019
1 parent 1a5f439 commit 8f9fab4
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion include/linux/kernel.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,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)
Expand Down

0 comments on commit 8f9fab4

Please sign in to comment.