mirror of
https://github.com/torvalds/linux
synced 2024-09-30 08:20:40 +00:00
net: dsa: lan9303: use ethtool_puts() for lan9303_get_strings()
This pattern of strncpy with some pointer arithmetic setting fixed-sized intervals with string literal data is a bit weird so let's use ethtool_puts() as this has more obvious behavior and is less-error prone. Nicely, we also get to drop a usage of the now deprecated strncpy() [1]. 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 Suggested-by: Alexander Lobakin <aleksander.lobakin@intel.com> Reviewed-by: Kees Cook <keescook@chromium.org> Signed-off-by: Justin Stitt <justinstitt@google.com> Link: https://lore.kernel.org/r/20240425-strncpy-drivers-net-dsa-lan9303-core-c-v4-1-9fafd419d7bb@google.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
parent
d5115a55ff
commit
8880e2666f
|
@ -1007,15 +1007,14 @@ static const struct lan9303_mib_desc lan9303_mib[] = {
|
||||||
static void lan9303_get_strings(struct dsa_switch *ds, int port,
|
static void lan9303_get_strings(struct dsa_switch *ds, int port,
|
||||||
u32 stringset, uint8_t *data)
|
u32 stringset, uint8_t *data)
|
||||||
{
|
{
|
||||||
|
u8 *buf = data;
|
||||||
unsigned int u;
|
unsigned int u;
|
||||||
|
|
||||||
if (stringset != ETH_SS_STATS)
|
if (stringset != ETH_SS_STATS)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (u = 0; u < ARRAY_SIZE(lan9303_mib); u++) {
|
for (u = 0; u < ARRAY_SIZE(lan9303_mib); u++)
|
||||||
strncpy(data + u * ETH_GSTRING_LEN, lan9303_mib[u].name,
|
ethtool_puts(&buf, lan9303_mib[u].name);
|
||||||
ETH_GSTRING_LEN);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void lan9303_get_ethtool_stats(struct dsa_switch *ds, int port,
|
static void lan9303_get_ethtool_stats(struct dsa_switch *ds, int port,
|
||||||
|
|
Loading…
Reference in a new issue