[PATCH net-next] amd-xgbe: use ethtool string helpers

Rosen Penev posted 1 patch 1 month ago
drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c | 22 ++++++++------------
1 file changed, 9 insertions(+), 13 deletions(-)
[PATCH net-next] amd-xgbe: use ethtool string helpers
Posted by Rosen Penev 1 month ago
The latter is the preferred way to copy ethtool strings.

Avoids manually incrementing the pointer.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c | 22 ++++++++------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
index 5fc94c2f638e..4431ab1c18b3 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
@@ -195,23 +195,19 @@ static void xgbe_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
 
 	switch (stringset) {
 	case ETH_SS_STATS:
-		for (i = 0; i < XGBE_STATS_COUNT; i++) {
-			memcpy(data, xgbe_gstring_stats[i].stat_string,
-			       ETH_GSTRING_LEN);
-			data += ETH_GSTRING_LEN;
-		}
+		for (i = 0; i < XGBE_STATS_COUNT; i++)
+			ethtool_puts(&data, xgbe_gstring_stats[i].stat_string);
+
 		for (i = 0; i < pdata->tx_ring_count; i++) {
-			sprintf(data, "txq_%u_packets", i);
-			data += ETH_GSTRING_LEN;
-			sprintf(data, "txq_%u_bytes", i);
-			data += ETH_GSTRING_LEN;
+			ethtool_sprintf(&data, "txq_%u_packets", i);
+			ethtool_sprintf(&data, "txq_%u_bytes", i);
 		}
+
 		for (i = 0; i < pdata->rx_ring_count; i++) {
-			sprintf(data, "rxq_%u_packets", i);
-			data += ETH_GSTRING_LEN;
-			sprintf(data, "rxq_%u_bytes", i);
-			data += ETH_GSTRING_LEN;
+			ethtool_sprintf(&data, "rxq_%u_packets", i);
+			ethtool_sprintf(&data, "rxq_%u_bytes", i);
 		}
+
 		break;
 	}
 }
-- 
2.47.0
Re: [PATCH net-next] amd-xgbe: use ethtool string helpers
Posted by Simon Horman 1 month ago
On Tue, Oct 22, 2024 at 04:32:03PM -0700, Rosen Penev wrote:
> The latter is the preferred way to copy ethtool strings.
> 
> Avoids manually incrementing the pointer.
> 
> Signed-off-by: Rosen Penev <rosenp@gmail.com>

Reviewed-by: Simon Horman <horms@kernel.org>
Re: [PATCH net-next] amd-xgbe: use ethtool string helpers
Posted by Shyam Sundar S K 1 month ago

On 10/23/2024 05:02, Rosen Penev wrote:
> The latter is the preferred way to copy ethtool strings.
> 
> Avoids manually incrementing the pointer.
> 
> Signed-off-by: Rosen Penev <rosenp@gmail.com>

Looks good to me.

Acked-by: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>

Thanks,
Shyam

> ---
>  drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c | 22 ++++++++------------
>  1 file changed, 9 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
> index 5fc94c2f638e..4431ab1c18b3 100644
> --- a/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
> +++ b/drivers/net/ethernet/amd/xgbe/xgbe-ethtool.c
> @@ -195,23 +195,19 @@ static void xgbe_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
>  
>  	switch (stringset) {
>  	case ETH_SS_STATS:
> -		for (i = 0; i < XGBE_STATS_COUNT; i++) {
> -			memcpy(data, xgbe_gstring_stats[i].stat_string,
> -			       ETH_GSTRING_LEN);
> -			data += ETH_GSTRING_LEN;
> -		}
> +		for (i = 0; i < XGBE_STATS_COUNT; i++)
> +			ethtool_puts(&data, xgbe_gstring_stats[i].stat_string);
> +
>  		for (i = 0; i < pdata->tx_ring_count; i++) {
> -			sprintf(data, "txq_%u_packets", i);
> -			data += ETH_GSTRING_LEN;
> -			sprintf(data, "txq_%u_bytes", i);
> -			data += ETH_GSTRING_LEN;
> +			ethtool_sprintf(&data, "txq_%u_packets", i);
> +			ethtool_sprintf(&data, "txq_%u_bytes", i);
>  		}
> +
>  		for (i = 0; i < pdata->rx_ring_count; i++) {
> -			sprintf(data, "rxq_%u_packets", i);
> -			data += ETH_GSTRING_LEN;
> -			sprintf(data, "rxq_%u_bytes", i);
> -			data += ETH_GSTRING_LEN;
> +			ethtool_sprintf(&data, "rxq_%u_packets", i);
> +			ethtool_sprintf(&data, "rxq_%u_bytes", i);
>  		}
> +
>  		break;
>  	}
>  }