Message ID | 20230718-net-dsa-strncpy-v2-1-3210463a08be@google.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 5c9f7b04aadf79f783542d096dfbb8184e7c91f5 |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | [v2] net: dsa: remove deprecated strncpy | expand |
Hello: This patch was applied to netdev/net-next.git (main) by David S. Miller <davem@davemloft.net>: On Tue, 18 Jul 2023 22:56:38 +0000 you wrote: > `strncpy` is deprecated for use on NUL-terminated destination strings [1]. > > Even call sites utilizing length-bounded destination buffers should > switch over to using `strtomem` or `strtomem_pad`. In this case, > however, the compiler is unable to determine the size of the `data` > buffer which renders `strtomem` unusable. Due to this, `strscpy` > should be used. > > [...] Here is the summary with links: - [v2] net: dsa: remove deprecated strncpy https://git.kernel.org/netdev/net-next/c/5c9f7b04aadf You are awesome, thank you!
diff --git a/net/dsa/slave.c b/net/dsa/slave.c index 527b1d576460..48db91b33390 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -21,6 +21,7 @@ #include <linux/if_hsr.h> #include <net/dcbnl.h> #include <linux/netpoll.h> +#include <linux/string.h> #include "dsa.h" #include "port.h" @@ -1056,10 +1057,10 @@ static void dsa_slave_get_strings(struct net_device *dev, if (stringset == ETH_SS_STATS) { int len = ETH_GSTRING_LEN; - strncpy(data, "tx_packets", len); - strncpy(data + len, "tx_bytes", len); - strncpy(data + 2 * len, "rx_packets", len); - strncpy(data + 3 * len, "rx_bytes", len); + strscpy_pad(data, "tx_packets", len); + strscpy_pad(data + len, "tx_bytes", len); + strscpy_pad(data + 2 * len, "rx_packets", len); + strscpy_pad(data + 3 * len, "rx_bytes", len); if (ds->ops->get_strings) ds->ops->get_strings(ds, dp->index, stringset, data + 4 * len);