[PATCH v2 2/3] lib/string_helpers.c: don't lose precision in string_get_size()

2015-10-27 Thread Vitaly Kuznetsov
string_get_size() loses precision when there is a remainder for blk_size / divisor[units] and size is big enough. E.g string_get_size(8192, 4096, STRING_UNITS_10, ...) returns "32.7 MB" while it is supposed to return "33.5 MB". For some artificial inputs the result can be ridiculously wrong, e.g. s

Re: [PATCH v2 2/3] lib/string_helpers.c: don't lose precision in string_get_size()

2015-10-27 Thread Andy Shevchenko
On Tue, 2015-10-27 at 15:06 +0100, Vitaly Kuznetsov wrote: > string_get_size() loses precision when there is a remainder for > blk_size / divisor[units] and size is big enough. E.g > string_get_size(8192, 4096, STRING_UNITS_10, ...) returns "32.7 MB" > while it is supposed to return "33.5 MB". For

Re: [PATCH v2 2/3] lib/string_helpers.c: don't lose precision in string_get_size()

2015-10-27 Thread Vitaly Kuznetsov
Andy Shevchenko writes: > On Tue, 2015-10-27 at 15:06 +0100, Vitaly Kuznetsov wrote: >> string_get_size() loses precision when there is a remainder for >> blk_size / divisor[units] and size is big enough. E.g >> string_get_size(8192, 4096, STRING_UNITS_10, ...) returns "32.7 MB" >> while it is su

Re: [PATCH v2 2/3] lib/string_helpers.c: don't lose precision in string_get_size()

2015-10-27 Thread Andy Shevchenko
On Tue, 2015-10-27 at 17:16 +0100, Vitaly Kuznetsov wrote: > Andy Shevchenko writes: [] > > + if (!blk_size) { > > > + WARN_ON(1); > > > > Hmm... Isn't it too strong? WARN_ONCE() might reduce a noise. Or > > even > > pr_warn_once/ratelimited(). > > Nobody is supposed to call string_g

Re: [PATCH v2 2/3] lib/string_helpers.c: don't lose precision in string_get_size()

2015-10-27 Thread Rasmus Villemoes
On Tue, Oct 27 2015, Vitaly Kuznetsov wrote: > string_get_size() loses precision when there is a remainder for > blk_size / divisor[units] and size is big enough. E.g > string_get_size(8192, 4096, STRING_UNITS_10, ...) returns "32.7 MB" > while it is supposed to return "33.5 MB". For some artific

Re: [PATCH v2 2/3] lib/string_helpers.c: don't lose precision in string_get_size()

2015-10-29 Thread Vitaly Kuznetsov
Rasmus Villemoes writes: > On Tue, Oct 27 2015, Vitaly Kuznetsov wrote: > >> string_get_size() loses precision when there is a remainder for >> blk_size / divisor[units] and size is big enough. E.g >> string_get_size(8192, 4096, STRING_UNITS_10, ...) returns "32.7 MB" >> while it is supposed to