mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: James Bottomley <James.Bottomley@HansenPartnership.com>
To: Andy Shevchenko <andy.shevchenko@gmail.com>,
	Shuvam Pandey <shuvampandey1@gmail.com>
Cc: Kees Cook <kees@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	 Andy Shevchenko <andy@kernel.org>,
	linux-hardening@vger.kernel.org,  linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] lib/string_helpers: renormalize string_get_size() after rounding carry
Date: Tue, 21 Apr 2026 08:16:24 -0400	[thread overview]
Message-ID: <696d25567aadbb8ba324d4a980c15eb5cf4ccef6.camel@HansenPartnership.com> (raw)
In-Reply-To: <CAHp75VfB0Y7K=chk5wpKtZcgVfCN5X7zhNEq6QSrirdgHs5_bQ@mail.gmail.com>

On Tue, 2026-04-21 at 07:53 +0300, Andy Shevchenko wrote:
> On Tue, Apr 21, 2026 at 6:38 AM Shuvam Pandey
> <shuvampandey1@gmail.com> wrote:
> 
> > > Well firstly I would note that the original behaviour isn't a
> > > bug.
> 
> James, thank you for the prompt reply!
> 
> > So I agree this should not go forward as a bug fix in its current
> > form. I'll drop this patch here and revisit it only if I can come
> > back with a better understanding of the intended semantics.
> 
> Shuvam, perhaps we need to add a few more test cases first to
> understand current behaviour better?

Sure, but the base 2 one is the problem.  It will go up to 1023 in
whatever units but for binary that's under 1 of the next unit up.  So

1023 B == 1.00 KiB
1018 B == 0.99 KiB
1000 B == 0.98 KiB

And so on.  However, technically the latter two (when converted to the
upper unit) are only 2sf not 3 because the leading zero doesn't count.
If you run the above to 3sf it comes out

1023 B == 0.999 KiB
1018 B == 0.994 KiB
1000 B == 0.977 KiB

If the desire is really to be 3sf everywhere, you need the latter and
the routine can be adjusted to do that: the while  around the do_div
would have to be checking strictly >= 1000 and you now have to set j=0
if size comes out 0.  Rounding also has to be done inside that loop now
(because too much precision is lost in the j = 3 case).

But, like I said, this isn't a bug fix it's a behaviour change.

Regards,

James


      parent reply	other threads:[~2026-04-21 12:16 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-07 14:33 [PATCH] lib/string_helpers: fix string_get_size() unit promotion after rounding Shuvam Pandey
2026-04-07 14:53 ` Andy Shevchenko
     [not found]   ` <CANAAWH+ihOpBVB5_Q4gxLs0_zO=pHb-kF53UXE-pqg1U9E9OKw@mail.gmail.com>
     [not found]     ` <adayT_7xAtOLiVlq@ashevche-desk.local>
     [not found]       ` <CANAAWHKDBoi1x=MpAyU5bQ88=ZOOrkaJNziyhcK9Ei7c8oNSHg@mail.gmail.com>
     [not found]         ` <CANAAWHKZXbFAr7=DRCrS46GDsWi88Q=v883RQrgF4+EScksP=w@mail.gmail.com>
2026-04-14  7:19           ` Andy Shevchenko
2026-04-14  8:06             ` Shuvam Pandey
2026-04-19 15:31 ` [PATCH v2] lib/string_helpers: renormalize string_get_size() after rounding carry Shuvam Pandey
2026-04-20  6:56   ` Andy Shevchenko
2026-04-21  3:04     ` James Bottomley
2026-04-21  3:38       ` Shuvam Pandey
2026-04-21  4:53         ` Andy Shevchenko
2026-04-21 10:10           ` Shuvam Pandey
2026-04-21 12:16           ` James Bottomley [this message]

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=696d25567aadbb8ba324d4a980c15eb5cf4ccef6.camel@HansenPartnership.com \
    --to=james.bottomley@hansenpartnership.com \
    --cc=akpm@linux-foundation.org \
    --cc=andy.shevchenko@gmail.com \
    --cc=andy@kernel.org \
    --cc=kees@kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shuvampandey1@gmail.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

all inboxes | Powered by JetHome®