]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
string_helpers: fix precision loss for some inputs
authorJames Bottomley <JBottomley@Odin.com>
Wed, 20 Jan 2016 22:58:29 +0000 (14:58 -0800)
committerSasha Levin <sasha.levin@oracle.com>
Wed, 3 Feb 2016 21:23:22 +0000 (16:23 -0500)
commitc81f4f0331deb1b482d93b3ac8da5f04ff20ad48
treeff374ae18d54c4278fcf3c8201748fbbfdf1dd69
parent4aba5827e764110bd1462eecf79209e656090f9c
string_helpers: fix precision loss for some inputs

[ Upstream commit 564b026fbd0d28e9f70fb3831293d2922bb7855b ]

It was noticed that we lose precision in the final calculation for some
inputs.  The most egregious example is size=3000 blk_size=1900 in units
of 10 should yield 5.70 MB but in fact yields 3.00 MB (oops).

This is because the current algorithm doesn't correctly account for
all the remainders in the logarithms.  Fix this by doing a correct
calculation in the remainders based on napier's algorithm.

Additionally, now we have the correct result, we have to account for
arithmetic rounding because we're printing 3 digits of precision.  This
means that if the fourth digit is five or greater, we have to round up,
so add a section to ensure correct rounding.  Finally account for all
possible inputs correctly, including zero for block size.

Fixes: b9f28d863594c429e1df35a0474d2663ca28b307
Signed-off-by: James Bottomley <JBottomley@Odin.com>
Reported-by: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: <stable@vger.kernel.org> [delay until after 4.4 release]
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Sasha Levin <sasha.levin@oracle.com>
lib/string_helpers.c