All of lore.kernel.org
 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; 5+ 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@kernel.org, H. Peter Anvin, Jiri Wiesner, Daniel J Blueman,
	Habil Eren Türker, linux-kernel@vger.kernel.org

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 related	[flat|nested] 5+ 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; 5+ messages in thread
From: Edgecombe, Rick P @ 2026-11-19 23:04 UTC (permalink / raw)
  To: dave.hansen@linux.intel.com, bp@alien8.de, hpa@zytor.com,
	mingo@redhat.com, daniel@quora.org, x86@kernel.org,
	habilerenturker@hotmail.com, tglx@kernel.org, jwiesner@suse.de,
	linux-kernel@vger.kernel.org

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] 5+ 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
  2026-11-19 23:50     ` Dave Hansen
  0 siblings, 1 reply; 5+ messages in thread
From: Habil Eren Türker @ 2026-11-19 23:28 UTC (permalink / raw)
  To: rick.p.edgecombe@intel.com
  Cc: bp@alien8.de, daniel@quora.org, dave.hansen@linux.intel.com,
	Habil Eren Türker, hpa@zytor.com, jwiesner@suse.de,
	linux-kernel@vger.kernel.org, mingo@redhat.com, tglx@kernel.org,
	x86@kernel.org

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] 5+ messages in thread

* Re: [PATCH] x86/hpet: Replace sprintf() with scnprintf() in hpet_select_clockevents()
  2026-11-19 23:28   ` Habil Eren Türker
@ 2026-11-19 23:50     ` Dave Hansen
  2026-11-19 23:59       ` Habil Eren Türker
  0 siblings, 1 reply; 5+ messages in thread
From: Dave Hansen @ 2026-11-19 23:50 UTC (permalink / raw)
  To: Habil Eren Türker, rick.p.edgecombe@intel.com
  Cc: bp@alien8.de, daniel@quora.org, dave.hansen@linux.intel.com,
	hpa@zytor.com, jwiesner@suse.de, linux-kernel@vger.kernel.org,
	mingo@redhat.com, tglx@kernel.org, x86@kernel.org

On 11/19/26 15:28, Habil Eren Türker wrote:
> I can prepare a v2 patch and correct the commit message.
> Is that okay with you?

This is like a spelling or whitespace fix. It's acceptable as part of
other work on the code, but I'm not super interested in these on their own.

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

* Re: [PATCH] x86/hpet: Replace sprintf() with scnprintf() in hpet_select_clockevents()
  2026-11-19 23:50     ` Dave Hansen
@ 2026-11-19 23:59       ` Habil Eren Türker
  0 siblings, 0 replies; 5+ messages in thread
From: Habil Eren Türker @ 2026-11-19 23:59 UTC (permalink / raw)
  To: dave.hansen@intel.com
  Cc: bp@alien8.de, daniel@quora.org, dave.hansen@linux.intel.com,
	Habil Eren Türker, hpa@zytor.com, jwiesner@suse.de,
	linux-kernel@vger.kernel.org, mingo@redhat.com,
	rick.p.edgecombe@intel.com, tglx@kernel.org, x86@kernel.org

Understood, it makes sense. I will drop the patch. Thanks for 
the review.

Regards,
Türker

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

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

Thread overview: 5+ 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
2026-11-19 23:50     ` Dave Hansen
2026-11-19 23:59       ` Habil Eren Türker

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.