mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Shuvam Pandey <shuvampandey1@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Kees Cook <kees@kernel.org>, Andy Shevchenko <andy@kernel.org>,
	linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org
Subject: Re: [PATCH] lib/string_helpers: fix string_get_size() unit promotion after rounding
Date: Tue, 7 Apr 2026 17:53:02 +0300	[thread overview]
Message-ID: <adUaTrU_DZuK1Kd8@ashevche-desk.local> (raw)
In-Reply-To: <20260407143306.78809-1-shuvampandey1@gmail.com>

On Tue, Apr 07, 2026 at 08:18:06PM +0545, Shuvam Pandey wrote:
> string_get_size() rounds the fractional part before formatting the
> result. If that carry pushes the integer part to the unit divisor, the
> value is still printed in the old unit.
> 
> This yields outputs like "1000 kB" for 999500 bytes and "1024 KiB" for
> 1048064 bytes instead of promoting them to the next unit.

What does it print for 1048575, 1048576, 1048577 respectively?
(before and after your patch)

All the same for numbers around 2MiB.

> Renormalize the value after the carry so it is promoted before
> formatting. Add KUnit coverage for the decimal and binary boundary
> cases.

...

> --- a/lib/tests/string_helpers_kunit.c
> +++ b/lib/tests/string_helpers_kunit.c

Thumb up for the test cases!

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2026-04-07 14:53 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-07 14:33 Shuvam Pandey
2026-04-07 14:53 ` Andy Shevchenko [this message]
     [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

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=adUaTrU_DZuK1Kd8@ashevche-desk.local \
    --to=andriy.shevchenko@intel.com \
    --cc=akpm@linux-foundation.org \
    --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®