mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] x86/hpet: Replace sprintf() with scnprintf() in hpet_select_clockevents()
@ 2026-11-17 11:39 Habil Eren Türker
  2026-11-19 23:04 ` Edgecombe, Rick P
  0 siblings, 1 reply; 3+ messages in thread
From: Habil Eren Türker @ 2026-11-17 11:39 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, Borislav Petkov, Dave Hansen, x86,
	H. Peter Anvin, Jiri Wiesner, Daniel J Blueman,
	Habil Eren Türker, linux-kernel

Replace the deprecated sprintf() call with scnprintf() when formatting
the per-CPU HPET channel name into the 10-byte hc->name buffer.
Using scnprintf() ensures null-termination while avoiding
-Wformat-truncation warnings for the unsigned int channel index.

Signed-off-by: Habil Eren Türker <habilerenturker@hotmail.com>
---
 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)
-- 
2.47.3


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/hpet: Replace sprintf() with scnprintf() in hpet_select_clockevents()
  2026-11-17 11:39 [PATCH] x86/hpet: Replace sprintf() with scnprintf() in hpet_select_clockevents() Habil Eren Türker
@ 2026-11-19 23:04 ` Edgecombe, Rick P
  2026-11-19 23:28   ` Habil Eren Türker
  0 siblings, 1 reply; 3+ messages in thread
From: Edgecombe, Rick P @ 2026-11-19 23:04 UTC (permalink / raw)
  To: dave.hansen, bp, hpa, mingo, daniel, x86, habilerenturker, tglx,
	jwiesner, linux-kernel

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@hotmail.com>
> ---
>  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)



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] x86/hpet: Replace sprintf() with scnprintf() in hpet_select_clockevents()
  2026-11-19 23:04 ` Edgecombe, Rick P
@ 2026-11-19 23:28   ` Habil Eren Türker
  0 siblings, 0 replies; 3+ messages in thread
From: Habil Eren Türker @ 2026-11-19 23:28 UTC (permalink / raw)
  To: rick.p.edgecombe
  Cc: bp, daniel, dave.hansen, Habil Eren Türker, hpa, jwiesner,
	linux-kernel, mingo, tglx, x86

Hello Rick, 
Thank you for your review. 

I didn't actually see a compiler warning. I just assumed that sprintf()
might cause a truncation warning here, so I added that to the 
commit message.

My main motivation was simply to remove the deprecated sprintf() usage as
it is considered unsafe.

I can prepare a v2 patch and correct the commit message.
Is that okay with you?

Regards,
Türker

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-19 23:28 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-17 11:39 [PATCH] x86/hpet: Replace sprintf() with scnprintf() in hpet_select_clockevents() Habil Eren Türker
2026-11-19 23:04 ` Edgecombe, Rick P
2026-11-19 23:28   ` Habil Eren Türker

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®