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: Mon, 20 Apr 2026 23:04:50 -0400	[thread overview]
Message-ID: <150cda6feffe0826cfd43e5d8f0b4199b6268486.camel@HansenPartnership.com> (raw)
In-Reply-To: <CAHp75VcW0cexQk6Zg-RwKSMBpOxPa3YCAomK7PFXEGLQ0VkrMQ@mail.gmail.com>

On Mon, 2026-04-20 at 09:56 +0300, Andy Shevchenko wrote:
> Please, keep the author of the original change in the loop.

> James, what do you think?

Well firstly I would note that the original behaviour isn't a bug.  It
works that way because of the binary case.  So if you feed in 1023 in
for STRING_UNITS_2 it will return 1023 B. If we're going to allow that
slop for binary, it didn't seem reasonable to be precious about the
over by 1 of decimal.

However, if the desire is for this only ever to print out three
significant figures (is that the desire? because I don't really get it
from the changelog) then this:

> > +       if (size >= divisor[units_base] && i + 1 <
> > ARRAY_SIZE(units_2)) {
> > +               size = 1;
> > +               remainder = 0;
> > +               i++;
> > +               j = 2;

Isn't right.  Size is base_10 here, so it should always be compared
against 1000 and, for the STRING_UNITS_2 case, the lower two digits
need to be carried over to the remainder (with roundup).  I'd also drop
the comparison against ARRAY_SIZE because  you'd still violate the 3sf
rule even if the unit is UNK.

Regards,

James


  reply	other threads:[~2026-04-21  3:04 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 [this message]
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

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=150cda6feffe0826cfd43e5d8f0b4199b6268486.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®