Skip to content

Commit b545465

Browse files
JustinStittkees
authored andcommitted
cpuidle: dt: 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. A suitable replacement is `strscpy` [2] due to the fact that it guarantees NUL-termination on the destination buffer. With this, we can also drop the now unnecessary `CPUIDLE_(NAME|DESC)_LEN - 1` pieces. 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]> Link: https://lore.kernel.org/r/20230913-strncpy-drivers-cpuidle-dt_idle_states-c-v1-1-d16a0dbe5658@google.com Signed-off-by: Kees Cook <[email protected]>
1 parent 0faf84c commit b545465

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/cpuidle/dt_idle_states.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ static int init_state_node(struct cpuidle_state *idle_state,
8484
* replace with kstrdup and pointer assignment when name
8585
* and desc become string pointers
8686
*/
87-
strncpy(idle_state->name, state_node->name, CPUIDLE_NAME_LEN - 1);
88-
strncpy(idle_state->desc, desc, CPUIDLE_DESC_LEN - 1);
87+
strscpy(idle_state->name, state_node->name, CPUIDLE_NAME_LEN);
88+
strscpy(idle_state->desc, desc, CPUIDLE_DESC_LEN);
8989
return 0;
9090
}
9191

0 commit comments

Comments
 (0)