Skip to content

Commit 0faf84c

Browse files
JustinStittkees
authored andcommitted
cpufreq: Replace deprecated strncpy() with strscpy()
`strncpy` is deprecated for use on NUL-terminated destination strings [1]. We should prefer more robust and less ambiguous string interfaces. Both `policy->last_governor` and `default_governor` are expected to be NUL-terminated which is shown by their heavy usage with other string apis like `strcmp`. A suitable replacement is `strscpy` [2] due to the fact that it guarantees NUL-termination on the destination buffer. Link: https://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 Cc: [email protected] Signed-off-by: Justin Stitt <[email protected]> Reviewed-by: Kees Cook <[email protected]> Acked-by: Viresh Kumar <[email protected]> Link: https://lore.kernel.org/r/20230913-strncpy-drivers-cpufreq-cpufreq-c-v1-1-f1608bfeff63@google.com Signed-off-by: Kees Cook <[email protected]>
1 parent de055e6 commit 0faf84c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/cpufreq/cpufreq.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1650,7 +1650,7 @@ static void __cpufreq_offline(unsigned int cpu, struct cpufreq_policy *policy)
16501650
}
16511651

16521652
if (has_target())
1653-
strncpy(policy->last_governor, policy->governor->name,
1653+
strscpy(policy->last_governor, policy->governor->name,
16541654
CPUFREQ_NAME_LEN);
16551655
else
16561656
policy->last_policy = policy->policy;
@@ -2996,7 +2996,7 @@ static int __init cpufreq_core_init(void)
29962996
BUG_ON(!cpufreq_global_kobject);
29972997

29982998
if (!strlen(default_governor))
2999-
strncpy(default_governor, gov->name, CPUFREQ_NAME_LEN);
2999+
strscpy(default_governor, gov->name, CPUFREQ_NAME_LEN);
30003000

30013001
return 0;
30023002
}

0 commit comments

Comments
 (0)