Re: [PATCH v2] lib/string_helpers: renormalize string_get_size() after rounding carry

From: James Bottomley

Date: Mon Apr 20 2026 - 23:05:48 EST


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