Re: [PATCH v3] lib/vsprintf: Preserve the sign of seconds in %ptSp

From: Petr Mladek

Date: Tue Nov 10 2026 - 08:55:28 EST


On Mon 2026-11-09 21:54:45, 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 a signed decimal printf_spec for the seconds and add printf KUnit
> coverage for zero, negative seconds and the signed limits.
>
> Fixes: bccd5937447f ("lib/vsprintf: Add specifier for printing struct timespec64")
> Cc: stable@xxxxxxxxxxxxxxx
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
> Tested-by: Keith Teeple <keithrteeple@xxxxxxxxx>
> Signed-off-by: Hungyu Lin <dennylin0707@xxxxxxxxx>

JFYI, the patch has been committed into printk/linux.git,
branch for-7.5-trivial.

Best Regards,
Petr