Skip to content

Commit

Permalink
net: sparx5: replace deprecated strncpy with ethtool_sprintf
Browse files Browse the repository at this point in the history
strncpy() is deprecated for use on NUL-terminated destination strings
[1] and as such we should prefer more robust and less ambiguous string
interfaces.

ethtool_sprintf() is designed specifically for get_strings() usage.
Let's replace strncpy() in favor of this more robust and easier to
understand interface.

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: 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/20231011-strncpy-drivers-net-ethernet-microchip-sparx5-sparx5_ethtool-c-v1-1-410953d07f42@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Justin Stitt authored and Jakub Kicinski committed Oct 14, 2023
1 parent 88fca39 commit e343023
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -1012,8 +1012,7 @@ static void sparx5_get_sset_strings(struct net_device *ndev, u32 sset, u8 *data)
return;

for (idx = 0; idx < sparx5->num_ethtool_stats; idx++)
strncpy(data + idx * ETH_GSTRING_LEN,
sparx5->stats_layout[idx], ETH_GSTRING_LEN);
ethtool_sprintf(&data, "%s", sparx5->stats_layout[idx]);
}

static void sparx5_get_sset_data(struct net_device *ndev,
Expand Down

0 comments on commit e343023

Please sign in to comment.