From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753872AbbJ0Jgs (ORCPT ); Tue, 27 Oct 2015 05:36:48 -0400 Received: from mga09.intel.com ([134.134.136.24]:3369 "EHLO mga09.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752692AbbJ0Jgp (ORCPT ); Tue, 27 Oct 2015 05:36:45 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.20,204,1444719600"; d="scan'208";a="835966973" Message-ID: <1445938473.6332.17.camel@linux.intel.com> Subject: Re: [PATCH 2/3] lib/string_helpers.c: don't lose precision in string_get_size() From: Andy Shevchenko To: Vitaly Kuznetsov Cc: Andrew Morton , Rasmus Villemoes , Ulf Hansson , James Bottomley , Kees Cook , linux-kernel@vger.kernel.org Date: Tue, 27 Oct 2015 11:34:33 +0200 In-Reply-To: <87fv0wyah4.fsf@vitty.brq.redhat.com> References: <1445867720-25473-1-git-send-email-vkuznets@redhat.com> <1445867720-25473-3-git-send-email-vkuznets@redhat.com> <1445875739.6332.2.camel@linux.intel.com> <87fv0wyah4.fsf@vitty.brq.redhat.com> Organization: Intel Finland Oy Content-Type: text/plain; charset="UTF-8" X-Mailer: Evolution 3.18.1-1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, 2015-10-27 at 09:36 +0100, Vitaly Kuznetsov wrote: > Andy Shevchenko 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 Intel Finland Oy