From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Vitaly Kuznetsov <vkuznets@redhat.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
Rasmus Villemoes <linux@rasmusvillemoes.dk>,
Ulf Hansson <ulf.hansson@linaro.org>,
James Bottomley <JBottomley@Odin.com>,
Kees Cook <keescook@chromium.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/3] lib/string_helpers.c: don't lose precision in string_get_size()
Date: Tue, 27 Oct 2015 11:34:33 +0200 [thread overview]
Message-ID: <1445938473.6332.17.camel@linux.intel.com> (raw)
In-Reply-To: <87fv0wyah4.fsf@vitty.brq.redhat.com>
On Tue, 2015-10-27 at 09:36 +0100, Vitaly Kuznetsov wrote:
> Andy Shevchenko <andriy.shevchenko@linux.intel.com> writes:
>
> > On Mon, 2015-10-26 at 14:55 +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 some artificial
> > > inputs
> > > the result can be ridiculously wrong, e.g.
> > > string_get_size(3000, 1900, STRING_UNITS_10, ...) returns "3.00
> > > MB"
> > > when "5.70 MB" is expected.
[]
> > > - int i, j;
> > > - u32 remainder = 0, sf_cap, exp;
> > > + int order = 0, j;
> > > + u64 remainder = 0;
> > > + u32 sf_cap;
> > > char tmp[8];
> > > const char *unit;
> > >
> > > tmp[0] = '\0';
> > > - i = 0;
> >
> > Maybe leave i naming as is. Your order is not strictly speaking an
> > order, rather 3x order. I will make patch neater.
> >
>
> While reading the original function I found meaningless 'i' and 'j'
> here
> a bit consufing but yes, strictly speaking 'i' is a power of
> divisor[units], not 'order' and I don't have a good name for it
> (div_power?). I'll revert back to 'i' in v2.
I agree that names suck, however it might be better to have separate
patch to fix naming.
Rasmus?
--
Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Intel Finland Oy
next prev parent reply other threads:[~2015-10-27 9:36 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-26 13:55 [PATCH 0/3] lib/string_helpers: fix precision issues and introduce tests Vitaly Kuznetsov
2015-10-26 13:55 ` [PATCH 1/3] lib/string_helpers: change blk_size to u32 for string_get_size() interface Vitaly Kuznetsov
2015-10-26 13:55 ` [PATCH 2/3] lib/string_helpers.c: don't lose precision in string_get_size() Vitaly Kuznetsov
2015-10-26 16:08 ` Andy Shevchenko
2015-10-27 8:36 ` Vitaly Kuznetsov
2015-10-27 9:34 ` Andy Shevchenko [this message]
2015-10-26 21:48 ` Rasmus Villemoes
2015-10-27 8:45 ` Vitaly Kuznetsov
2015-10-26 13:55 ` [PATCH 3/3] lib/test-string_helpers.c: add string_get_size() tests Vitaly Kuznetsov
2015-10-26 15:13 ` Andy Shevchenko
2015-10-26 15:18 ` Vitaly Kuznetsov
2015-10-26 15:21 ` Andy Shevchenko
2015-10-26 15:50 ` Vitaly Kuznetsov
2015-10-26 21:54 ` Rasmus Villemoes
2015-10-27 8:56 ` Vitaly Kuznetsov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1445938473.6332.17.camel@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=JBottomley@Odin.com \
--cc=akpm@linux-foundation.org \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@rasmusvillemoes.dk \
--cc=ulf.hansson@linaro.org \
--cc=vkuznets@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).