[PATCH net-next] net: fjes: use ethtool string helpers

Rosen Penev posted 1 patch 1 month ago
There is a newer version of this series
drivers/net/fjes/fjes_ethtool.c | 50 +++++++++++----------------------
1 file changed, 17 insertions(+), 33 deletions(-)
[PATCH net-next] net: fjes: 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/fjes/fjes_ethtool.c | 50 +++++++++++----------------------
 1 file changed, 17 insertions(+), 33 deletions(-)

diff --git a/drivers/net/fjes/fjes_ethtool.c b/drivers/net/fjes/fjes_ethtool.c
index 19c99529566b..1dc7754e0f1f 100644
--- a/drivers/net/fjes/fjes_ethtool.c
+++ b/drivers/net/fjes/fjes_ethtool.c
@@ -92,42 +92,26 @@ static void fjes_get_strings(struct net_device *netdev,
 
 	switch (stringset) {
 	case ETH_SS_STATS:
-		for (i = 0; i < ARRAY_SIZE(fjes_gstrings_stats); i++) {
-			memcpy(p, fjes_gstrings_stats[i].stat_string,
-			       ETH_GSTRING_LEN);
-			p += ETH_GSTRING_LEN;
-		}
+		for (i = 0; i < ARRAY_SIZE(fjes_gstrings_stats); i++)
+			ethtool_puts(&p, fjes_gstrings_stats[i].stat_string);
+
 		for (i = 0; i < hw->max_epid; i++) {
 			if (i == hw->my_epid)
 				continue;
-			sprintf(p, "ep%u_com_regist_buf_exec", i);
-			p += ETH_GSTRING_LEN;
-			sprintf(p, "ep%u_com_unregist_buf_exec", i);
-			p += ETH_GSTRING_LEN;
-			sprintf(p, "ep%u_send_intr_rx", i);
-			p += ETH_GSTRING_LEN;
-			sprintf(p, "ep%u_send_intr_unshare", i);
-			p += ETH_GSTRING_LEN;
-			sprintf(p, "ep%u_send_intr_zoneupdate", i);
-			p += ETH_GSTRING_LEN;
-			sprintf(p, "ep%u_recv_intr_rx", i);
-			p += ETH_GSTRING_LEN;
-			sprintf(p, "ep%u_recv_intr_unshare", i);
-			p += ETH_GSTRING_LEN;
-			sprintf(p, "ep%u_recv_intr_stop", i);
-			p += ETH_GSTRING_LEN;
-			sprintf(p, "ep%u_recv_intr_zoneupdate", i);
-			p += ETH_GSTRING_LEN;
-			sprintf(p, "ep%u_tx_buffer_full", i);
-			p += ETH_GSTRING_LEN;
-			sprintf(p, "ep%u_tx_dropped_not_shared", i);
-			p += ETH_GSTRING_LEN;
-			sprintf(p, "ep%u_tx_dropped_ver_mismatch", i);
-			p += ETH_GSTRING_LEN;
-			sprintf(p, "ep%u_tx_dropped_buf_size_mismatch", i);
-			p += ETH_GSTRING_LEN;
-			sprintf(p, "ep%u_tx_dropped_vlanid_mismatch", i);
-			p += ETH_GSTRING_LEN;
+			ethtool_sprintf(&p, "ep%u_com_regist_buf_exec", i);
+			ethtool_sprintf(&p, "ep%u_com_unregist_buf_exec", i);
+			ethtool_sprintf(&p, "ep%u_send_intr_rx", i);
+			ethtool_sprintf(&p, "ep%u_send_intr_unshare", i);
+			ethtool_sprintf(&p, "ep%u_send_intr_zoneupdate", i);
+			ethtool_sprintf(&p, "ep%u_recv_intr_rx", i);
+			ethtool_sprintf(&p, "ep%u_recv_intr_unshare", i);
+			ethtool_sprintf(&p, "ep%u_recv_intr_stop", i);
+			ethtool_sprintf(&p, "ep%u_recv_intr_zoneupdate", i);
+			ethtool_sprintf(&p, "ep%u_tx_buffer_full", i);
+			ethtool_sprintf(&p, "ep%u_tx_dropped_not_shared", i);
+			ethtool_sprintf(&p, "ep%u_tx_dropped_ver_mismatch", i);
+			ethtool_sprintf(&p, "ep%u_tx_dropped_buf_size_mismatch", i);
+			ethtool_sprintf(&p, "ep%u_tx_dropped_vlanid_mismatch", i);
 		}
 		break;
 	}
-- 
2.47.0
Re: [PATCH net-next] net: fjes: use ethtool string helpers
Posted by Jakub Kicinski 3 weeks, 5 days ago
On Tue, 22 Oct 2024 13:54:31 -0700 Rosen Penev wrote:
> -		for (i = 0; i < ARRAY_SIZE(fjes_gstrings_stats); i++) {
> -			memcpy(p, fjes_gstrings_stats[i].stat_string,
> -			       ETH_GSTRING_LEN);
> -			p += ETH_GSTRING_LEN;
> -		}
> +		for (i = 0; i < ARRAY_SIZE(fjes_gstrings_stats); i++)
> +			ethtool_puts(&p, fjes_gstrings_stats[i].stat_string);
> +
>  		for (i = 0; i < hw->max_epid; i++) {
>  			if (i == hw->my_epid)
>  				continue;
> -			sprintf(p, "ep%u_com_regist_buf_exec", i);
> -			p += ETH_GSTRING_LEN;

In some of the other patches you deleted the local variable called p
and operate on data directly. I think that's better. Plus you can
remove the indentation here and exit early if stringset != ETH_SS_STATS
-- 
pw-bot: cr
Re: [PATCH net-next] net: fjes: use ethtool string helpers
Posted by Simon Horman 1 month ago
On Tue, Oct 22, 2024 at 01:54:31PM -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>