Commit 61f27ba2 authored by Wen Yang's avatar Wen Yang Committed by Greg Kroah-Hartman

timekeeping: Prevent 32bit truncation in scale64_check_overflow()

[ Upstream commit 4cbbc3a0 ]

While unlikely the divisor in scale64_check_overflow() could be >= 32bit in
scale64_check_overflow(). do_div() truncates the divisor to 32bit at least
on 32bit platforms.

Use div64_u64() instead to avoid the truncation to 32-bit.

[ tglx: Massaged changelog ]
Signed-off-by: default avatarWen Yang <wenyang@linux.alibaba.com>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
Link: https://lkml.kernel.org/r/20200120100523.45656-1-wenyang@linux.alibaba.comSigned-off-by: default avatarSasha Levin <sashal@kernel.org>
parent e500a986
...@@ -950,9 +950,8 @@ static int scale64_check_overflow(u64 mult, u64 div, u64 *base) ...@@ -950,9 +950,8 @@ static int scale64_check_overflow(u64 mult, u64 div, u64 *base)
((int)sizeof(u64)*8 - fls64(mult) < fls64(rem))) ((int)sizeof(u64)*8 - fls64(mult) < fls64(rem)))
return -EOVERFLOW; return -EOVERFLOW;
tmp *= mult; tmp *= mult;
rem *= mult;
do_div(rem, div); rem = div64_u64(rem * mult, div);
*base = tmp + rem; *base = tmp + rem;
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment