Re: [PATCH] x86/hpet: Replace sprintf() with scnprintf() in hpet_select_clockevents()
From: Edgecombe, Rick P
Date: Thu Nov 19 2026 - 18:05:12 EST
On Tue, 2026-11-17 at 11:39 +0000, Habil Eren Türker wrote:
> Replace the deprecated sprintf() call with scnprintf() when formatting
> the per-CPU HPET channel name into the 10-byte hc->name buffer.
It gets read, then masked by 0x00001f00, and shifted right by 8, then add 1. So
a max value of 32. It seems it can't overflow, no matter what the HW reports.
> Using scnprintf() ensures null-termination while avoiding
> -Wformat-truncation warnings for the unsigned int channel index.
Did you see a real compiler warning for this?
>
> Signed-off-by: Habil Eren Türker <habilerenturker@xxxxxxxxxxx>
> ---
> arch/x86/kernel/hpet.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/x86/kernel/hpet.c b/arch/x86/kernel/hpet.c
> index 8dc7b710e125..0edf0fe0ac2b 100644
> --- a/arch/x86/kernel/hpet.c
> +++ b/arch/x86/kernel/hpet.c
> @@ -722,7 +722,7 @@ static void __init hpet_select_clockevents(void)
> if (!(hc->boot_cfg & HPET_TN_FSB_CAP))
> continue;
>
> - sprintf(hc->name, "hpet%d", i);
> + scnprintf(hc->name, sizeof(hc->name), "hpet%u", i);
>
> irq = hpet_assign_irq(hpet_domain, hc, hc->num);
> if (irq <= 0)