Skip to contentSkip to conversation

net: intel: use ethtool string helpers

PATCH Superseded Rosen Penev 2 participants 5 messages Oct 25, 2024 – Oct 31, 2024

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: intel: use ethtool string helpers

The latter is the preferred way to copy ethtool strings.

Avoids manually incrementing the pointer. Cleans up the code quite well.

---
v2: add iwl-next tag. use inline int in for loops.

 .../net/ethernet/intel/e1000/e1000_ethtool.c  | 10 ++---
 drivers/net/ethernet/intel/e1000e/ethtool.c   | 14 +++----
 .../net/ethernet/intel/fm10k/fm10k_ethtool.c  | 10 ++---
 .../net/ethernet/intel/i40e/i40e_ethtool.c    |  6 +--
 drivers/net/ethernet/intel/ice/ice_ethtool.c  | 37 +++++++++++--------
 drivers/net/ethernet/intel/igb/igb_ethtool.c  | 35 ++++++++++--------
 drivers/net/ethernet/intel/igbvf/ethtool.c    | 10 ++---
 drivers/net/ethernet/intel/igc/igc_ethtool.c  | 36 +++++++++---------
 .../net/ethernet/intel/ixgbe/ixgbe_ethtool.c  | 32 ++++++++--------
 drivers/net/ethernet/intel/ixgbevf/ethtool.c  | 36 +++++++-----------
 10 files changed, 115 insertions(+), 111 deletions(-)
drivers/net/ethernet/intel/e1000/e1000_ethtool.c +5 -5
index d06d29c6c037..33222fadb3b9 100644
@@ -1839,18 +1839,18 @@ static void e1000_get_ethtool_stats(struct net_device *netdev,
 static void e1000_get_strings(struct net_device *netdev, u32 stringset,
 			      u8 *data)
 {
-	u8 *p = data;
+	const char *str;
 	int i;
 
 	switch (stringset) {
 	case ETH_SS_TEST:
-		memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
+		for (i = 0; i < E1000_TEST_LEN; i++)
+			ethtool_puts(&data, e1000_gstrings_test[i]);
 		break;
 	case ETH_SS_STATS:
 		for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
-			memcpy(p, e1000_gstrings_stats[i].stat_string,
-			       ETH_GSTRING_LEN);
-			p += ETH_GSTRING_LEN;
+			str = e1000_gstrings_stats[i].stat_string;
+			ethtool_puts(&data, str);
 		}
 		/* BUG_ON(p - data != E1000_STATS_LEN * ETH_GSTRING_LEN); */
 		break;
drivers/net/ethernet/intel/e1000e/ethtool.c +7 -7
index 9364bc2b4eb1..ab590b69c14f 100644
@@ -2075,23 +2075,23 @@ static void e1000_get_ethtool_stats(struct net_device *netdev,
 static void e1000_get_strings(struct net_device __always_unused *netdev,
 			      u32 stringset, u8 *data)
 {
-	u8 *p = data;
+	const char *str;
 	int i;
 
 	switch (stringset) {
 	case ETH_SS_TEST:
-		memcpy(data, e1000_gstrings_test, sizeof(e1000_gstrings_test));
+		for (i = 0; i < E1000_TEST_LEN; i++)
+			ethtool_puts(&data, e1000_gstrings_test[i]);
 		break;
 	case ETH_SS_STATS:
 		for (i = 0; i < E1000_GLOBAL_STATS_LEN; i++) {
-			memcpy(p, e1000_gstrings_stats[i].stat_string,
-			       ETH_GSTRING_LEN);
-			p += ETH_GSTRING_LEN;
+			str = e1000_gstrings_stats[i].stat_string;
+			ethtool_puts(&data, str);
 		}
 		break;
 	case ETH_SS_PRIV_FLAGS:
-		memcpy(data, e1000e_priv_flags_strings,
-		       E1000E_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN);
+		for (i = 0; i < E1000E_PRIV_FLAGS_STR_LEN; i++)
+			ethtool_puts(&data, e1000e_priv_flags_strings[i]);
 		break;
 	}
 }
drivers/net/ethernet/intel/fm10k/fm10k_ethtool.c +5 -5
index 1bc5b6c0b897..fb03bb30154a 100644
@@ -122,7 +122,7 @@ static const char fm10k_gstrings_test[][ETH_GSTRING_LEN] = {
 	"Mailbox test (on/offline)"
 };
 
-#define FM10K_TEST_LEN (sizeof(fm10k_gstrings_test) / ETH_GSTRING_LEN)
+#define FM10K_TEST_LEN ARRAY_SIZE(fm10k_gstrings_test)
 
 enum fm10k_self_test_types {
 	FM10K_TEST_MBX,
@@ -182,15 +182,15 @@ static void fm10k_get_strings(struct net_device *dev,
 {
 	switch (stringset) {
 	case ETH_SS_TEST:
-		memcpy(data, fm10k_gstrings_test,
-		       FM10K_TEST_LEN * ETH_GSTRING_LEN);
+		for (int i = 0; i < FM10K_TEST_LEN; i++)
+			ethtool_puts(&data, fm10k_gstrings_test[i]);
 		break;
 	case ETH_SS_STATS:
 		fm10k_get_stat_strings(dev, data);
 		break;
 	case ETH_SS_PRIV_FLAGS:
-		memcpy(data, fm10k_prv_flags,
-		       FM10K_PRV_FLAG_LEN * ETH_GSTRING_LEN);
+		for (int i = 0; i < FM10K_PRV_FLAG_LEN; i++)
+			ethtool_puts(&data, fm10k_prv_flags[i]);
 		break;
 	}
 }
drivers/net/ethernet/intel/i40e/i40e_ethtool.c +3 -3
index f2506511bbff..90fc0c29fbd6 100644
@@ -426,7 +426,7 @@ static const char i40e_gstrings_test[][ETH_GSTRING_LEN] = {
 	"Link test   (on/offline)"
 };
 
-#define I40E_TEST_LEN (sizeof(i40e_gstrings_test) / ETH_GSTRING_LEN)
+#define I40E_TEST_LEN ARRAY_SIZE(i40e_gstrings_test)
 
 struct i40e_priv_flags {
 	char flag_string[ETH_GSTRING_LEN];
@@ -2531,8 +2531,8 @@ static void i40e_get_strings(struct net_device *netdev, u32 stringset,
 {
 	switch (stringset) {
 	case ETH_SS_TEST:
-		memcpy(data, i40e_gstrings_test,
-		       I40E_TEST_LEN * ETH_GSTRING_LEN);
+		for (int i = 0; i < I40E_TEST_LEN; i++)
+			ethtool_puts(&data, i40e_gstrings_test[i]);
 		break;
 	case ETH_SS_STATS:
 		i40e_get_stat_strings(netdev, data);
drivers/net/ethernet/intel/ice/ice_ethtool.c +21 -16
index 2924ac61300d..62a152be8180 100644
@@ -83,7 +83,7 @@ static const char ice_gstrings_test[][ETH_GSTRING_LEN] = {
 	"Link test   (on/offline)",
 };
 
-#define ICE_TEST_LEN (sizeof(ice_gstrings_test) / ETH_GSTRING_LEN)
+#define ICE_TEST_LEN ARRAY_SIZE(ice_gstrings_test)
 
 /* These PF_STATs might look like duplicates of some NETDEV_STATs,
  * but they aren't. This device is capable of supporting multiple
@@ -1481,48 +1481,53 @@ static void
 __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,
 		  struct ice_vsi *vsi)
 {
+	const char *str;
 	unsigned int i;
-	u8 *p = data;
 
 	switch (stringset) {
 	case ETH_SS_STATS:
-		for (i = 0; i < ICE_VSI_STATS_LEN; i++)
-			ethtool_puts(&p, ice_gstrings_vsi_stats[i].stat_string);
+		for (i = 0; i < ICE_VSI_STATS_LEN; i++) {
+			str = ice_gstrings_vsi_stats[i].stat_string;
+			ethtool_puts(&data, str);
+		}
 
 		if (ice_is_port_repr_netdev(netdev))
 			return;
 
 		ice_for_each_alloc_txq(vsi, i) {
-			ethtool_sprintf(&p, "tx_queue_%u_packets", i);
-			ethtool_sprintf(&p, "tx_queue_%u_bytes", i);
+			ethtool_sprintf(&data, "tx_queue_%u_packets", i);
+			ethtool_sprintf(&data, "tx_queue_%u_bytes", i);
 		}
 
 		ice_for_each_alloc_rxq(vsi, i) {
-			ethtool_sprintf(&p, "rx_queue_%u_packets", i);
-			ethtool_sprintf(&p, "rx_queue_%u_bytes", i);
+			ethtool_sprintf(&data, "rx_queue_%u_packets", i);
+			ethtool_sprintf(&data, "rx_queue_%u_bytes", i);
 		}
 
 		if (vsi->type != ICE_VSI_PF)
 			return;
 
-		for (i = 0; i < ICE_PF_STATS_LEN; i++)
-			ethtool_puts(&p, ice_gstrings_pf_stats[i].stat_string);
+		for (i = 0; i < ICE_PF_STATS_LEN; i++) {
+			str = ice_gstrings_pf_stats[i].stat_string;
+			ethtool_puts(&data, str);
+		}
 
 		for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
-			ethtool_sprintf(&p, "tx_priority_%u_xon.nic", i);
-			ethtool_sprintf(&p, "tx_priority_%u_xoff.nic", i);
+			ethtool_sprintf(&data, "tx_priority_%u_xon.nic", i);
+			ethtool_sprintf(&data, "tx_priority_%u_xoff.nic", i);
 		}
 		for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
-			ethtool_sprintf(&p, "rx_priority_%u_xon.nic", i);
-			ethtool_sprintf(&p, "rx_priority_%u_xoff.nic", i);
+			ethtool_sprintf(&data, "rx_priority_%u_xon.nic", i);
+			ethtool_sprintf(&data, "rx_priority_%u_xoff.nic", i);
 		}
 		break;
 	case ETH_SS_TEST:
-		memcpy(data, ice_gstrings_test, ICE_TEST_LEN * ETH_GSTRING_LEN);
+		for (i = 0; i < ICE_TEST_LEN; i++)
+			ethtool_puts(&data, ice_gstrings_test[i]);
 		break;
 	case ETH_SS_PRIV_FLAGS:
 		for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++)
-			ethtool_puts(&p, ice_gstrings_priv_flags[i].name);
+			ethtool_puts(&data, ice_gstrings_priv_flags[i].name);
 		break;
 	default:
 		break;
drivers/net/ethernet/intel/igb/igb_ethtool.c +19 -16
index ca6ccbc13954..c4a8712389af 100644
@@ -123,7 +123,7 @@ static const char igb_gstrings_test[][ETH_GSTRING_LEN] = {
 	[TEST_LOOP] = "Loopback test  (offline)",
 	[TEST_LINK] = "Link test   (on/offline)"
 };
-#define IGB_TEST_LEN (sizeof(igb_gstrings_test) / ETH_GSTRING_LEN)
+#define IGB_TEST_LEN ARRAY_SIZE(igb_gstrings_test)
 
 static const char igb_priv_flags_strings[][ETH_GSTRING_LEN] = {
 #define IGB_PRIV_FLAGS_LEGACY_RX	BIT(0)
@@ -2347,35 +2347,38 @@ static void igb_get_ethtool_stats(struct net_device *netdev,
 static void igb_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
 {
 	struct igb_adapter *adapter = netdev_priv(netdev);
-	u8 *p = data;
+	const char *str;
 	int i;
 
 	switch (stringset) {
 	case ETH_SS_TEST:
-		memcpy(data, igb_gstrings_test, sizeof(igb_gstrings_test));
+		for (i = 0; i < IGB_TEST_LEN; i++)
+			ethtool_puts(&data, igb_gstrings_test[i]);
 		break;
 	case ETH_SS_STATS:
 		for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++)
-			ethtool_puts(&p, igb_gstrings_stats[i].stat_string);
-		for (i = 0; i < IGB_NETDEV_STATS_LEN; i++)
-			ethtool_puts(&p, igb_gstrings_net_stats[i].stat_string);
+			ethtool_puts(&data, igb_gstrings_stats[i].stat_string);
+		for (i = 0; i < IGB_NETDEV_STATS_LEN; i++) {
+			str = igb_gstrings_net_stats[i].stat_string;
+			ethtool_puts(&data, str);
+		}
 		for (i = 0; i < adapter->num_tx_queues; i++) {
-			ethtool_sprintf(&p, "tx_queue_%u_packets", i);
-			ethtool_sprintf(&p, "tx_queue_%u_bytes", i);
-			ethtool_sprintf(&p, "tx_queue_%u_restart", i);
+			ethtool_sprintf(&data, "tx_queue_%u_packets", i);
+			ethtool_sprintf(&data, "tx_queue_%u_bytes", i);
+			ethtool_sprintf(&data, "tx_queue_%u_restart", i);
 		}
 		for (i = 0; i < adapter->num_rx_queues; i++) {
-			ethtool_sprintf(&p, "rx_queue_%u_packets", i);
-			ethtool_sprintf(&p, "rx_queue_%u_bytes", i);
-			ethtool_sprintf(&p, "rx_queue_%u_drops", i);
-			ethtool_sprintf(&p, "rx_queue_%u_csum_err", i);
-			ethtool_sprintf(&p, "rx_queue_%u_alloc_failed", i);
+			ethtool_sprintf(&data, "rx_queue_%u_packets", i);
+			ethtool_sprintf(&data, "rx_queue_%u_bytes", i);
+			ethtool_sprintf(&data, "rx_queue_%u_drops", i);
+			ethtool_sprintf(&data, "rx_queue_%u_csum_err", i);
+			ethtool_sprintf(&data, "rx_queue_%u_alloc_failed", i);
 		}
 		/* BUG_ON(p - data != IGB_STATS_LEN * ETH_GSTRING_LEN); */
 		break;
 	case ETH_SS_PRIV_FLAGS:
-		memcpy(data, igb_priv_flags_strings,
-		       IGB_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN);
+		for (i = 0; i < IGB_PRIV_FLAGS_STR_LEN; i++)
+			ethtool_puts(&data, igb_priv_flags_strings[i]);
 		break;
 	}
 }
drivers/net/ethernet/intel/igbvf/ethtool.c +5 -5
index 83b97989a6bd..2da95ea66718 100644
@@ -412,18 +412,18 @@ static int igbvf_get_sset_count(struct net_device *dev, int stringset)
 static void igbvf_get_strings(struct net_device *netdev, u32 stringset,
 			      u8 *data)
 {
-	u8 *p = data;
+	const char *str;
 	int i;
 
 	switch (stringset) {
 	case ETH_SS_TEST:
-		memcpy(data, *igbvf_gstrings_test, sizeof(igbvf_gstrings_test));
+		for (i = 0; i < IGBVF_TEST_LEN; i++)
+			ethtool_puts(&data, igbvf_gstrings_test[i]);
 		break;
 	case ETH_SS_STATS:
 		for (i = 0; i < IGBVF_GLOBAL_STATS_LEN; i++) {
-			memcpy(p, igbvf_gstrings_stats[i].stat_string,
-			       ETH_GSTRING_LEN);
-			p += ETH_GSTRING_LEN;
+			str = igbvf_gstrings_stats[i].stat_string;
+			ethtool_puts(&data, str);
 		}
 		break;
 	}
drivers/net/ethernet/intel/igc/igc_ethtool.c +19 -17
index 5b0c6f433767..7b118fb7097b 100644
@@ -104,7 +104,7 @@ static const char igc_gstrings_test[][ETH_GSTRING_LEN] = {
 	[TEST_LINK] = "Link test   (on/offline)"
 };
 
-#define IGC_TEST_LEN (sizeof(igc_gstrings_test) / ETH_GSTRING_LEN)
+#define IGC_TEST_LEN ARRAY_SIZE(igc_gstrings_test)
 
 #define IGC_GLOBAL_STATS_LEN	\
 	(sizeof(igc_gstrings_stats) / sizeof(struct igc_stats))
@@ -763,36 +763,38 @@ static void igc_ethtool_get_strings(struct net_device *netdev, u32 stringset,
 				    u8 *data)
 {
 	struct igc_adapter *adapter = netdev_priv(netdev);
-	u8 *p = data;
+	const char *str;
 	int i;
 
 	switch (stringset) {
 	case ETH_SS_TEST:
-		memcpy(data, *igc_gstrings_test,
-		       IGC_TEST_LEN * ETH_GSTRING_LEN);
+		for (i = 0; i < IGC_TEST_LEN; i++)
+			ethtool_puts(&data, igc_gstrings_test[i]);
 		break;
 	case ETH_SS_STATS:
 		for (i = 0; i < IGC_GLOBAL_STATS_LEN; i++)
-			ethtool_puts(&p, igc_gstrings_stats[i].stat_string);
-		for (i = 0; i < IGC_NETDEV_STATS_LEN; i++)
-			ethtool_puts(&p, igc_gstrings_net_stats[i].stat_string);
+			ethtool_puts(&data, igc_gstrings_stats[i].stat_string);
+		for (i = 0; i < IGC_NETDEV_STATS_LEN; i++) {
+			str = igc_gstrings_net_stats[i].stat_string;
+			ethtool_puts(&data, str);
+		}
 		for (i = 0; i < adapter->num_tx_queues; i++) {
-			ethtool_sprintf(&p, "tx_queue_%u_packets", i);
-			ethtool_sprintf(&p, "tx_queue_%u_bytes", i);
-			ethtool_sprintf(&p, "tx_queue_%u_restart", i);
+			ethtool_sprintf(&data, "tx_queue_%u_packets", i);
+			ethtool_sprintf(&data, "tx_queue_%u_bytes", i);
+			ethtool_sprintf(&data, "tx_queue_%u_restart", i);
 		}
 		for (i = 0; i < adapter->num_rx_queues; i++) {
-			ethtool_sprintf(&p, "rx_queue_%u_packets", i);
-			ethtool_sprintf(&p, "rx_queue_%u_bytes", i);
-			ethtool_sprintf(&p, "rx_queue_%u_drops", i);
-			ethtool_sprintf(&p, "rx_queue_%u_csum_err", i);
-			ethtool_sprintf(&p, "rx_queue_%u_alloc_failed", i);
+			ethtool_sprintf(&data, "rx_queue_%u_packets", i);
+			ethtool_sprintf(&data, "rx_queue_%u_bytes", i);
+			ethtool_sprintf(&data, "rx_queue_%u_drops", i);
+			ethtool_sprintf(&data, "rx_queue_%u_csum_err", i);
+			ethtool_sprintf(&data, "rx_queue_%u_alloc_failed", i);
 		}
 		/* BUG_ON(p - data != IGC_STATS_LEN * ETH_GSTRING_LEN); */
 		break;
 	case ETH_SS_PRIV_FLAGS:
-		memcpy(data, igc_priv_flags_strings,
-		       IGC_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN);
+		for (i = 0; i < IGC_PRIV_FLAGS_STR_LEN; i++)
+			ethtool_puts(&data, igc_priv_flags_strings[i]);
 		break;
 	}
 }
drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c +17 -15
index 9482e0cca8b7..b3b2e38c2ae6 100644
@@ -129,7 +129,7 @@ static const char ixgbe_gstrings_test[][ETH_GSTRING_LEN] = {
 	"Interrupt test (offline)", "Loopback test  (offline)",
 	"Link test   (on/offline)"
 };
-#define IXGBE_TEST_LEN sizeof(ixgbe_gstrings_test) / ETH_GSTRING_LEN
+#define IXGBE_TEST_LEN ARRAY_SIZE(ixgbe_gstrings_test)
 
 static const char ixgbe_priv_flags_strings[][ETH_GSTRING_LEN] = {
 #define IXGBE_PRIV_FLAGS_LEGACY_RX	BIT(0)
@@ -1409,38 +1409,40 @@ static void ixgbe_get_ethtool_stats(struct net_device *netdev,
 static void ixgbe_get_strings(struct net_device *netdev, u32 stringset,
 			      u8 *data)
 {
+	const char *str;
 	unsigned int i;
-	u8 *p = data;
 
 	switch (stringset) {
 	case ETH_SS_TEST:
 		for (i = 0; i < IXGBE_TEST_LEN; i++)
-			ethtool_puts(&p, ixgbe_gstrings_test[i]);
+			ethtool_puts(&data, ixgbe_gstrings_test[i]);
 		break;
 	case ETH_SS_STATS:
-		for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++)
-			ethtool_puts(&p, ixgbe_gstrings_stats[i].stat_string);
+		for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++) {
+			str = ixgbe_gstrings_stats[i].stat_string;
+			ethtool_puts(&data, str);
+		}
 		for (i = 0; i < netdev->num_tx_queues; i++) {
-			ethtool_sprintf(&p, "tx_queue_%u_packets", i);
-			ethtool_sprintf(&p, "tx_queue_%u_bytes", i);
+			ethtool_sprintf(&data, "tx_queue_%u_packets", i);
+			ethtool_sprintf(&data, "tx_queue_%u_bytes", i);
 		}
 		for (i = 0; i < IXGBE_NUM_RX_QUEUES; i++) {
-			ethtool_sprintf(&p, "rx_queue_%u_packets", i);
-			ethtool_sprintf(&p, "rx_queue_%u_bytes", i);
+			ethtool_sprintf(&data, "rx_queue_%u_packets", i);
+			ethtool_sprintf(&data, "rx_queue_%u_bytes", i);
 		}
 		for (i = 0; i < IXGBE_MAX_PACKET_BUFFERS; i++) {
-			ethtool_sprintf(&p, "tx_pb_%u_pxon", i);
-			ethtool_sprintf(&p, "tx_pb_%u_pxoff", i);
+			ethtool_sprintf(&data, "tx_pb_%u_pxon", i);
+			ethtool_sprintf(&data, "tx_pb_%u_pxoff", i);
 		}
 		for (i = 0; i < IXGBE_MAX_PACKET_BUFFERS; i++) {
-			ethtool_sprintf(&p, "rx_pb_%u_pxon", i);
-			ethtool_sprintf(&p, "rx_pb_%u_pxoff", i);
+			ethtool_sprintf(&data, "rx_pb_%u_pxon", i);
+			ethtool_sprintf(&data, "rx_pb_%u_pxoff", i);
 		}
 		/* BUG_ON(p - data != IXGBE_STATS_LEN * ETH_GSTRING_LEN); */
 		break;
 	case ETH_SS_PRIV_FLAGS:
-		memcpy(data, ixgbe_priv_flags_strings,
-		       IXGBE_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN);
+		for (i = 0; i < IXGBE_PRIV_FLAGS_STR_LEN; i++)
+			ethtool_puts(&data, ixgbe_priv_flags_strings[i]);
 	}
 }
 
drivers/net/ethernet/intel/ixgbevf/ethtool.c +14 -22
index 7ac53171b041..f63a9f683e20 100644
@@ -70,7 +70,7 @@ static const char ixgbe_gstrings_test[][ETH_GSTRING_LEN] = {
 	"Link test   (on/offline)"
 };
 
-#define IXGBEVF_TEST_LEN (sizeof(ixgbe_gstrings_test) / ETH_GSTRING_LEN)
+#define IXGBEVF_TEST_LEN ARRAY_SIZE(ixgbe_gstrings_test)
 
 static const char ixgbevf_priv_flags_strings[][ETH_GSTRING_LEN] = {
 #define IXGBEVF_PRIV_FLAGS_LEGACY_RX	BIT(0)
@@ -504,43 +504,35 @@ static void ixgbevf_get_strings(struct net_device *netdev, u32 stringset,
 				u8 *data)
 {
 	struct ixgbevf_adapter *adapter = netdev_priv(netdev);
-	char *p = (char *)data;
+	const char *str;
 	int i;
 
 	switch (stringset) {
 	case ETH_SS_TEST:
-		memcpy(data, *ixgbe_gstrings_test,
-		       IXGBEVF_TEST_LEN * ETH_GSTRING_LEN);
+		for (i = 0; i < IXGBEVF_TEST_LEN; i++)
+			ethtool_puts(&data, ixgbe_gstrings_test[i]);
 		break;
 	case ETH_SS_STATS:
 		for (i = 0; i < IXGBEVF_GLOBAL_STATS_LEN; i++) {
-			memcpy(p, ixgbevf_gstrings_stats[i].stat_string,
-			       ETH_GSTRING_LEN);
-			p += ETH_GSTRING_LEN;
+			str = ixgbevf_gstrings_stats[i].stat_string;
+			ethtool_puts(&data, str);
 		}
-
 		for (i = 0; i < adapter->num_tx_queues; i++) {
-			sprintf(p, "tx_queue_%u_packets", i);
-			p += ETH_GSTRING_LEN;
-			sprintf(p, "tx_queue_%u_bytes", i);
-			p += ETH_GSTRING_LEN;
+			ethtool_sprintf(&data, "tx_queue_%u_packets", i);
+			ethtool_sprintf(&data, "tx_queue_%u_bytes", i);
 		}
 		for (i = 0; i < adapter->num_xdp_queues; i++) {
-			sprintf(p, "xdp_queue_%u_packets", i);
-			p += ETH_GSTRING_LEN;
-			sprintf(p, "xdp_queue_%u_bytes", i);
-			p += ETH_GSTRING_LEN;
+			ethtool_sprintf(&data, "xdp_queue_%u_packets", i);
+			ethtool_sprintf(&data, "xdp_queue_%u_bytes", i);
 		}
 		for (i = 0; i < adapter->num_rx_queues; i++) {
-			sprintf(p, "rx_queue_%u_packets", i);
-			p += ETH_GSTRING_LEN;
-			sprintf(p, "rx_queue_%u_bytes", i);
-			p += ETH_GSTRING_LEN;
+			ethtool_sprintf(&data, "rx_queue_%u_packets", i);
+			ethtool_sprintf(&data, "rx_queue_%u_bytes", i);
 		}
 		break;
 	case ETH_SS_PRIV_FLAGS:
-		memcpy(data, ixgbevf_priv_flags_strings,
-		       IXGBEVF_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN);
+		for (i = 0; i < IXGBEVF_PRIV_FLAGS_STR_LEN; i++)
+			ethtool_puts(&data, ixgbevf_priv_flags_strings[i]);
 		break;
 	}
 }
Signature · 1 line
2.47.0
maintainer
#1 lore raw
Quoted 7 lines · Rosen Penev

The latter is the preferred way to copy ethtool strings.

Avoids manually incrementing the pointer. Cleans up the code quite well.

---
v2: add iwl-next tag. use inline int in for loops.

Quoted 9 lines
  .../net/ethernet/intel/e1000/e1000_ethtool.c  | 10 ++---
  drivers/net/ethernet/intel/e1000e/ethtool.c   | 14 +++----
  .../net/ethernet/intel/fm10k/fm10k_ethtool.c  | 10 ++---
  .../net/ethernet/intel/i40e/i40e_ethtool.c    |  6 +--
  drivers/net/ethernet/intel/ice/ice_ethtool.c  | 37 +++++++++++--------
  drivers/net/ethernet/intel/igb/igb_ethtool.c  | 35 ++++++++++--------
  drivers/net/ethernet/intel/igbvf/ethtool.c    | 10 ++---
  drivers/net/ethernet/intel/igc/igc_ethtool.c  | 36 +++++++++---------
  .../net/ethernet/intel/ixgbe/ixgbe_ethtool.c  | 32 ++++++++--------

for ice, igb, igc, and ixgbe the current code already uses ethtool string helpers, and in many places you are just changing variable name, "p" to "data", I would rather avoid that.

sorry for not spotting that earlier, and apologies that we have so many drivers to fix up in the first place

Quoted 72 lines
drivers/net/ethernet/intel/ice/ice_ethtool.c +18 -15
index 2924ac61300d..62a152be8180 100644
@@ -83,7 +83,7 @@ static const char ice_gstrings_test[][ETH_GSTRING_LEN] = {
  	"Link test   (on/offline)",
  };
 
-#define ICE_TEST_LEN (sizeof(ice_gstrings_test) / ETH_GSTRING_LEN)
+#define ICE_TEST_LEN ARRAY_SIZE(ice_gstrings_test)
 
  /* These PF_STATs might look like duplicates of some NETDEV_STATs,
   * but they aren't. This device is capable of supporting multiple
@@ -1481,48 +1481,53 @@ static void
  __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,
  		  struct ice_vsi *vsi)
  {
+	const char *str;
  	unsigned int i;
-	u8 *p = data;
 
  	switch (stringset) {
  	case ETH_SS_STATS:
-		for (i = 0; i < ICE_VSI_STATS_LEN; i++)
-			ethtool_puts(&p, ice_gstrings_vsi_stats[i].stat_string);
+		for (i = 0; i < ICE_VSI_STATS_LEN; i++) {
+			str = ice_gstrings_vsi_stats[i].stat_string;
+			ethtool_puts(&data, str);
+		}
 
  		if (ice_is_port_repr_netdev(netdev))
  			return;
 
  		ice_for_each_alloc_txq(vsi, i) {
-			ethtool_sprintf(&p, "tx_queue_%u_packets", i);
-			ethtool_sprintf(&p, "tx_queue_%u_bytes", i);
+			ethtool_sprintf(&data, "tx_queue_%u_packets", i);
+			ethtool_sprintf(&data, "tx_queue_%u_bytes", i);
  		}
 
  		ice_for_each_alloc_rxq(vsi, i) {
-			ethtool_sprintf(&p, "rx_queue_%u_packets", i);
-			ethtool_sprintf(&p, "rx_queue_%u_bytes", i);
+			ethtool_sprintf(&data, "rx_queue_%u_packets", i);
+			ethtool_sprintf(&data, "rx_queue_%u_bytes", i);
  		}
 
  		if (vsi->type != ICE_VSI_PF)
  			return;
 
-		for (i = 0; i < ICE_PF_STATS_LEN; i++)
-			ethtool_puts(&p, ice_gstrings_pf_stats[i].stat_string);
+		for (i = 0; i < ICE_PF_STATS_LEN; i++) {
+			str = ice_gstrings_pf_stats[i].stat_string;
+			ethtool_puts(&data, str);
+		}
 
  		for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
-			ethtool_sprintf(&p, "tx_priority_%u_xon.nic", i);
-			ethtool_sprintf(&p, "tx_priority_%u_xoff.nic", i);
+			ethtool_sprintf(&data, "tx_priority_%u_xon.nic", i);
+			ethtool_sprintf(&data, "tx_priority_%u_xoff.nic", i);
  		}
  		for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
-			ethtool_sprintf(&p, "rx_priority_%u_xon.nic", i);
-			ethtool_sprintf(&p, "rx_priority_%u_xoff.nic", i);
+			ethtool_sprintf(&data, "rx_priority_%u_xon.nic", i);
+			ethtool_sprintf(&data, "rx_priority_%u_xoff.nic", i);
  		}
  		break;
  	case ETH_SS_TEST:
-		memcpy(data, ice_gstrings_test, ICE_TEST_LEN * ETH_GSTRING_LEN);

drivers/net/ethernet/intel/ice/ice_ethtool.c static void · line 1533

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_ethtool.c +3 -1
+		for (i = 0; i < ICE_TEST_LEN; i++)
+			ethtool_puts(&data, ice_gstrings_test[i]);
  		break;
  	case ETH_SS_PRIV_FLAGS:
  		for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++)
-			ethtool_puts(&p, ice_gstrings_priv_flags[i].name);
+			ethtool_puts(&data, ice_gstrings_priv_flags[i].name);
  		break;
  	default:
  		break;

really no need to git-blame touch most of the code here

Quoted 57 lines
drivers/net/ethernet/intel/igb/igb_ethtool.c +17 -14
index ca6ccbc13954..c4a8712389af 100644
@@ -123,7 +123,7 @@ static const char igb_gstrings_test[][ETH_GSTRING_LEN] = {
  	[TEST_LOOP] = "Loopback test  (offline)",
  	[TEST_LINK] = "Link test   (on/offline)"
  };
-#define IGB_TEST_LEN (sizeof(igb_gstrings_test) / ETH_GSTRING_LEN)
+#define IGB_TEST_LEN ARRAY_SIZE(igb_gstrings_test)
 
  static const char igb_priv_flags_strings[][ETH_GSTRING_LEN] = {
  #define IGB_PRIV_FLAGS_LEGACY_RX	BIT(0)
@@ -2347,35 +2347,38 @@ static void igb_get_ethtool_stats(struct net_device *netdev,
  static void igb_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
  {
  	struct igb_adapter *adapter = netdev_priv(netdev);
-	u8 *p = data;
+	const char *str;
  	int i;
 
  	switch (stringset) {
  	case ETH_SS_TEST:
-		memcpy(data, igb_gstrings_test, sizeof(igb_gstrings_test));
+		for (i = 0; i < IGB_TEST_LEN; i++)
+			ethtool_puts(&data, igb_gstrings_test[i]);
  		break;
  	case ETH_SS_STATS:
  		for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++)
-			ethtool_puts(&p, igb_gstrings_stats[i].stat_string);
-		for (i = 0; i < IGB_NETDEV_STATS_LEN; i++)
-			ethtool_puts(&p, igb_gstrings_net_stats[i].stat_string);
+			ethtool_puts(&data, igb_gstrings_stats[i].stat_string);
+		for (i = 0; i < IGB_NETDEV_STATS_LEN; i++) {
+			str = igb_gstrings_net_stats[i].stat_string;
+			ethtool_puts(&data, str);
+		}
  		for (i = 0; i < adapter->num_tx_queues; i++) {
-			ethtool_sprintf(&p, "tx_queue_%u_packets", i);
-			ethtool_sprintf(&p, "tx_queue_%u_bytes", i);
-			ethtool_sprintf(&p, "tx_queue_%u_restart", i);
+			ethtool_sprintf(&data, "tx_queue_%u_packets", i);
+			ethtool_sprintf(&data, "tx_queue_%u_bytes", i);
+			ethtool_sprintf(&data, "tx_queue_%u_restart", i);
  		}
  		for (i = 0; i < adapter->num_rx_queues; i++) {
-			ethtool_sprintf(&p, "rx_queue_%u_packets", i);
-			ethtool_sprintf(&p, "rx_queue_%u_bytes", i);
-			ethtool_sprintf(&p, "rx_queue_%u_drops", i);
-			ethtool_sprintf(&p, "rx_queue_%u_csum_err", i);
-			ethtool_sprintf(&p, "rx_queue_%u_alloc_failed", i);
+			ethtool_sprintf(&data, "rx_queue_%u_packets", i);
+			ethtool_sprintf(&data, "rx_queue_%u_bytes", i);
+			ethtool_sprintf(&data, "rx_queue_%u_drops", i);
+			ethtool_sprintf(&data, "rx_queue_%u_csum_err", i);
+			ethtool_sprintf(&data, "rx_queue_%u_alloc_failed", i);
  		}

drivers/net/ethernet/intel/igb/igb_ethtool.c static void igb_get_ethtool_stats(struct net_device *netdev, · line 2384

Quoted 10 lines
drivers/net/ethernet/intel/igb/igb_ethtool.c +2 -2
  		/* BUG_ON(p - data != IGB_STATS_LEN * ETH_GSTRING_LEN); */
  		break;
  	case ETH_SS_PRIV_FLAGS:
-		memcpy(data, igb_priv_flags_strings,
-		       IGB_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN);
+		for (i = 0; i < IGB_PRIV_FLAGS_STR_LEN; i++)
+			ethtool_puts(&data, igb_priv_flags_strings[i]);
  		break;
  	}
  }

ditto

Quoted 58 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c +17 -15
index 5b0c6f433767..7b118fb7097b 100644
@@ -104,7 +104,7 @@ static const char igc_gstrings_test[][ETH_GSTRING_LEN] = {
  	[TEST_LINK] = "Link test   (on/offline)"
  };
 
-#define IGC_TEST_LEN (sizeof(igc_gstrings_test) / ETH_GSTRING_LEN)
+#define IGC_TEST_LEN ARRAY_SIZE(igc_gstrings_test)
 
  #define IGC_GLOBAL_STATS_LEN	\
  	(sizeof(igc_gstrings_stats) / sizeof(struct igc_stats))
@@ -763,36 +763,38 @@ static void igc_ethtool_get_strings(struct net_device *netdev, u32 stringset,
  				    u8 *data)
  {
  	struct igc_adapter *adapter = netdev_priv(netdev);
-	u8 *p = data;
+	const char *str;
  	int i;
 
  	switch (stringset) {
  	case ETH_SS_TEST:
-		memcpy(data, *igc_gstrings_test,
-		       IGC_TEST_LEN * ETH_GSTRING_LEN);
+		for (i = 0; i < IGC_TEST_LEN; i++)
+			ethtool_puts(&data, igc_gstrings_test[i]);
  		break;
  	case ETH_SS_STATS:
  		for (i = 0; i < IGC_GLOBAL_STATS_LEN; i++)
-			ethtool_puts(&p, igc_gstrings_stats[i].stat_string);
-		for (i = 0; i < IGC_NETDEV_STATS_LEN; i++)
-			ethtool_puts(&p, igc_gstrings_net_stats[i].stat_string);
+			ethtool_puts(&data, igc_gstrings_stats[i].stat_string);
+		for (i = 0; i < IGC_NETDEV_STATS_LEN; i++) {
+			str = igc_gstrings_net_stats[i].stat_string;
+			ethtool_puts(&data, str);
+		}
  		for (i = 0; i < adapter->num_tx_queues; i++) {
-			ethtool_sprintf(&p, "tx_queue_%u_packets", i);
-			ethtool_sprintf(&p, "tx_queue_%u_bytes", i);
-			ethtool_sprintf(&p, "tx_queue_%u_restart", i);
+			ethtool_sprintf(&data, "tx_queue_%u_packets", i);
+			ethtool_sprintf(&data, "tx_queue_%u_bytes", i);
+			ethtool_sprintf(&data, "tx_queue_%u_restart", i);
  		}
  		for (i = 0; i < adapter->num_rx_queues; i++) {
-			ethtool_sprintf(&p, "rx_queue_%u_packets", i);
-			ethtool_sprintf(&p, "rx_queue_%u_bytes", i);
-			ethtool_sprintf(&p, "rx_queue_%u_drops", i);
-			ethtool_sprintf(&p, "rx_queue_%u_csum_err", i);
-			ethtool_sprintf(&p, "rx_queue_%u_alloc_failed", i);
+			ethtool_sprintf(&data, "rx_queue_%u_packets", i);
+			ethtool_sprintf(&data, "rx_queue_%u_bytes", i);
+			ethtool_sprintf(&data, "rx_queue_%u_drops", i);
+			ethtool_sprintf(&data, "rx_queue_%u_csum_err", i);
+			ethtool_sprintf(&data, "rx_queue_%u_alloc_failed", i);
  		}

drivers/net/ethernet/intel/igc/igc_ethtool.c static void igc_ethtool_get_strings(struct net_device *netdev, u32 stringset, · line 800

Quoted 10 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c +2 -2
  		/* BUG_ON(p - data != IGC_STATS_LEN * ETH_GSTRING_LEN); */
  		break;
  	case ETH_SS_PRIV_FLAGS:
-		memcpy(data, igc_priv_flags_strings,
-		       IGC_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN);
+		for (i = 0; i < IGC_PRIV_FLAGS_STR_LEN; i++)
+			ethtool_puts(&data, igc_priv_flags_strings[i]);
  		break;
  	}
  }

ditto

Quoted 58 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c +15 -13
index 9482e0cca8b7..b3b2e38c2ae6 100644
@@ -129,7 +129,7 @@ static const char ixgbe_gstrings_test[][ETH_GSTRING_LEN] = {
  	"Interrupt test (offline)", "Loopback test  (offline)",
  	"Link test   (on/offline)"
  };
-#define IXGBE_TEST_LEN sizeof(ixgbe_gstrings_test) / ETH_GSTRING_LEN
+#define IXGBE_TEST_LEN ARRAY_SIZE(ixgbe_gstrings_test)
 
  static const char ixgbe_priv_flags_strings[][ETH_GSTRING_LEN] = {
  #define IXGBE_PRIV_FLAGS_LEGACY_RX	BIT(0)
@@ -1409,38 +1409,40 @@ static void ixgbe_get_ethtool_stats(struct net_device *netdev,
  static void ixgbe_get_strings(struct net_device *netdev, u32 stringset,
  			      u8 *data)
  {
+	const char *str;
  	unsigned int i;
-	u8 *p = data;
 
  	switch (stringset) {
  	case ETH_SS_TEST:
  		for (i = 0; i < IXGBE_TEST_LEN; i++)
-			ethtool_puts(&p, ixgbe_gstrings_test[i]);
+			ethtool_puts(&data, ixgbe_gstrings_test[i]);
  		break;
  	case ETH_SS_STATS:
-		for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++)
-			ethtool_puts(&p, ixgbe_gstrings_stats[i].stat_string);
+		for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++) {
+			str = ixgbe_gstrings_stats[i].stat_string;
+			ethtool_puts(&data, str);
+		}
  		for (i = 0; i < netdev->num_tx_queues; i++) {
-			ethtool_sprintf(&p, "tx_queue_%u_packets", i);
-			ethtool_sprintf(&p, "tx_queue_%u_bytes", i);
+			ethtool_sprintf(&data, "tx_queue_%u_packets", i);
+			ethtool_sprintf(&data, "tx_queue_%u_bytes", i);
  		}
  		for (i = 0; i < IXGBE_NUM_RX_QUEUES; i++) {
-			ethtool_sprintf(&p, "rx_queue_%u_packets", i);
-			ethtool_sprintf(&p, "rx_queue_%u_bytes", i);
+			ethtool_sprintf(&data, "rx_queue_%u_packets", i);
+			ethtool_sprintf(&data, "rx_queue_%u_bytes", i);
  		}
  		for (i = 0; i < IXGBE_MAX_PACKET_BUFFERS; i++) {
-			ethtool_sprintf(&p, "tx_pb_%u_pxon", i);
-			ethtool_sprintf(&p, "tx_pb_%u_pxoff", i);
+			ethtool_sprintf(&data, "tx_pb_%u_pxon", i);
+			ethtool_sprintf(&data, "tx_pb_%u_pxoff", i);
  		}
  		for (i = 0; i < IXGBE_MAX_PACKET_BUFFERS; i++) {
-			ethtool_sprintf(&p, "rx_pb_%u_pxon", i);
-			ethtool_sprintf(&p, "rx_pb_%u_pxoff", i);
+			ethtool_sprintf(&data, "rx_pb_%u_pxon", i);
+			ethtool_sprintf(&data, "rx_pb_%u_pxoff", i);
  		}

drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c static void ixgbe_get_ethtool_stats(struct net_device *netdev, · line 1448

Quoted 10 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c +2 -2
  		/* BUG_ON(p - data != IXGBE_STATS_LEN * ETH_GSTRING_LEN); */
  		break;
  	case ETH_SS_PRIV_FLAGS:
-		memcpy(data, ixgbe_priv_flags_strings,
-		       IXGBE_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN);
+		for (i = 0; i < IXGBE_PRIV_FLAGS_STR_LEN; i++)
+			ethtool_puts(&data, ixgbe_priv_flags_strings[i]);
  	}
  }
 

ditto here

#2 lore raw
Quoted 19 lines · Przemek Kitszel
Quoted 7 lines · Rosen Penev

The latter is the preferred way to copy ethtool strings.

Avoids manually incrementing the pointer. Cleans up the code quite well.

---
v2: add iwl-next tag. use inline int in for loops.

Quoted 9 lines
  .../net/ethernet/intel/e1000/e1000_ethtool.c  | 10 ++---
  drivers/net/ethernet/intel/e1000e/ethtool.c   | 14 +++----
  .../net/ethernet/intel/fm10k/fm10k_ethtool.c  | 10 ++---
  .../net/ethernet/intel/i40e/i40e_ethtool.c    |  6 +--
  drivers/net/ethernet/intel/ice/ice_ethtool.c  | 37 +++++++++++--------
  drivers/net/ethernet/intel/igb/igb_ethtool.c  | 35 ++++++++++--------
  drivers/net/ethernet/intel/igbvf/ethtool.c    | 10 ++---
  drivers/net/ethernet/intel/igc/igc_ethtool.c  | 36 +++++++++---------
  .../net/ethernet/intel/ixgbe/ixgbe_ethtool.c  | 32 ++++++++--------
Quoted 3 lines

for ice, igb, igc, and ixgbe the current code already uses ethtool string helpers, and in many places you are just changing variable name, "p" to "data", I would rather avoid that.

well, since I'm cleaning some of this code up, might as well get rid of variables. That was suggested to me with other similar patches.

Quoted 80 lines

sorry for not spotting that earlier, and apologies that we have so many drivers to fix up in the first place

Quoted 76 lines
drivers/net/ethernet/intel/ice/ice_ethtool.c +20 -15
index 2924ac61300d..62a152be8180 100644
@@ -83,7 +83,7 @@ static const char ice_gstrings_test[][ETH_GSTRING_LEN] = {
      "Link test   (on/offline)",
  };
 
-#define ICE_TEST_LEN (sizeof(ice_gstrings_test) / ETH_GSTRING_LEN)
+#define ICE_TEST_LEN ARRAY_SIZE(ice_gstrings_test)
 
  /* These PF_STATs might look like duplicates of some NETDEV_STATs,
   * but they aren't. This device is capable of supporting multiple
@@ -1481,48 +1481,53 @@ static void
  __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,
                struct ice_vsi *vsi)
  {
+     const char *str;
      unsigned int i;
-     u8 *p = data;
 
      switch (stringset) {
      case ETH_SS_STATS:
-             for (i = 0; i < ICE_VSI_STATS_LEN; i++)
-                     ethtool_puts(&p, ice_gstrings_vsi_stats[i].stat_string);
+             for (i = 0; i < ICE_VSI_STATS_LEN; i++) {
+                     str = ice_gstrings_vsi_stats[i].stat_string;
+                     ethtool_puts(&data, str);
+             }
 
              if (ice_is_port_repr_netdev(netdev))
                      return;
 
              ice_for_each_alloc_txq(vsi, i) {
-                     ethtool_sprintf(&p, "tx_queue_%u_packets", i);
-                     ethtool_sprintf(&p, "tx_queue_%u_bytes", i);
+                     ethtool_sprintf(&data, "tx_queue_%u_packets", i);
+                     ethtool_sprintf(&data, "tx_queue_%u_bytes", i);
              }
 
              ice_for_each_alloc_rxq(vsi, i) {
-                     ethtool_sprintf(&p, "rx_queue_%u_packets", i);
-                     ethtool_sprintf(&p, "rx_queue_%u_bytes", i);
+                     ethtool_sprintf(&data, "rx_queue_%u_packets", i);
+                     ethtool_sprintf(&data, "rx_queue_%u_bytes", i);
              }
 
              if (vsi->type != ICE_VSI_PF)
                      return;
 
-             for (i = 0; i < ICE_PF_STATS_LEN; i++)
-                     ethtool_puts(&p, ice_gstrings_pf_stats[i].stat_string);
+             for (i = 0; i < ICE_PF_STATS_LEN; i++) {
+                     str = ice_gstrings_pf_stats[i].stat_string;
+                     ethtool_puts(&data, str);
+             }
 
              for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
-                     ethtool_sprintf(&p, "tx_priority_%u_xon.nic", i);
-                     ethtool_sprintf(&p, "tx_priority_%u_xoff.nic", i);
+                     ethtool_sprintf(&data, "tx_priority_%u_xon.nic", i);
+                     ethtool_sprintf(&data, "tx_priority_%u_xoff.nic", i);
              }
              for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
-                     ethtool_sprintf(&p, "rx_priority_%u_xon.nic", i);
-                     ethtool_sprintf(&p, "rx_priority_%u_xoff.nic", i);
+                     ethtool_sprintf(&data, "rx_priority_%u_xon.nic", i);
+                     ethtool_sprintf(&data, "rx_priority_%u_xoff.nic", i);
              }
              break;
      case ETH_SS_TEST:
-             memcpy(data, ice_gstrings_test, ICE_TEST_LEN * ETH_GSTRING_LEN);
+             for (i = 0; i < ICE_TEST_LEN; i++)
+                     ethtool_puts(&data, ice_gstrings_test[i]);
              break;
      case ETH_SS_PRIV_FLAGS:
Quoted 8 lines

drivers/net/ethernet/intel/ice/ice_ethtool.c static void · line 1533

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_ethtool.c +1 -1
              for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++)
-                     ethtool_puts(&p, ice_gstrings_priv_flags[i].name);
+                     ethtool_puts(&data, ice_gstrings_priv_flags[i].name);
              break;
      default:
              break;

really no need to git-blame touch most of the code here>

Actually the function should be taking a double pointer here I think in case something gets called after it in the main function.

Quoted 211 lines
Quoted 57 lines
drivers/net/ethernet/intel/igb/igb_ethtool.c +17 -14
index ca6ccbc13954..c4a8712389af 100644
@@ -123,7 +123,7 @@ static const char igb_gstrings_test[][ETH_GSTRING_LEN] = {
      [TEST_LOOP] = "Loopback test  (offline)",
      [TEST_LINK] = "Link test   (on/offline)"
  };
-#define IGB_TEST_LEN (sizeof(igb_gstrings_test) / ETH_GSTRING_LEN)
+#define IGB_TEST_LEN ARRAY_SIZE(igb_gstrings_test)
 
  static const char igb_priv_flags_strings[][ETH_GSTRING_LEN] = {
  #define IGB_PRIV_FLAGS_LEGACY_RX    BIT(0)
@@ -2347,35 +2347,38 @@ static void igb_get_ethtool_stats(struct net_device *netdev,
  static void igb_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
  {
      struct igb_adapter *adapter = netdev_priv(netdev);
-     u8 *p = data;
+     const char *str;
      int i;
 
      switch (stringset) {
      case ETH_SS_TEST:
-             memcpy(data, igb_gstrings_test, sizeof(igb_gstrings_test));
+             for (i = 0; i < IGB_TEST_LEN; i++)
+                     ethtool_puts(&data, igb_gstrings_test[i]);
              break;
      case ETH_SS_STATS:
              for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++)
-                     ethtool_puts(&p, igb_gstrings_stats[i].stat_string);
-             for (i = 0; i < IGB_NETDEV_STATS_LEN; i++)
-                     ethtool_puts(&p, igb_gstrings_net_stats[i].stat_string);
+                     ethtool_puts(&data, igb_gstrings_stats[i].stat_string);
+             for (i = 0; i < IGB_NETDEV_STATS_LEN; i++) {
+                     str = igb_gstrings_net_stats[i].stat_string;
+                     ethtool_puts(&data, str);
+             }
              for (i = 0; i < adapter->num_tx_queues; i++) {
-                     ethtool_sprintf(&p, "tx_queue_%u_packets", i);
-                     ethtool_sprintf(&p, "tx_queue_%u_bytes", i);
-                     ethtool_sprintf(&p, "tx_queue_%u_restart", i);
+                     ethtool_sprintf(&data, "tx_queue_%u_packets", i);
+                     ethtool_sprintf(&data, "tx_queue_%u_bytes", i);
+                     ethtool_sprintf(&data, "tx_queue_%u_restart", i);
              }
              for (i = 0; i < adapter->num_rx_queues; i++) {
-                     ethtool_sprintf(&p, "rx_queue_%u_packets", i);
-                     ethtool_sprintf(&p, "rx_queue_%u_bytes", i);
-                     ethtool_sprintf(&p, "rx_queue_%u_drops", i);
-                     ethtool_sprintf(&p, "rx_queue_%u_csum_err", i);
-                     ethtool_sprintf(&p, "rx_queue_%u_alloc_failed", i);
+                     ethtool_sprintf(&data, "rx_queue_%u_packets", i);
+                     ethtool_sprintf(&data, "rx_queue_%u_bytes", i);
+                     ethtool_sprintf(&data, "rx_queue_%u_drops", i);
+                     ethtool_sprintf(&data, "rx_queue_%u_csum_err", i);
+                     ethtool_sprintf(&data, "rx_queue_%u_alloc_failed", i);
              }

drivers/net/ethernet/intel/igb/igb_ethtool.c static void igb_get_ethtool_stats(struct net_device *netdev, · line 2384

Quoted 10 lines
drivers/net/ethernet/intel/igb/igb_ethtool.c +2 -2
              /* BUG_ON(p - data != IGB_STATS_LEN * ETH_GSTRING_LEN); */
              break;
      case ETH_SS_PRIV_FLAGS:
-             memcpy(data, igb_priv_flags_strings,
-                    IGB_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN);
+             for (i = 0; i < IGB_PRIV_FLAGS_STR_LEN; i++)
+                     ethtool_puts(&data, igb_priv_flags_strings[i]);
              break;
      }
  }

ditto

Quoted 58 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c +17 -15
index 5b0c6f433767..7b118fb7097b 100644
@@ -104,7 +104,7 @@ static const char igc_gstrings_test[][ETH_GSTRING_LEN] = {
      [TEST_LINK] = "Link test   (on/offline)"
  };
 
-#define IGC_TEST_LEN (sizeof(igc_gstrings_test) / ETH_GSTRING_LEN)
+#define IGC_TEST_LEN ARRAY_SIZE(igc_gstrings_test)
 
  #define IGC_GLOBAL_STATS_LEN        \
      (sizeof(igc_gstrings_stats) / sizeof(struct igc_stats))
@@ -763,36 +763,38 @@ static void igc_ethtool_get_strings(struct net_device *netdev, u32 stringset,
                                  u8 *data)
  {
      struct igc_adapter *adapter = netdev_priv(netdev);
-     u8 *p = data;
+     const char *str;
      int i;
 
      switch (stringset) {
      case ETH_SS_TEST:
-             memcpy(data, *igc_gstrings_test,
-                    IGC_TEST_LEN * ETH_GSTRING_LEN);
+             for (i = 0; i < IGC_TEST_LEN; i++)
+                     ethtool_puts(&data, igc_gstrings_test[i]);
              break;
      case ETH_SS_STATS:
              for (i = 0; i < IGC_GLOBAL_STATS_LEN; i++)
-                     ethtool_puts(&p, igc_gstrings_stats[i].stat_string);
-             for (i = 0; i < IGC_NETDEV_STATS_LEN; i++)
-                     ethtool_puts(&p, igc_gstrings_net_stats[i].stat_string);
+                     ethtool_puts(&data, igc_gstrings_stats[i].stat_string);
+             for (i = 0; i < IGC_NETDEV_STATS_LEN; i++) {
+                     str = igc_gstrings_net_stats[i].stat_string;
+                     ethtool_puts(&data, str);
+             }
              for (i = 0; i < adapter->num_tx_queues; i++) {
-                     ethtool_sprintf(&p, "tx_queue_%u_packets", i);
-                     ethtool_sprintf(&p, "tx_queue_%u_bytes", i);
-                     ethtool_sprintf(&p, "tx_queue_%u_restart", i);
+                     ethtool_sprintf(&data, "tx_queue_%u_packets", i);
+                     ethtool_sprintf(&data, "tx_queue_%u_bytes", i);
+                     ethtool_sprintf(&data, "tx_queue_%u_restart", i);
              }
              for (i = 0; i < adapter->num_rx_queues; i++) {
-                     ethtool_sprintf(&p, "rx_queue_%u_packets", i);
-                     ethtool_sprintf(&p, "rx_queue_%u_bytes", i);
-                     ethtool_sprintf(&p, "rx_queue_%u_drops", i);
-                     ethtool_sprintf(&p, "rx_queue_%u_csum_err", i);
-                     ethtool_sprintf(&p, "rx_queue_%u_alloc_failed", i);
+                     ethtool_sprintf(&data, "rx_queue_%u_packets", i);
+                     ethtool_sprintf(&data, "rx_queue_%u_bytes", i);
+                     ethtool_sprintf(&data, "rx_queue_%u_drops", i);
+                     ethtool_sprintf(&data, "rx_queue_%u_csum_err", i);
+                     ethtool_sprintf(&data, "rx_queue_%u_alloc_failed", i);
              }

drivers/net/ethernet/intel/igc/igc_ethtool.c static void igc_ethtool_get_strings(struct net_device *netdev, u32 stringset, · line 800

Quoted 10 lines
drivers/net/ethernet/intel/igc/igc_ethtool.c +2 -2
              /* BUG_ON(p - data != IGC_STATS_LEN * ETH_GSTRING_LEN); */
              break;
      case ETH_SS_PRIV_FLAGS:
-             memcpy(data, igc_priv_flags_strings,
-                    IGC_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN);
+             for (i = 0; i < IGC_PRIV_FLAGS_STR_LEN; i++)
+                     ethtool_puts(&data, igc_priv_flags_strings[i]);
              break;
      }
  }

ditto

Quoted 58 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c +15 -13
index 9482e0cca8b7..b3b2e38c2ae6 100644
@@ -129,7 +129,7 @@ static const char ixgbe_gstrings_test[][ETH_GSTRING_LEN] = {
      "Interrupt test (offline)", "Loopback test  (offline)",
      "Link test   (on/offline)"
  };
-#define IXGBE_TEST_LEN sizeof(ixgbe_gstrings_test) / ETH_GSTRING_LEN
+#define IXGBE_TEST_LEN ARRAY_SIZE(ixgbe_gstrings_test)
 
  static const char ixgbe_priv_flags_strings[][ETH_GSTRING_LEN] = {
  #define IXGBE_PRIV_FLAGS_LEGACY_RX  BIT(0)
@@ -1409,38 +1409,40 @@ static void ixgbe_get_ethtool_stats(struct net_device *netdev,
  static void ixgbe_get_strings(struct net_device *netdev, u32 stringset,
                            u8 *data)
  {
+     const char *str;
      unsigned int i;
-     u8 *p = data;
 
      switch (stringset) {
      case ETH_SS_TEST:
              for (i = 0; i < IXGBE_TEST_LEN; i++)
-                     ethtool_puts(&p, ixgbe_gstrings_test[i]);
+                     ethtool_puts(&data, ixgbe_gstrings_test[i]);
              break;
      case ETH_SS_STATS:
-             for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++)
-                     ethtool_puts(&p, ixgbe_gstrings_stats[i].stat_string);
+             for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++) {
+                     str = ixgbe_gstrings_stats[i].stat_string;
+                     ethtool_puts(&data, str);
+             }
              for (i = 0; i < netdev->num_tx_queues; i++) {
-                     ethtool_sprintf(&p, "tx_queue_%u_packets", i);
-                     ethtool_sprintf(&p, "tx_queue_%u_bytes", i);
+                     ethtool_sprintf(&data, "tx_queue_%u_packets", i);
+                     ethtool_sprintf(&data, "tx_queue_%u_bytes", i);
              }
              for (i = 0; i < IXGBE_NUM_RX_QUEUES; i++) {
-                     ethtool_sprintf(&p, "rx_queue_%u_packets", i);
-                     ethtool_sprintf(&p, "rx_queue_%u_bytes", i);
+                     ethtool_sprintf(&data, "rx_queue_%u_packets", i);
+                     ethtool_sprintf(&data, "rx_queue_%u_bytes", i);
              }
              for (i = 0; i < IXGBE_MAX_PACKET_BUFFERS; i++) {
-                     ethtool_sprintf(&p, "tx_pb_%u_pxon", i);
-                     ethtool_sprintf(&p, "tx_pb_%u_pxoff", i);
+                     ethtool_sprintf(&data, "tx_pb_%u_pxon", i);
+                     ethtool_sprintf(&data, "tx_pb_%u_pxoff", i);
              }
              for (i = 0; i < IXGBE_MAX_PACKET_BUFFERS; i++) {
-                     ethtool_sprintf(&p, "rx_pb_%u_pxon", i);
-                     ethtool_sprintf(&p, "rx_pb_%u_pxoff", i);
+                     ethtool_sprintf(&data, "rx_pb_%u_pxon", i);
+                     ethtool_sprintf(&data, "rx_pb_%u_pxoff", i);
              }

drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c static void ixgbe_get_ethtool_stats(struct net_device *netdev, · line 1448

Quoted 10 lines
drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c +2 -2
              /* BUG_ON(p - data != IXGBE_STATS_LEN * ETH_GSTRING_LEN); */
              break;
      case ETH_SS_PRIV_FLAGS:
-             memcpy(data, ixgbe_priv_flags_strings,
-                    IXGBE_PRIV_FLAGS_STR_LEN * ETH_GSTRING_LEN);
+             for (i = 0; i < IXGBE_PRIV_FLAGS_STR_LEN; i++)
+                     ethtool_puts(&data, ixgbe_priv_flags_strings[i]);
      }
  }
 

ditto here

maintainer
#3 lore raw
Quoted 115 lines · Rosen Penev
Quoted 19 lines · Przemek Kitszel
Quoted 7 lines · Rosen Penev

The latter is the preferred way to copy ethtool strings.

Avoids manually incrementing the pointer. Cleans up the code quite well.

---
v2: add iwl-next tag. use inline int in for loops.

Quoted 9 lines
   .../net/ethernet/intel/e1000/e1000_ethtool.c  | 10 ++---
   drivers/net/ethernet/intel/e1000e/ethtool.c   | 14 +++----
   .../net/ethernet/intel/fm10k/fm10k_ethtool.c  | 10 ++---
   .../net/ethernet/intel/i40e/i40e_ethtool.c    |  6 +--
   drivers/net/ethernet/intel/ice/ice_ethtool.c  | 37 +++++++++++--------
   drivers/net/ethernet/intel/igb/igb_ethtool.c  | 35 ++++++++++--------
   drivers/net/ethernet/intel/igbvf/ethtool.c    | 10 ++---
   drivers/net/ethernet/intel/igc/igc_ethtool.c  | 36 +++++++++---------
   .../net/ethernet/intel/ixgbe/ixgbe_ethtool.c  | 32 ++++++++--------
Quoted 3 lines

for ice, igb, igc, and ixgbe the current code already uses ethtool string helpers, and in many places you are just changing variable name, "p" to "data", I would rather avoid that.

well, since I'm cleaning some of this code up, might as well get rid of variables. That was suggested to me with other similar patches.

Quoted 80 lines

sorry for not spotting that earlier, and apologies that we have so many drivers to fix up in the first place

Quoted 76 lines
drivers/net/ethernet/intel/ice/ice_ethtool.c +20 -15
index 2924ac61300d..62a152be8180 100644
@@ -83,7 +83,7 @@ static const char ice_gstrings_test[][ETH_GSTRING_LEN] = {
       "Link test   (on/offline)",
   };
 
-#define ICE_TEST_LEN (sizeof(ice_gstrings_test) / ETH_GSTRING_LEN)
+#define ICE_TEST_LEN ARRAY_SIZE(ice_gstrings_test)
 
   /* These PF_STATs might look like duplicates of some NETDEV_STATs,
    * but they aren't. This device is capable of supporting multiple
@@ -1481,48 +1481,53 @@ static void
   __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,
                 struct ice_vsi *vsi)
   {
+     const char *str;
       unsigned int i;
-     u8 *p = data;
 
       switch (stringset) {
       case ETH_SS_STATS:
-             for (i = 0; i < ICE_VSI_STATS_LEN; i++)
-                     ethtool_puts(&p, ice_gstrings_vsi_stats[i].stat_string);
+             for (i = 0; i < ICE_VSI_STATS_LEN; i++) {
+                     str = ice_gstrings_vsi_stats[i].stat_string;
+                     ethtool_puts(&data, str);
+             }
 
               if (ice_is_port_repr_netdev(netdev))
                       return;
 
               ice_for_each_alloc_txq(vsi, i) {
-                     ethtool_sprintf(&p, "tx_queue_%u_packets", i);
-                     ethtool_sprintf(&p, "tx_queue_%u_bytes", i);
+                     ethtool_sprintf(&data, "tx_queue_%u_packets", i);
+                     ethtool_sprintf(&data, "tx_queue_%u_bytes", i);
               }
 
               ice_for_each_alloc_rxq(vsi, i) {
-                     ethtool_sprintf(&p, "rx_queue_%u_packets", i);
-                     ethtool_sprintf(&p, "rx_queue_%u_bytes", i);
+                     ethtool_sprintf(&data, "rx_queue_%u_packets", i);
+                     ethtool_sprintf(&data, "rx_queue_%u_bytes", i);
               }
 
               if (vsi->type != ICE_VSI_PF)
                       return;
 
-             for (i = 0; i < ICE_PF_STATS_LEN; i++)
-                     ethtool_puts(&p, ice_gstrings_pf_stats[i].stat_string);
+             for (i = 0; i < ICE_PF_STATS_LEN; i++) {
+                     str = ice_gstrings_pf_stats[i].stat_string;
+                     ethtool_puts(&data, str);
+             }
 
               for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
-                     ethtool_sprintf(&p, "tx_priority_%u_xon.nic", i);
-                     ethtool_sprintf(&p, "tx_priority_%u_xoff.nic", i);
+                     ethtool_sprintf(&data, "tx_priority_%u_xon.nic", i);
+                     ethtool_sprintf(&data, "tx_priority_%u_xoff.nic", i);
               }
               for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
-                     ethtool_sprintf(&p, "rx_priority_%u_xon.nic", i);
-                     ethtool_sprintf(&p, "rx_priority_%u_xoff.nic", i);
+                     ethtool_sprintf(&data, "rx_priority_%u_xon.nic", i);
+                     ethtool_sprintf(&data, "rx_priority_%u_xoff.nic", i);
               }
               break;
       case ETH_SS_TEST:
-             memcpy(data, ice_gstrings_test, ICE_TEST_LEN * ETH_GSTRING_LEN);
+             for (i = 0; i < ICE_TEST_LEN; i++)
+                     ethtool_puts(&data, ice_gstrings_test[i]);
               break;
       case ETH_SS_PRIV_FLAGS:
Quoted 8 lines

drivers/net/ethernet/intel/ice/ice_ethtool.c static void · line 1533

Quoted 6 lines
drivers/net/ethernet/intel/ice/ice_ethtool.c +1 -1
               for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++)
-                     ethtool_puts(&p, ice_gstrings_priv_flags[i].name);
+                     ethtool_puts(&data, ice_gstrings_priv_flags[i].name);
               break;
       default:
               break;

really no need to git-blame touch most of the code here>

Quoted 2 lines

Actually the function should be taking a double pointer here I think in case something gets called after it in the main function.

I mean that both @p and @data are (u8 *).
I'm fine getting rid of tmp var, and updating the originally passed argument is fine. But you could achieve it by just changing param name.

BTW I guess it was @p to fit into 80 chars more easily ;)

#4 lore raw
Quoted 117 lines · Przemek Kitszel
Quoted 115 lines · Rosen Penev
Quoted 19 lines · Przemek Kitszel
Quoted 7 lines · Rosen Penev

The latter is the preferred way to copy ethtool strings.

Avoids manually incrementing the pointer. Cleans up the code quite well.

---
v2: add iwl-next tag. use inline int in for loops.

Quoted 9 lines
   .../net/ethernet/intel/e1000/e1000_ethtool.c  | 10 ++---
   drivers/net/ethernet/intel/e1000e/ethtool.c   | 14 +++----
   .../net/ethernet/intel/fm10k/fm10k_ethtool.c  | 10 ++---
   .../net/ethernet/intel/i40e/i40e_ethtool.c    |  6 +--
   drivers/net/ethernet/intel/ice/ice_ethtool.c  | 37 +++++++++++--------
   drivers/net/ethernet/intel/igb/igb_ethtool.c  | 35 ++++++++++--------
   drivers/net/ethernet/intel/igbvf/ethtool.c    | 10 ++---
   drivers/net/ethernet/intel/igc/igc_ethtool.c  | 36 +++++++++---------
   .../net/ethernet/intel/ixgbe/ixgbe_ethtool.c  | 32 ++++++++--------
Quoted 3 lines

for ice, igb, igc, and ixgbe the current code already uses ethtool string helpers, and in many places you are just changing variable name, "p" to "data", I would rather avoid that.

well, since I'm cleaning some of this code up, might as well get rid of variables. That was suggested to me with other similar patches.

Quoted 88 lines

sorry for not spotting that earlier, and apologies that we have so many drivers to fix up in the first place

Quoted 72 lines
drivers/net/ethernet/intel/ice/ice_ethtool.c +18 -15
index 2924ac61300d..62a152be8180 100644
@@ -83,7 +83,7 @@ static const char ice_gstrings_test[][ETH_GSTRING_LEN] = {
       "Link test   (on/offline)",
   };
 
-#define ICE_TEST_LEN (sizeof(ice_gstrings_test) / ETH_GSTRING_LEN)
+#define ICE_TEST_LEN ARRAY_SIZE(ice_gstrings_test)
 
   /* These PF_STATs might look like duplicates of some NETDEV_STATs,
    * but they aren't. This device is capable of supporting multiple
@@ -1481,48 +1481,53 @@ static void
   __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,
                 struct ice_vsi *vsi)
   {
+     const char *str;
       unsigned int i;
-     u8 *p = data;
 
       switch (stringset) {
       case ETH_SS_STATS:
-             for (i = 0; i < ICE_VSI_STATS_LEN; i++)
-                     ethtool_puts(&p, ice_gstrings_vsi_stats[i].stat_string);
+             for (i = 0; i < ICE_VSI_STATS_LEN; i++) {
+                     str = ice_gstrings_vsi_stats[i].stat_string;
+                     ethtool_puts(&data, str);
+             }
 
               if (ice_is_port_repr_netdev(netdev))
                       return;
 
               ice_for_each_alloc_txq(vsi, i) {
-                     ethtool_sprintf(&p, "tx_queue_%u_packets", i);
-                     ethtool_sprintf(&p, "tx_queue_%u_bytes", i);
+                     ethtool_sprintf(&data, "tx_queue_%u_packets", i);
+                     ethtool_sprintf(&data, "tx_queue_%u_bytes", i);
               }
 
               ice_for_each_alloc_rxq(vsi, i) {
-                     ethtool_sprintf(&p, "rx_queue_%u_packets", i);
-                     ethtool_sprintf(&p, "rx_queue_%u_bytes", i);
+                     ethtool_sprintf(&data, "rx_queue_%u_packets", i);
+                     ethtool_sprintf(&data, "rx_queue_%u_bytes", i);
               }
 
               if (vsi->type != ICE_VSI_PF)
                       return;
 
-             for (i = 0; i < ICE_PF_STATS_LEN; i++)
-                     ethtool_puts(&p, ice_gstrings_pf_stats[i].stat_string);
+             for (i = 0; i < ICE_PF_STATS_LEN; i++) {
+                     str = ice_gstrings_pf_stats[i].stat_string;
+                     ethtool_puts(&data, str);
+             }
 
               for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
-                     ethtool_sprintf(&p, "tx_priority_%u_xon.nic", i);
-                     ethtool_sprintf(&p, "tx_priority_%u_xoff.nic", i);
+                     ethtool_sprintf(&data, "tx_priority_%u_xon.nic", i);
+                     ethtool_sprintf(&data, "tx_priority_%u_xoff.nic", i);
               }
               for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
-                     ethtool_sprintf(&p, "rx_priority_%u_xon.nic", i);
-                     ethtool_sprintf(&p, "rx_priority_%u_xoff.nic", i);
+                     ethtool_sprintf(&data, "rx_priority_%u_xon.nic", i);
+                     ethtool_sprintf(&data, "rx_priority_%u_xoff.nic", i);
               }
               break;
       case ETH_SS_TEST:
-             memcpy(data, ice_gstrings_test, ICE_TEST_LEN * ETH_GSTRING_LEN);

drivers/net/ethernet/intel/ice/ice_ethtool.c static void · line 1533

Quoted 10 lines
drivers/net/ethernet/intel/ice/ice_ethtool.c +3 -1
+             for (i = 0; i < ICE_TEST_LEN; i++)
+                     ethtool_puts(&data, ice_gstrings_test[i]);
               break;
       case ETH_SS_PRIV_FLAGS:
               for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++)
-                     ethtool_puts(&p, ice_gstrings_priv_flags[i].name);
+                     ethtool_puts(&data, ice_gstrings_priv_flags[i].name);
               break;
       default:
               break;

really no need to git-blame touch most of the code here>

Quoted 7 lines
Quoted 2 lines

Actually the function should be taking a double pointer here I think in case something gets called after it in the main function.

I mean that both @p and @data are (u8 *).
I'm fine getting rid of tmp var, and updating the originally passed argument is fine. But you could achieve it by just changing param name.

BTW I guess it was @p to fit into 80 chars more easily ;)

Yeah I think so too.