.../ethernet/microsoft/mana/mana_ethtool.c | 55 ++++++------------- 1 file changed, 18 insertions(+), 37 deletions(-)
The latter is the preferred way to copy ethtool strings.
Avoids manually incrementing the data pointer.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
.../ethernet/microsoft/mana/mana_ethtool.c | 55 ++++++-------------
1 file changed, 18 insertions(+), 37 deletions(-)
diff --git a/drivers/net/ethernet/microsoft/mana/mana_ethtool.c b/drivers/net/ethernet/microsoft/mana/mana_ethtool.c
index 349f11bf8e64..c419626073f5 100644
--- a/drivers/net/ethernet/microsoft/mana/mana_ethtool.c
+++ b/drivers/net/ethernet/microsoft/mana/mana_ethtool.c
@@ -91,53 +91,34 @@ static void mana_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
{
struct mana_port_context *apc = netdev_priv(ndev);
unsigned int num_queues = apc->num_queues;
- u8 *p = data;
int i;
if (stringset != ETH_SS_STATS)
return;
- for (i = 0; i < ARRAY_SIZE(mana_eth_stats); i++) {
- memcpy(p, mana_eth_stats[i].name, ETH_GSTRING_LEN);
- p += ETH_GSTRING_LEN;
- }
+ for (i = 0; i < ARRAY_SIZE(mana_eth_stats); i++)
+ ethtool_puts(&data, mana_eth_stats[i].name);
for (i = 0; i < num_queues; i++) {
- sprintf(p, "rx_%d_packets", i);
- p += ETH_GSTRING_LEN;
- sprintf(p, "rx_%d_bytes", i);
- p += ETH_GSTRING_LEN;
- sprintf(p, "rx_%d_xdp_drop", i);
- p += ETH_GSTRING_LEN;
- sprintf(p, "rx_%d_xdp_tx", i);
- p += ETH_GSTRING_LEN;
- sprintf(p, "rx_%d_xdp_redirect", i);
- p += ETH_GSTRING_LEN;
+ ethtool_sprintf(&data, "rx_%d_packets", i);
+ ethtool_sprintf(&data, "rx_%d_bytes", i);
+ ethtool_sprintf(&data, "rx_%d_xdp_drop", i);
+ ethtool_sprintf(&data, "rx_%d_xdp_tx", i);
+ ethtool_sprintf(&data, "rx_%d_xdp_redirect", i);
}
for (i = 0; i < num_queues; i++) {
- sprintf(p, "tx_%d_packets", i);
- p += ETH_GSTRING_LEN;
- sprintf(p, "tx_%d_bytes", i);
- p += ETH_GSTRING_LEN;
- sprintf(p, "tx_%d_xdp_xmit", i);
- p += ETH_GSTRING_LEN;
- sprintf(p, "tx_%d_tso_packets", i);
- p += ETH_GSTRING_LEN;
- sprintf(p, "tx_%d_tso_bytes", i);
- p += ETH_GSTRING_LEN;
- sprintf(p, "tx_%d_tso_inner_packets", i);
- p += ETH_GSTRING_LEN;
- sprintf(p, "tx_%d_tso_inner_bytes", i);
- p += ETH_GSTRING_LEN;
- sprintf(p, "tx_%d_long_pkt_fmt", i);
- p += ETH_GSTRING_LEN;
- sprintf(p, "tx_%d_short_pkt_fmt", i);
- p += ETH_GSTRING_LEN;
- sprintf(p, "tx_%d_csum_partial", i);
- p += ETH_GSTRING_LEN;
- sprintf(p, "tx_%d_mana_map_err", i);
- p += ETH_GSTRING_LEN;
+ ethtool_sprintf(&data, "tx_%d_packets", i);
+ ethtool_sprintf(&data, "tx_%d_bytes", i);
+ ethtool_sprintf(&data, "tx_%d_xdp_xmit", i);
+ ethtool_sprintf(&data, "tx_%d_tso_packets", i);
+ ethtool_sprintf(&data, "tx_%d_tso_bytes", i);
+ ethtool_sprintf(&data, "tx_%d_tso_inner_packets", i);
+ ethtool_sprintf(&data, "tx_%d_tso_inner_bytes", i);
+ ethtool_sprintf(&data, "tx_%d_long_pkt_fmt", i);
+ ethtool_sprintf(&data, "tx_%d_short_pkt_fmt", i);
+ ethtool_sprintf(&data, "tx_%d_csum_partial", i);
+ ethtool_sprintf(&data, "tx_%d_mana_map_err", i);
}
}
--
2.47.0
On Tue, Oct 22, 2024 at 01:49:08PM -0700, Rosen Penev wrote: > The latter is the preferred way to copy ethtool strings. > > Avoids manually incrementing the data pointer. > > Signed-off-by: Rosen Penev <rosenp@gmail.com> > --- > .../ethernet/microsoft/mana/mana_ethtool.c | 55 ++++++------------- > 1 file changed, 18 insertions(+), 37 deletions(-) > > diff --git a/drivers/net/ethernet/microsoft/mana/mana_ethtool.c b/drivers/net/ethernet/microsoft/mana/mana_ethtool.c > index 349f11bf8e64..c419626073f5 100644 > --- a/drivers/net/ethernet/microsoft/mana/mana_ethtool.c > +++ b/drivers/net/ethernet/microsoft/mana/mana_ethtool.c > @@ -91,53 +91,34 @@ static void mana_get_strings(struct net_device *ndev, u32 stringset, u8 *data) > { > struct mana_port_context *apc = netdev_priv(ndev); > unsigned int num_queues = apc->num_queues; > - u8 *p = data; > int i; > > if (stringset != ETH_SS_STATS) > return; > > - for (i = 0; i < ARRAY_SIZE(mana_eth_stats); i++) { > - memcpy(p, mana_eth_stats[i].name, ETH_GSTRING_LEN); > - p += ETH_GSTRING_LEN; > - } > + for (i = 0; i < ARRAY_SIZE(mana_eth_stats); i++) > + ethtool_puts(&data, mana_eth_stats[i].name); > > for (i = 0; i < num_queues; i++) { > - sprintf(p, "rx_%d_packets", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "rx_%d_bytes", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "rx_%d_xdp_drop", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "rx_%d_xdp_tx", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "rx_%d_xdp_redirect", i); > - p += ETH_GSTRING_LEN; > + ethtool_sprintf(&data, "rx_%d_packets", i); > + ethtool_sprintf(&data, "rx_%d_bytes", i); > + ethtool_sprintf(&data, "rx_%d_xdp_drop", i); > + ethtool_sprintf(&data, "rx_%d_xdp_tx", i); > + ethtool_sprintf(&data, "rx_%d_xdp_redirect", i); > } > > for (i = 0; i < num_queues; i++) { > - sprintf(p, "tx_%d_packets", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "tx_%d_bytes", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "tx_%d_xdp_xmit", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "tx_%d_tso_packets", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "tx_%d_tso_bytes", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "tx_%d_tso_inner_packets", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "tx_%d_tso_inner_bytes", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "tx_%d_long_pkt_fmt", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "tx_%d_short_pkt_fmt", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "tx_%d_csum_partial", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "tx_%d_mana_map_err", i); > - p += ETH_GSTRING_LEN; > + ethtool_sprintf(&data, "tx_%d_packets", i); > + ethtool_sprintf(&data, "tx_%d_bytes", i); > + ethtool_sprintf(&data, "tx_%d_xdp_xmit", i); > + ethtool_sprintf(&data, "tx_%d_tso_packets", i); > + ethtool_sprintf(&data, "tx_%d_tso_bytes", i); > + ethtool_sprintf(&data, "tx_%d_tso_inner_packets", i); > + ethtool_sprintf(&data, "tx_%d_tso_inner_bytes", i); > + ethtool_sprintf(&data, "tx_%d_long_pkt_fmt", i); > + ethtool_sprintf(&data, "tx_%d_short_pkt_fmt", i); > + ethtool_sprintf(&data, "tx_%d_csum_partial", i); > + ethtool_sprintf(&data, "tx_%d_mana_map_err", i); > } > } Reviewed-by: Shradha Gupta <shradhagupta@linux.microsoft.com> > > -- > 2.47.0
On Tue, Oct 22, 2024 at 01:49:08PM -0700, Rosen Penev wrote: > The latter is the preferred way to copy ethtool strings. > > Avoids manually incrementing the data pointer. > > Signed-off-by: Rosen Penev <rosenp@gmail.com> Reviewed-by: Simon Horman <horms@kernel.org>
On Tue, Oct 22, 2024 at 1:49 PM Rosen Penev <rosenp@gmail.com> wrote: > > The latter is the preferred way to copy ethtool strings. > > Avoids manually incrementing the data pointer. > > Signed-off-by: Rosen Penev <rosenp@gmail.com> forgot to put net-next. > --- > .../ethernet/microsoft/mana/mana_ethtool.c | 55 ++++++------------- > 1 file changed, 18 insertions(+), 37 deletions(-) > > diff --git a/drivers/net/ethernet/microsoft/mana/mana_ethtool.c b/drivers/net/ethernet/microsoft/mana/mana_ethtool.c > index 349f11bf8e64..c419626073f5 100644 > --- a/drivers/net/ethernet/microsoft/mana/mana_ethtool.c > +++ b/drivers/net/ethernet/microsoft/mana/mana_ethtool.c > @@ -91,53 +91,34 @@ static void mana_get_strings(struct net_device *ndev, u32 stringset, u8 *data) > { > struct mana_port_context *apc = netdev_priv(ndev); > unsigned int num_queues = apc->num_queues; > - u8 *p = data; > int i; > > if (stringset != ETH_SS_STATS) > return; > > - for (i = 0; i < ARRAY_SIZE(mana_eth_stats); i++) { > - memcpy(p, mana_eth_stats[i].name, ETH_GSTRING_LEN); > - p += ETH_GSTRING_LEN; > - } > + for (i = 0; i < ARRAY_SIZE(mana_eth_stats); i++) > + ethtool_puts(&data, mana_eth_stats[i].name); > > for (i = 0; i < num_queues; i++) { > - sprintf(p, "rx_%d_packets", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "rx_%d_bytes", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "rx_%d_xdp_drop", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "rx_%d_xdp_tx", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "rx_%d_xdp_redirect", i); > - p += ETH_GSTRING_LEN; > + ethtool_sprintf(&data, "rx_%d_packets", i); > + ethtool_sprintf(&data, "rx_%d_bytes", i); > + ethtool_sprintf(&data, "rx_%d_xdp_drop", i); > + ethtool_sprintf(&data, "rx_%d_xdp_tx", i); > + ethtool_sprintf(&data, "rx_%d_xdp_redirect", i); > } > > for (i = 0; i < num_queues; i++) { > - sprintf(p, "tx_%d_packets", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "tx_%d_bytes", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "tx_%d_xdp_xmit", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "tx_%d_tso_packets", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "tx_%d_tso_bytes", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "tx_%d_tso_inner_packets", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "tx_%d_tso_inner_bytes", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "tx_%d_long_pkt_fmt", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "tx_%d_short_pkt_fmt", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "tx_%d_csum_partial", i); > - p += ETH_GSTRING_LEN; > - sprintf(p, "tx_%d_mana_map_err", i); > - p += ETH_GSTRING_LEN; > + ethtool_sprintf(&data, "tx_%d_packets", i); > + ethtool_sprintf(&data, "tx_%d_bytes", i); > + ethtool_sprintf(&data, "tx_%d_xdp_xmit", i); > + ethtool_sprintf(&data, "tx_%d_tso_packets", i); > + ethtool_sprintf(&data, "tx_%d_tso_bytes", i); > + ethtool_sprintf(&data, "tx_%d_tso_inner_packets", i); > + ethtool_sprintf(&data, "tx_%d_tso_inner_bytes", i); > + ethtool_sprintf(&data, "tx_%d_long_pkt_fmt", i); > + ethtool_sprintf(&data, "tx_%d_short_pkt_fmt", i); > + ethtool_sprintf(&data, "tx_%d_csum_partial", i); > + ethtool_sprintf(&data, "tx_%d_mana_map_err", i); > } > } > > -- > 2.47.0 >
On Tue, Oct 22, 2024 at 01:56:56PM -0700, Rosen Penev wrote: > On Tue, Oct 22, 2024 at 1:49 PM Rosen Penev <rosenp@gmail.com> wrote: > > > > The latter is the preferred way to copy ethtool strings. > > > > Avoids manually incrementing the data pointer. > > > > Signed-off-by: Rosen Penev <rosenp@gmail.com> > forgot to put net-next. Hi Rosen, The CI guessed correctly, so I don't think you need to repost just for that. ...
© 2016 - 2024 Red Hat, Inc.