diff options
author | Justin Stitt <justinstitt@google.com> | 2023-10-09 17:45:33 +0000 |
---|---|---|
committer | Jakub Kicinski <kuba@kernel.org> | 2023-10-11 17:26:14 -0700 |
commit | 460c81da66f2258e504a547ea0e4facf5ed90903 (patch) | |
tree | 8d1a7e227084e0f003fdea9e8ab130fe7da247d9 /drivers/net/ethernet/brocade | |
parent | ed9417206de7d306d6f79340fbe4849d3bdfae4e (diff) | |
download | lwn-460c81da66f2258e504a547ea0e4facf5ed90903.tar.gz lwn-460c81da66f2258e504a547ea0e4facf5ed90903.zip |
bna: replace deprecated strncpy with strscpy_pad
`strncpy` is deprecated for use on NUL-terminated destination strings
[1] and as such we should prefer more robust and less ambiguous string
interfaces.
bfa_ioc_get_adapter_manufacturer() simply copies a string literal into
`manufacturer`.
Another implementation of bfa_ioc_get_adapter_manufacturer() from
drivers/scsi/bfa/bfa_ioc.c uses memset + strscpy:
| void
| bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)
| {
| memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
| strscpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
| }
Let's use `strscpy_pad` to eliminate some redundant work while still
NUL-terminating and NUL-padding the destination buffer.
Link: https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings [1]
Link: https://github.com/KSPP/linux/issues/90
Signed-off-by: Justin Stitt <justinstitt@google.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/20231009-strncpy-drivers-net-ethernet-brocade-bna-bfa_ioc-c-v2-1-78e0f47985d3@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'drivers/net/ethernet/brocade')
-rw-r--r-- | drivers/net/ethernet/brocade/bna/bfa_ioc.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/drivers/net/ethernet/brocade/bna/bfa_ioc.c b/drivers/net/ethernet/brocade/bna/bfa_ioc.c index b07522ac3e74..9c80ab07a735 100644 --- a/drivers/net/ethernet/brocade/bna/bfa_ioc.c +++ b/drivers/net/ethernet/brocade/bna/bfa_ioc.c @@ -2839,7 +2839,7 @@ bfa_ioc_get_adapter_optrom_ver(struct bfa_ioc *ioc, char *optrom_ver) static void bfa_ioc_get_adapter_manufacturer(struct bfa_ioc *ioc, char *manufacturer) { - strncpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN); + strscpy_pad(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN); } static void |