mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Hungyu Lin <dennylin0707@gmail.com>
Cc: pmladek@suse.com, rostedt@goodmis.org, linux@rasmusvillemoes.dk,
	senozhatsky@chromium.org, akpm@linux-foundation.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] lib/vsprintf: Preserve the sign of seconds in %ptSp
Date: Wed, 21 Oct 2026 12:22:37 +0300	[thread overview]
Message-ID: <atiEXdNApPHi5ObO@ashevche-desk.local> (raw)
In-Reply-To: <20261020220243.67919-1-dennylin0707@gmail.com>

On Tue, Oct 20, 2026 at 10:02:43PM +0000, Hungyu Lin wrote:
> The documentation defines %ptSp as equivalent to %lld.%09ld, but
> timespec64_str() formats tv_sec with default_dec_spec, which does not
> have SIGN set. Negative seconds are therefore printed as unsigned
> values: {-1, 0} produces "18446744073709551615.000000000" instead of
> "-1.000000000".
> 
> Negative values can arise from time differences, for example in
> fnic_get_stats_data() after the realtime clock steps backwards.
> 
> Use signed decimal formatting for the seconds and add printf KUnit
> coverage for zero, negative seconds and the signed limits.

Thanks for the report and the patch. My comment below.

...

> -	if (fmt[2] == 'p')
> -		buf = number(buf, end, ts->tv_sec, default_dec_spec);
> -	else
> +	if (fmt[2] == 'p') {
> +		spec = default_dec_spec;
> +		spec.flags |= SIGN;
> +		buf = number(buf, end, ts->tv_sec, spec);

Instead, add a new default_signed_dec_spec above and use it here.
While at it, make field_width to be explicitly -1, so

static const struct printf_spec default_signed_dec_spec = {
        .base = 10,
        .field_width = -1,
        .precision = -1,
	.flags = SIGN,
};

> +	} else {
>  		buf = time64_str(buf, end, ts->tv_sec, spec, fmt);
> +	}

-- 
With Best Regards,
Andy Shevchenko



      reply	other threads:[~2026-10-21  9:22 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-20 22:02 Hungyu Lin
2026-10-21  9:22 ` Andy Shevchenko [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=atiEXdNApPHi5ObO@ashevche-desk.local \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=akpm@linux-foundation.org \
    --cc=dennylin0707@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@rasmusvillemoes.dk \
    --cc=pmladek@suse.com \
    --cc=rostedt@goodmis.org \
    --cc=senozhatsky@chromium.org \
    /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®