]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - queue-3.18/lib-div64.c-off-by-one-in-shift.patch
autosel patches for 3.18
[thirdparty/kernel/stable-queue.git] / queue-3.18 / lib-div64.c-off-by-one-in-shift.patch
1 From dd59dac3d4d81e5d9469bd20d48fe55e8cbd53a2 Mon Sep 17 00:00:00 2001
2 From: Stanislaw Gruszka <sgruszka@redhat.com>
3 Date: Thu, 7 Mar 2019 16:28:18 -0800
4 Subject: lib/div64.c: off by one in shift
5
6 [ Upstream commit cdc94a37493135e355dfc0b0e086d84e3eadb50d ]
7
8 fls counts bits starting from 1 to 32 (returns 0 for zero argument). If
9 we add 1 we shift right one bit more and loose precision from divisor,
10 what cause function incorect results with some numbers.
11
12 Corrected code was tested in user-space, see bugzilla:
13 https://bugzilla.kernel.org/show_bug.cgi?id=202391
14
15 Link: http://lkml.kernel.org/r/1548686944-11891-1-git-send-email-sgruszka@redhat.com
16 Fixes: 658716d19f8f ("div64_u64(): improve precision on 32bit platforms")
17 Signed-off-by: Stanislaw Gruszka <sgruszka@redhat.com>
18 Reported-by: Siarhei Volkau <lis8215@gmail.com>
19 Tested-by: Siarhei Volkau <lis8215@gmail.com>
20 Acked-by: Oleg Nesterov <oleg@redhat.com>
21 Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
22 Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
23 Signed-off-by: Sasha Levin <sashal@kernel.org>
24 ---
25 lib/div64.c | 4 ++--
26 1 file changed, 2 insertions(+), 2 deletions(-)
27
28 diff --git a/lib/div64.c b/lib/div64.c
29 index 4382ad77777e..ce76dc3d674e 100644
30 --- a/lib/div64.c
31 +++ b/lib/div64.c
32 @@ -100,7 +100,7 @@ u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
33 quot = div_u64_rem(dividend, divisor, &rem32);
34 *remainder = rem32;
35 } else {
36 - int n = 1 + fls(high);
37 + int n = fls(high);
38 quot = div_u64(dividend >> n, divisor >> n);
39
40 if (quot != 0)
41 @@ -138,7 +138,7 @@ u64 div64_u64(u64 dividend, u64 divisor)
42 if (high == 0) {
43 quot = div_u64(dividend, divisor);
44 } else {
45 - int n = 1 + fls(high);
46 + int n = fls(high);
47 quot = div_u64(dividend >> n, divisor >> n);
48
49 if (quot != 0)
50 --
51 2.19.1
52