Skip to content

Commit 4108d14

Browse files
JustinStittIngo Molnar
authored andcommitted
x86/hpet: Refactor code using deprecated strncpy() interface to use strscpy()
`strncpy` is deprecated for use on NUL-terminated destination strings [1]. A suitable replacement is `strscpy` [2] due to the fact that it guarantees NUL-termination on its destination buffer argument which is _not_ the case for `strncpy`! In this case, it is a simple swap from `strncpy` to `strscpy`. There is one slight difference, though. If NUL-padding is a functional requirement here we should opt for `strscpy_pad`. It seems like this shouldn't be needed as I see no obvious signs of any padding being required. Signed-off-by: Justin Stitt <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Link: www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings[1] Link: https://manpages.debian.org/testing/linux-manual-4.8/strscpy.9.en.html [2] Link: KSPP#90 Link: https://lore.kernel.org/r/20230822-strncpy-arch-x86-kernel-hpet-v1-1-2c7d3be86f4a@google.com
1 parent 1e6f01f commit 4108d14

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

arch/x86/kernel/hpet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ static void __init hpet_legacy_clockevent_register(struct hpet_channel *hc)
421421
* the IO_APIC has been initialized.
422422
*/
423423
hc->cpu = boot_cpu_data.cpu_index;
424-
strncpy(hc->name, "hpet", sizeof(hc->name));
424+
strscpy(hc->name, "hpet", sizeof(hc->name));
425425
hpet_init_clockevent(hc, 50);
426426

427427
hc->evt.tick_resume = hpet_clkevt_legacy_resume;

0 commit comments

Comments
 (0)