Skip to content

Commit

Permalink
firmware: ti_sci: refactor deprecated strncpy
Browse files Browse the repository at this point in the history
`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.

It does not seem like `ver->firmware_description` requires NUL-padding
(which is a behavior that strncpy provides) but if it does let's opt for
`strscpy_pad()`.

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/linux#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-firmware-ti_sci-c-v1-1-740db471110d@google.com
Signed-off-by: Nishanth Menon <[email protected]>
  • Loading branch information
JustinStitt authored and nmenon committed Sep 20, 2023
1 parent be6d43e commit d8cce0d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion drivers/firmware/ti_sci.c
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ static int ti_sci_cmd_get_revision(struct ti_sci_info *info)
ver->abi_major = rev_info->abi_major;
ver->abi_minor = rev_info->abi_minor;
ver->firmware_revision = rev_info->firmware_revision;
strncpy(ver->firmware_description, rev_info->firmware_description,
strscpy(ver->firmware_description, rev_info->firmware_description,
sizeof(ver->firmware_description));

fail:
Expand Down

0 comments on commit d8cce0d

Please sign in to comment.