Skip to content

Commit 212f07a

Browse files
JustinStittIngo Molnar
authored andcommitted
x86/platform/uv: 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 means we can drop the `...-1` from: | strncpy(to, from, len-1); as well as remove the comment mentioning NUL-termination as `strscpy` implicitly grants us this behavior. There should be no functional change as I don't believe the padding from `strncpy` is needed here. If it turns out that the padding is necessary we should use `strscpy_pad` as a direct replacement. Signed-off-by: Justin Stitt <[email protected]> Signed-off-by: Ingo Molnar <[email protected]> Cc: Andy Shevchenko <[email protected]> Cc: Kees Cook <[email protected]> Cc: Dimitri Sivanich <[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-apic-x2apic_uv_x-v1-1-91d681d0b3f3@google.com
1 parent 4108d14 commit 212f07a

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

arch/x86/kernel/apic/x2apic_uv_x.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,7 @@ static void __init early_get_apic_socketid_shift(void)
294294

295295
static void __init uv_stringify(int len, char *to, char *from)
296296
{
297-
/* Relies on 'to' being NULL chars so result will be NULL terminated */
298-
strncpy(to, from, len-1);
297+
strscpy(to, from, len);
299298

300299
/* Trim trailing spaces */
301300
(void)strim(to);
@@ -1013,7 +1012,7 @@ static void __init calc_mmioh_map(enum mmioh_arch index,
10131012

10141013
/* One (UV2) mapping */
10151014
if (index == UV2_MMIOH) {
1016-
strncpy(id, "MMIOH", sizeof(id));
1015+
strscpy(id, "MMIOH", sizeof(id));
10171016
max_io = max_pnode;
10181017
mapped = 0;
10191018
goto map_exit;

0 commit comments

Comments
 (0)