]> git.baikalelectronics.ru Git - kernel.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)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 21 Jan 2016 01:09:18 +0000 (17:09 -0800)
commitb852a485da537c1d0a0ac5c3c7d095aae97b3e39
treeab7a5f6751cb7ef5764031e6f9bfee8a051aa2a7
parente594be3f62ea77edf8dcff87dac1eec35e9a5ab6
string_helpers: fix precision loss for some inputs

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: 81753e54e611ef1bb4290e1215cb3d70fdf7c0c6
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>
lib/string_helpers.c