netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/3] ethtool: Add ethtool_puts()
@ 2023-10-25 23:40 Justin Stitt
  2023-10-25 23:40 ` [PATCH 1/3] ethtool: Implement ethtool_puts() Justin Stitt
                   ` (3 more replies)
  0 siblings, 4 replies; 19+ messages in thread
From: Justin Stitt @ 2023-10-25 23:40 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Shay Agroskin, Arthur Kiyanovski, David Arinzon, Noam Dagan,
	Saeed Bishara, Rasesh Mody, Sudarsana Kalluru, GR-Linux-NIC-Dev,
	Dimitris Michailidis, Yisen Zhuang, Salil Mehta, Jesse Brandeburg,
	Tony Nguyen, Louis Peens, Shannon Nelson, Brett Creeley, drivers,
	K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Ronak Doshi,
	VMware PV-Drivers Reviewers, Andy Whitcroft, Joe Perches,
	Dwaipayan Ray, Lukas Bulwahn
  Cc: linux-kernel, netdev, Nick Desaulniers, Nathan Chancellor,
	Kees Cook, intel-wired-lan, oss-drivers, linux-hyperv,
	Justin Stitt

Hi,

This series aims to implement ethtool_puts() and send out a wave 1 of
conversions from ethtool_sprintf(). There's also a checkpatch patch
included to check for the cases listed below.

This was sparked from recent discussion here [1]

The conversions are used in cases where ethtool_sprintf() was being used
with just two arguments:
|       ethtool_sprintf(&data, buffer[i].name);
or when it's used with format string: "%s"
|       ethtool_sprintf(&data, "%s", buffer[i].name);
which both now become:
|       ethtool_puts(&data, buffer[i].name);

The first case commonly triggers a -Wformat-security warning with Clang
due to potential problems with format flags present in the strings [3].

The second is just a bit weird with a plain-ol' "%s".

Note that I have some outstanding patches [2] (some picked up) that use
the second case of ethtool_sprintf(). I went with this approach to clean
up some strncpy() uses and avoid -Wformat-security warnings before
discussion about implementing ...puts() arose. I will probably let the
ones that have been picked up land but send new versions for others.

Wave 1 changes found with Cocci [4] and grep [5].

[1]: https://lore.kernel.org/all/202310141935.B326C9E@keescook/
[2]: https://lore.kernel.org/all/?q=dfb%3Aethtool_sprintf+AND+f%3Ajustinstitt
[3]: https://lore.kernel.org/all/202310101528.9496539BE@keescook/
[4]: (script authored by Kees)
@replace_2_args@
identifier BUF;
expression VAR;
@@

-       ethtool_sprintf
+       ethtool_puts
        (&BUF, VAR)

@replace_3_args@
identifier BUF;
expression VAR;
@@

-       ethtool_sprintf(&BUF, "%s", VAR)
+       ethtool_puts(&BUF, VAR)
[5]: $ rg "ethtool_sprintf\(\s*[^,)]+\s*,\s*[^,)]+\s*\)"

Signed-off-by: Justin Stitt <justinstitt@google.com>
---
Justin Stitt (3):
      ethtool: Implement ethtool_puts()
      treewide: Convert some ethtool_sprintf() to ethtool_puts()
      checkpatch: add ethtool_sprintf rules

 drivers/net/ethernet/amazon/ena/ena_ethtool.c      |  4 +-
 drivers/net/ethernet/brocade/bna/bnad_ethtool.c    |  2 +-
 .../net/ethernet/fungible/funeth/funeth_ethtool.c  |  8 +--
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c |  2 +-
 .../net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c    |  2 +-
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c   | 66 +++++++++++-----------
 drivers/net/ethernet/intel/i40e/i40e_ethtool.c     |  4 +-
 drivers/net/ethernet/intel/ice/ice_ethtool.c       | 10 ++--
 drivers/net/ethernet/intel/igb/igb_ethtool.c       |  6 +-
 drivers/net/ethernet/intel/igc/igc_ethtool.c       |  6 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c   |  5 +-
 .../net/ethernet/netronome/nfp/nfp_net_ethtool.c   | 44 +++++++--------
 drivers/net/ethernet/pensando/ionic/ionic_stats.c  |  4 +-
 drivers/net/hyperv/netvsc_drv.c                    |  4 +-
 drivers/net/vmxnet3/vmxnet3_ethtool.c              | 10 ++--
 include/linux/ethtool.h                            | 13 +++++
 net/ethtool/ioctl.c                                |  7 +++
 scripts/checkpatch.pl                              | 13 +++++
 18 files changed, 120 insertions(+), 90 deletions(-)
---
base-commit: d88520ad73b79e71e3ddf08de335b8520ae41c5c
change-id: 20231025-ethtool_puts_impl-a1479ffbc7e0

Best regards,
--
Justin Stitt <justinstitt@google.com>


^ permalink raw reply	[flat|nested] 19+ messages in thread

* [PATCH 1/3] ethtool: Implement ethtool_puts()
  2023-10-25 23:40 [PATCH 0/3] ethtool: Add ethtool_puts() Justin Stitt
@ 2023-10-25 23:40 ` Justin Stitt
  2023-10-25 23:40 ` [PATCH 2/3] treewide: Convert some ethtool_sprintf() to ethtool_puts() Justin Stitt
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 19+ messages in thread
From: Justin Stitt @ 2023-10-25 23:40 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Shay Agroskin, Arthur Kiyanovski, David Arinzon, Noam Dagan,
	Saeed Bishara, Rasesh Mody, Sudarsana Kalluru, GR-Linux-NIC-Dev,
	Dimitris Michailidis, Yisen Zhuang, Salil Mehta, Jesse Brandeburg,
	Tony Nguyen, Louis Peens, Shannon Nelson, Brett Creeley, drivers,
	K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Ronak Doshi,
	VMware PV-Drivers Reviewers, Andy Whitcroft, Joe Perches,
	Dwaipayan Ray, Lukas Bulwahn
  Cc: linux-kernel, netdev, Nick Desaulniers, Nathan Chancellor,
	Kees Cook, intel-wired-lan, oss-drivers, linux-hyperv,
	Justin Stitt

Use strscpy() to implement ethtool_puts().

Functionally the same as ethtool_sprintf() when it's used with two
arguments or with just "%s" format specifier.

Signed-off-by: Justin Stitt <justinstitt@google.com>
---
 include/linux/ethtool.h | 13 +++++++++++++
 net/ethtool/ioctl.c     |  7 +++++++
 2 files changed, 20 insertions(+)

diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h
index 62b61527bcc4..fdd65050bf1b 100644
--- a/include/linux/ethtool.h
+++ b/include/linux/ethtool.h
@@ -1052,4 +1052,17 @@ static inline int ethtool_mm_frag_size_min_to_add(u32 val_min, u32 *val_add,
  * next string.
  */
 extern __printf(2, 3) void ethtool_sprintf(u8 **data, const char *fmt, ...);
+
+/**
+ * ethtool_puts - Write string to ethtool string data
+ * @data: Pointer to start of string to update
+ * @str: String to write
+ *
+ * Write string to data. Update data to point at start of next
+ * string.
+ *
+ * Prefer this function to ethtool_sprintf() when given only
+ * two arguments or if @fmt is just "%s".
+ */
+extern void ethtool_puts(u8 **data, const char *str);
 #endif /* _LINUX_ETHTOOL_H */
diff --git a/net/ethtool/ioctl.c b/net/ethtool/ioctl.c
index 0b0ce4f81c01..abdf05edf804 100644
--- a/net/ethtool/ioctl.c
+++ b/net/ethtool/ioctl.c
@@ -1991,6 +1991,13 @@ __printf(2, 3) void ethtool_sprintf(u8 **data, const char *fmt, ...)
 }
 EXPORT_SYMBOL(ethtool_sprintf);
 
+void ethtool_puts(u8 **data, const char *str)
+{
+	strscpy(*data, str, ETH_GSTRING_LEN);
+	*data += ETH_GSTRING_LEN;
+}
+EXPORT_SYMBOL(ethtool_puts);
+
 static int ethtool_phys_id(struct net_device *dev, void __user *useraddr)
 {
 	struct ethtool_value id;

-- 
2.42.0.758.gaed0368e0e-goog


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 2/3] treewide: Convert some ethtool_sprintf() to ethtool_puts()
  2023-10-25 23:40 [PATCH 0/3] ethtool: Add ethtool_puts() Justin Stitt
  2023-10-25 23:40 ` [PATCH 1/3] ethtool: Implement ethtool_puts() Justin Stitt
@ 2023-10-25 23:40 ` Justin Stitt
  2023-10-25 23:51   ` Joe Perches
                     ` (3 more replies)
  2023-10-25 23:40 ` [PATCH 3/3] checkpatch: add ethtool_sprintf rules Justin Stitt
  2023-10-26 15:47 ` [PATCH 0/3] ethtool: Add ethtool_puts() Kees Cook
  3 siblings, 4 replies; 19+ messages in thread
From: Justin Stitt @ 2023-10-25 23:40 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Shay Agroskin, Arthur Kiyanovski, David Arinzon, Noam Dagan,
	Saeed Bishara, Rasesh Mody, Sudarsana Kalluru, GR-Linux-NIC-Dev,
	Dimitris Michailidis, Yisen Zhuang, Salil Mehta, Jesse Brandeburg,
	Tony Nguyen, Louis Peens, Shannon Nelson, Brett Creeley, drivers,
	K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Ronak Doshi,
	VMware PV-Drivers Reviewers, Andy Whitcroft, Joe Perches,
	Dwaipayan Ray, Lukas Bulwahn
  Cc: linux-kernel, netdev, Nick Desaulniers, Nathan Chancellor,
	Kees Cook, intel-wired-lan, oss-drivers, linux-hyperv,
	Justin Stitt

This patch converts some basic cases of ethtool_sprintf() to
ethtool_puts().

The conversions are used in cases where ethtool_sprintf() was being used
with just two arguments:
|       ethtool_sprintf(&data, buffer[i].name);
or when it's used with format string: "%s"
|       ethtool_sprintf(&data, "%s", buffer[i].name);
which both now become:
|       ethtool_puts(&data, buffer[i].name);

There are some outstanding patches [1] that I've sent using plain "%s"
with ethtool_sprintf() that should be ethtool_puts() now. Some have been
picked up as-is but I will send new versions for the others.

[1]: https://lore.kernel.org/all/?q=dfb%3Aethtool_sprintf+AND+f%3Ajustinstitt

Signed-off-by: Justin Stitt <justinstitt@google.com>
---
 drivers/net/ethernet/amazon/ena/ena_ethtool.c      |  4 +-
 drivers/net/ethernet/brocade/bna/bnad_ethtool.c    |  2 +-
 .../net/ethernet/fungible/funeth/funeth_ethtool.c  |  8 +--
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c |  2 +-
 .../net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c    |  2 +-
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c   | 66 +++++++++++-----------
 drivers/net/ethernet/intel/i40e/i40e_ethtool.c     |  4 +-
 drivers/net/ethernet/intel/ice/ice_ethtool.c       | 10 ++--
 drivers/net/ethernet/intel/igb/igb_ethtool.c       |  6 +-
 drivers/net/ethernet/intel/igc/igc_ethtool.c       |  6 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c   |  5 +-
 .../net/ethernet/netronome/nfp/nfp_net_ethtool.c   | 44 +++++++--------
 drivers/net/ethernet/pensando/ionic/ionic_stats.c  |  4 +-
 drivers/net/hyperv/netvsc_drv.c                    |  4 +-
 drivers/net/vmxnet3/vmxnet3_ethtool.c              | 10 ++--
 15 files changed, 87 insertions(+), 90 deletions(-)

diff --git a/drivers/net/ethernet/amazon/ena/ena_ethtool.c b/drivers/net/ethernet/amazon/ena/ena_ethtool.c
index d671df4b76bc..e3ef081aa42b 100644
--- a/drivers/net/ethernet/amazon/ena/ena_ethtool.c
+++ b/drivers/net/ethernet/amazon/ena/ena_ethtool.c
@@ -299,13 +299,13 @@ static void ena_get_strings(struct ena_adapter *adapter,
 
 	for (i = 0; i < ENA_STATS_ARRAY_GLOBAL; i++) {
 		ena_stats = &ena_stats_global_strings[i];
-		ethtool_sprintf(&data, ena_stats->name);
+		ethtool_puts(&data, ena_stats->name);
 	}
 
 	if (eni_stats_needed) {
 		for (i = 0; i < ENA_STATS_ARRAY_ENI(adapter); i++) {
 			ena_stats = &ena_stats_eni_strings[i];
-			ethtool_sprintf(&data, ena_stats->name);
+			ethtool_puts(&data, ena_stats->name);
 		}
 	}
 
diff --git a/drivers/net/ethernet/brocade/bna/bnad_ethtool.c b/drivers/net/ethernet/brocade/bna/bnad_ethtool.c
index df10edff5603..d1ad6c9f8140 100644
--- a/drivers/net/ethernet/brocade/bna/bnad_ethtool.c
+++ b/drivers/net/ethernet/brocade/bna/bnad_ethtool.c
@@ -608,7 +608,7 @@ bnad_get_strings(struct net_device *netdev, u32 stringset, u8 *string)
 
 	for (i = 0; i < BNAD_ETHTOOL_STATS_NUM; i++) {
 		BUG_ON(!(strlen(bnad_net_stats_strings[i]) < ETH_GSTRING_LEN));
-		ethtool_sprintf(&string, bnad_net_stats_strings[i]);
+		ethtool_puts(&string, bnad_net_stats_strings[i]);
 	}
 
 	bmap = bna_tx_rid_mask(&bnad->bna);
diff --git a/drivers/net/ethernet/fungible/funeth/funeth_ethtool.c b/drivers/net/ethernet/fungible/funeth/funeth_ethtool.c
index 31aa185f4d17..091c93bd7587 100644
--- a/drivers/net/ethernet/fungible/funeth/funeth_ethtool.c
+++ b/drivers/net/ethernet/fungible/funeth/funeth_ethtool.c
@@ -655,7 +655,7 @@ static void fun_get_strings(struct net_device *netdev, u32 sset, u8 *data)
 						i);
 		}
 		for (j = 0; j < ARRAY_SIZE(txq_stat_names); j++)
-			ethtool_sprintf(&p, txq_stat_names[j]);
+			ethtool_puts(&p, txq_stat_names[j]);
 
 		for (i = 0; i < fp->num_xdpqs; i++) {
 			for (j = 0; j < ARRAY_SIZE(xdpq_stat_names); j++)
@@ -663,7 +663,7 @@ static void fun_get_strings(struct net_device *netdev, u32 sset, u8 *data)
 						xdpq_stat_names[j], i);
 		}
 		for (j = 0; j < ARRAY_SIZE(xdpq_stat_names); j++)
-			ethtool_sprintf(&p, xdpq_stat_names[j]);
+			ethtool_puts(&p, xdpq_stat_names[j]);
 
 		for (i = 0; i < netdev->real_num_rx_queues; i++) {
 			for (j = 0; j < ARRAY_SIZE(rxq_stat_names); j++)
@@ -671,10 +671,10 @@ static void fun_get_strings(struct net_device *netdev, u32 sset, u8 *data)
 						i);
 		}
 		for (j = 0; j < ARRAY_SIZE(rxq_stat_names); j++)
-			ethtool_sprintf(&p, rxq_stat_names[j]);
+			ethtool_puts(&p, rxq_stat_names[j]);
 
 		for (j = 0; j < ARRAY_SIZE(tls_stat_names); j++)
-			ethtool_sprintf(&p, tls_stat_names[j]);
+			ethtool_puts(&p, tls_stat_names[j]);
 		break;
 	default:
 		break;
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
index 8f391e2adcc0..bdb7afaabdd0 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
@@ -678,7 +678,7 @@ static void hns_gmac_get_strings(u32 stringset, u8 *data)
 		return;
 
 	for (i = 0; i < ARRAY_SIZE(g_gmac_stats_string); i++)
-		ethtool_sprintf(&buff, g_gmac_stats_string[i].desc);
+		ethtool_puts(&buff, g_gmac_stats_string[i].desc);
 }
 
 static int hns_gmac_get_sset_count(int stringset)
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c
index fc26ffaae620..c58833eb4830 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c
@@ -752,7 +752,7 @@ static void hns_xgmac_get_strings(u32 stringset, u8 *data)
 		return;
 
 	for (i = 0; i < ARRAY_SIZE(g_xgmac_stats_string); i++)
-		ethtool_sprintf(&buff, g_xgmac_stats_string[i].desc);
+		ethtool_puts(&buff, g_xgmac_stats_string[i].desc);
 }
 
 /**
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
index b54f3706fb97..b40415910e57 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
@@ -912,42 +912,42 @@ static void hns_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
 
 	if (stringset == ETH_SS_TEST) {
 		if (priv->ae_handle->phy_if != PHY_INTERFACE_MODE_XGMII)
-			ethtool_sprintf(&buff,
-					hns_nic_test_strs[MAC_INTERNALLOOP_MAC]);
-		ethtool_sprintf(&buff,
-				hns_nic_test_strs[MAC_INTERNALLOOP_SERDES]);
+			ethtool_puts(&buff,
+				     hns_nic_test_strs[MAC_INTERNALLOOP_MAC]);
+		ethtool_puts(&buff,
+			     hns_nic_test_strs[MAC_INTERNALLOOP_SERDES]);
 		if ((netdev->phydev) && (!netdev->phydev->is_c45))
-			ethtool_sprintf(&buff,
-					hns_nic_test_strs[MAC_INTERNALLOOP_PHY]);
+			ethtool_puts(&buff,
+				     hns_nic_test_strs[MAC_INTERNALLOOP_PHY]);
 
 	} else {
-		ethtool_sprintf(&buff, "rx_packets");
-		ethtool_sprintf(&buff, "tx_packets");
-		ethtool_sprintf(&buff, "rx_bytes");
-		ethtool_sprintf(&buff, "tx_bytes");
-		ethtool_sprintf(&buff, "rx_errors");
-		ethtool_sprintf(&buff, "tx_errors");
-		ethtool_sprintf(&buff, "rx_dropped");
-		ethtool_sprintf(&buff, "tx_dropped");
-		ethtool_sprintf(&buff, "multicast");
-		ethtool_sprintf(&buff, "collisions");
-		ethtool_sprintf(&buff, "rx_over_errors");
-		ethtool_sprintf(&buff, "rx_crc_errors");
-		ethtool_sprintf(&buff, "rx_frame_errors");
-		ethtool_sprintf(&buff, "rx_fifo_errors");
-		ethtool_sprintf(&buff, "rx_missed_errors");
-		ethtool_sprintf(&buff, "tx_aborted_errors");
-		ethtool_sprintf(&buff, "tx_carrier_errors");
-		ethtool_sprintf(&buff, "tx_fifo_errors");
-		ethtool_sprintf(&buff, "tx_heartbeat_errors");
-		ethtool_sprintf(&buff, "rx_length_errors");
-		ethtool_sprintf(&buff, "tx_window_errors");
-		ethtool_sprintf(&buff, "rx_compressed");
-		ethtool_sprintf(&buff, "tx_compressed");
-		ethtool_sprintf(&buff, "netdev_rx_dropped");
-		ethtool_sprintf(&buff, "netdev_tx_dropped");
-
-		ethtool_sprintf(&buff, "netdev_tx_timeout");
+		ethtool_puts(&buff, "rx_packets");
+		ethtool_puts(&buff, "tx_packets");
+		ethtool_puts(&buff, "rx_bytes");
+		ethtool_puts(&buff, "tx_bytes");
+		ethtool_puts(&buff, "rx_errors");
+		ethtool_puts(&buff, "tx_errors");
+		ethtool_puts(&buff, "rx_dropped");
+		ethtool_puts(&buff, "tx_dropped");
+		ethtool_puts(&buff, "multicast");
+		ethtool_puts(&buff, "collisions");
+		ethtool_puts(&buff, "rx_over_errors");
+		ethtool_puts(&buff, "rx_crc_errors");
+		ethtool_puts(&buff, "rx_frame_errors");
+		ethtool_puts(&buff, "rx_fifo_errors");
+		ethtool_puts(&buff, "rx_missed_errors");
+		ethtool_puts(&buff, "tx_aborted_errors");
+		ethtool_puts(&buff, "tx_carrier_errors");
+		ethtool_puts(&buff, "tx_fifo_errors");
+		ethtool_puts(&buff, "tx_heartbeat_errors");
+		ethtool_puts(&buff, "rx_length_errors");
+		ethtool_puts(&buff, "tx_window_errors");
+		ethtool_puts(&buff, "rx_compressed");
+		ethtool_puts(&buff, "tx_compressed");
+		ethtool_puts(&buff, "netdev_rx_dropped");
+		ethtool_puts(&buff, "netdev_tx_dropped");
+
+		ethtool_puts(&buff, "netdev_tx_timeout");
 
 		h->dev->ops->get_strings(h, stringset, buff);
 	}
diff --git a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
index bd1321bf7e26..2641b2a4fcb0 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
@@ -2512,11 +2512,11 @@ static void i40e_get_priv_flag_strings(struct net_device *netdev, u8 *data)
 	u8 *p = data;
 
 	for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++)
-		ethtool_sprintf(&p, i40e_gstrings_priv_flags[i].flag_string);
+		ethtool_puts(&p, i40e_gstrings_priv_flags[i].flag_string);
 	if (pf->hw.pf_id != 0)
 		return;
 	for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++)
-		ethtool_sprintf(&p, i40e_gl_gstrings_priv_flags[i].flag_string);
+		ethtool_puts(&p, i40e_gl_gstrings_priv_flags[i].flag_string);
 }
 
 static void i40e_get_strings(struct net_device *netdev, u32 stringset,
diff --git a/drivers/net/ethernet/intel/ice/ice_ethtool.c b/drivers/net/ethernet/intel/ice/ice_ethtool.c
index ad4d4702129f..7871bba4b099 100644
--- a/drivers/net/ethernet/intel/ice/ice_ethtool.c
+++ b/drivers/net/ethernet/intel/ice/ice_ethtool.c
@@ -1060,8 +1060,8 @@ __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,
 	switch (stringset) {
 	case ETH_SS_STATS:
 		for (i = 0; i < ICE_VSI_STATS_LEN; i++)
-			ethtool_sprintf(&p,
-					ice_gstrings_vsi_stats[i].stat_string);
+			ethtool_puts(&p,
+				     ice_gstrings_vsi_stats[i].stat_string);
 
 		if (ice_is_port_repr_netdev(netdev))
 			return;
@@ -1080,8 +1080,8 @@ __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,
 			return;
 
 		for (i = 0; i < ICE_PF_STATS_LEN; i++)
-			ethtool_sprintf(&p,
-					ice_gstrings_pf_stats[i].stat_string);
+			ethtool_puts(&p,
+				     ice_gstrings_pf_stats[i].stat_string);
 
 		for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
 			ethtool_sprintf(&p, "tx_priority_%u_xon.nic", i);
@@ -1097,7 +1097,7 @@ __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,
 		break;
 	case ETH_SS_PRIV_FLAGS:
 		for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++)
-			ethtool_sprintf(&p, ice_gstrings_priv_flags[i].name);
+			ethtool_puts(&p, ice_gstrings_priv_flags[i].name);
 		break;
 	default:
 		break;
diff --git a/drivers/net/ethernet/intel/igb/igb_ethtool.c b/drivers/net/ethernet/intel/igb/igb_ethtool.c
index 319ed601eaa1..e0a24c7c37f9 100644
--- a/drivers/net/ethernet/intel/igb/igb_ethtool.c
+++ b/drivers/net/ethernet/intel/igb/igb_ethtool.c
@@ -2356,11 +2356,9 @@ static void igb_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
 		break;
 	case ETH_SS_STATS:
 		for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++)
-			ethtool_sprintf(&p,
-					igb_gstrings_stats[i].stat_string);
+			ethtool_puts(&p, igb_gstrings_stats[i].stat_string);
 		for (i = 0; i < IGB_NETDEV_STATS_LEN; i++)
-			ethtool_sprintf(&p,
-					igb_gstrings_net_stats[i].stat_string);
+			ethtool_puts(&p, igb_gstrings_net_stats[i].stat_string);
 		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);
diff --git a/drivers/net/ethernet/intel/igc/igc_ethtool.c b/drivers/net/ethernet/intel/igc/igc_ethtool.c
index 7ab6dd58e400..2aac55ebdf5a 100644
--- a/drivers/net/ethernet/intel/igc/igc_ethtool.c
+++ b/drivers/net/ethernet/intel/igc/igc_ethtool.c
@@ -773,10 +773,10 @@ static void igc_ethtool_get_strings(struct net_device *netdev, u32 stringset,
 		break;
 	case ETH_SS_STATS:
 		for (i = 0; i < IGC_GLOBAL_STATS_LEN; i++)
-			ethtool_sprintf(&p, igc_gstrings_stats[i].stat_string);
+			ethtool_puts(&p, igc_gstrings_stats[i].stat_string);
 		for (i = 0; i < IGC_NETDEV_STATS_LEN; i++)
-			ethtool_sprintf(&p,
-					igc_gstrings_net_stats[i].stat_string);
+			ethtool_puts(&p,
+				     igc_gstrings_net_stats[i].stat_string);
 		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);
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
index 0bbad4a5cc2f..dd722b0381e0 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
@@ -1413,12 +1413,11 @@ static void ixgbe_get_strings(struct net_device *netdev, u32 stringset,
 	switch (stringset) {
 	case ETH_SS_TEST:
 		for (i = 0; i < IXGBE_TEST_LEN; i++)
-			ethtool_sprintf(&p, ixgbe_gstrings_test[i]);
+			ethtool_puts(&p, ixgbe_gstrings_test[i]);
 		break;
 	case ETH_SS_STATS:
 		for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++)
-			ethtool_sprintf(&p,
-					ixgbe_gstrings_stats[i].stat_string);
+			ethtool_puts(&p, ixgbe_gstrings_stats[i].stat_string);
 		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);
diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c b/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
index e75cbb287625..1636ce61a3c0 100644
--- a/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
+++ b/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
@@ -800,7 +800,7 @@ static void nfp_get_self_test_strings(struct net_device *netdev, u8 *data)
 
 	for (i = 0; i < NFP_TEST_TOTAL_NUM; i++)
 		if (nfp_self_test[i].is_supported(netdev))
-			ethtool_sprintf(&data, nfp_self_test[i].name);
+			ethtool_puts(&data, nfp_self_test[i].name);
 }
 
 static int nfp_get_self_test_count(struct net_device *netdev)
@@ -852,24 +852,24 @@ static u8 *nfp_vnic_get_sw_stats_strings(struct net_device *netdev, u8 *data)
 		ethtool_sprintf(&data, "rvec_%u_tx_busy", i);
 	}
 
-	ethtool_sprintf(&data, "hw_rx_csum_ok");
-	ethtool_sprintf(&data, "hw_rx_csum_inner_ok");
-	ethtool_sprintf(&data, "hw_rx_csum_complete");
-	ethtool_sprintf(&data, "hw_rx_csum_err");
-	ethtool_sprintf(&data, "rx_replace_buf_alloc_fail");
-	ethtool_sprintf(&data, "rx_tls_decrypted_packets");
-	ethtool_sprintf(&data, "hw_tx_csum");
-	ethtool_sprintf(&data, "hw_tx_inner_csum");
-	ethtool_sprintf(&data, "tx_gather");
-	ethtool_sprintf(&data, "tx_lso");
-	ethtool_sprintf(&data, "tx_tls_encrypted_packets");
-	ethtool_sprintf(&data, "tx_tls_ooo");
-	ethtool_sprintf(&data, "tx_tls_drop_no_sync_data");
-
-	ethtool_sprintf(&data, "hw_tls_no_space");
-	ethtool_sprintf(&data, "rx_tls_resync_req_ok");
-	ethtool_sprintf(&data, "rx_tls_resync_req_ign");
-	ethtool_sprintf(&data, "rx_tls_resync_sent");
+	ethtool_puts(&data, "hw_rx_csum_ok");
+	ethtool_puts(&data, "hw_rx_csum_inner_ok");
+	ethtool_puts(&data, "hw_rx_csum_complete");
+	ethtool_puts(&data, "hw_rx_csum_err");
+	ethtool_puts(&data, "rx_replace_buf_alloc_fail");
+	ethtool_puts(&data, "rx_tls_decrypted_packets");
+	ethtool_puts(&data, "hw_tx_csum");
+	ethtool_puts(&data, "hw_tx_inner_csum");
+	ethtool_puts(&data, "tx_gather");
+	ethtool_puts(&data, "tx_lso");
+	ethtool_puts(&data, "tx_tls_encrypted_packets");
+	ethtool_puts(&data, "tx_tls_ooo");
+	ethtool_puts(&data, "tx_tls_drop_no_sync_data");
+
+	ethtool_puts(&data, "hw_tls_no_space");
+	ethtool_puts(&data, "rx_tls_resync_req_ok");
+	ethtool_puts(&data, "rx_tls_resync_req_ign");
+	ethtool_puts(&data, "rx_tls_resync_sent");
 
 	return data;
 }
@@ -943,13 +943,13 @@ nfp_vnic_get_hw_stats_strings(u8 *data, unsigned int num_vecs, bool repr)
 	swap_off = repr * NN_ET_SWITCH_STATS_LEN;
 
 	for (i = 0; i < NN_ET_SWITCH_STATS_LEN; i++)
-		ethtool_sprintf(&data, nfp_net_et_stats[i + swap_off].name);
+		ethtool_puts(&data, nfp_net_et_stats[i + swap_off].name);
 
 	for (i = NN_ET_SWITCH_STATS_LEN; i < NN_ET_SWITCH_STATS_LEN * 2; i++)
-		ethtool_sprintf(&data, nfp_net_et_stats[i - swap_off].name);
+		ethtool_puts(&data, nfp_net_et_stats[i - swap_off].name);
 
 	for (i = NN_ET_SWITCH_STATS_LEN * 2; i < NN_ET_GLOBAL_STATS_LEN; i++)
-		ethtool_sprintf(&data, nfp_net_et_stats[i].name);
+		ethtool_puts(&data, nfp_net_et_stats[i].name);
 
 	for (i = 0; i < num_vecs; i++) {
 		ethtool_sprintf(&data, "rxq_%u_pkts", i);
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_stats.c b/drivers/net/ethernet/pensando/ionic/ionic_stats.c
index 9859a4432985..1f6022fb7679 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_stats.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_stats.c
@@ -258,10 +258,10 @@ static void ionic_sw_stats_get_strings(struct ionic_lif *lif, u8 **buf)
 	int i, q_num;
 
 	for (i = 0; i < IONIC_NUM_LIF_STATS; i++)
-		ethtool_sprintf(buf, ionic_lif_stats_desc[i].name);
+		ethtool_puts(buf, ionic_lif_stats_desc[i].name);
 
 	for (i = 0; i < IONIC_NUM_PORT_STATS; i++)
-		ethtool_sprintf(buf, ionic_port_stats_desc[i].name);
+		ethtool_puts(buf, ionic_port_stats_desc[i].name);
 
 	for (q_num = 0; q_num < MAX_Q(lif); q_num++)
 		ionic_sw_stats_get_tx_strings(lif, buf, q_num);
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 3ba3c8fb28a5..cbd9405fc2f3 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -1582,10 +1582,10 @@ static void netvsc_get_strings(struct net_device *dev, u32 stringset, u8 *data)
 	switch (stringset) {
 	case ETH_SS_STATS:
 		for (i = 0; i < ARRAY_SIZE(netvsc_stats); i++)
-			ethtool_sprintf(&p, netvsc_stats[i].name);
+			ethtool_puts(&p, netvsc_stats[i].name);
 
 		for (i = 0; i < ARRAY_SIZE(vf_stats); i++)
-			ethtool_sprintf(&p, vf_stats[i].name);
+			ethtool_puts(&p, vf_stats[i].name);
 
 		for (i = 0; i < nvdev->num_chn; i++) {
 			ethtool_sprintf(&p, "tx_queue_%u_packets", i);
diff --git a/drivers/net/vmxnet3/vmxnet3_ethtool.c b/drivers/net/vmxnet3/vmxnet3_ethtool.c
index 98c22d7d87a2..8f5f202cde39 100644
--- a/drivers/net/vmxnet3/vmxnet3_ethtool.c
+++ b/drivers/net/vmxnet3/vmxnet3_ethtool.c
@@ -245,20 +245,20 @@ vmxnet3_get_strings(struct net_device *netdev, u32 stringset, u8 *buf)
 
 	for (j = 0; j < adapter->num_tx_queues; j++) {
 		for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++)
-			ethtool_sprintf(&buf, vmxnet3_tq_dev_stats[i].desc);
+			ethtool_puts(&buf, vmxnet3_tq_dev_stats[i].desc);
 		for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats); i++)
-			ethtool_sprintf(&buf, vmxnet3_tq_driver_stats[i].desc);
+			ethtool_puts(&buf, vmxnet3_tq_driver_stats[i].desc);
 	}
 
 	for (j = 0; j < adapter->num_rx_queues; j++) {
 		for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++)
-			ethtool_sprintf(&buf, vmxnet3_rq_dev_stats[i].desc);
+			ethtool_puts(&buf, vmxnet3_rq_dev_stats[i].desc);
 		for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats); i++)
-			ethtool_sprintf(&buf, vmxnet3_rq_driver_stats[i].desc);
+			ethtool_puts(&buf, vmxnet3_rq_driver_stats[i].desc);
 	}
 
 	for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++)
-		ethtool_sprintf(&buf, vmxnet3_global_stats[i].desc);
+		ethtool_puts(&buf, vmxnet3_global_stats[i].desc);
 }
 
 netdev_features_t vmxnet3_fix_features(struct net_device *netdev,

-- 
2.42.0.758.gaed0368e0e-goog


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* [PATCH 3/3] checkpatch: add ethtool_sprintf rules
  2023-10-25 23:40 [PATCH 0/3] ethtool: Add ethtool_puts() Justin Stitt
  2023-10-25 23:40 ` [PATCH 1/3] ethtool: Implement ethtool_puts() Justin Stitt
  2023-10-25 23:40 ` [PATCH 2/3] treewide: Convert some ethtool_sprintf() to ethtool_puts() Justin Stitt
@ 2023-10-25 23:40 ` Justin Stitt
  2023-10-25 23:52   ` Joe Perches
                     ` (2 more replies)
  2023-10-26 15:47 ` [PATCH 0/3] ethtool: Add ethtool_puts() Kees Cook
  3 siblings, 3 replies; 19+ messages in thread
From: Justin Stitt @ 2023-10-25 23:40 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Shay Agroskin, Arthur Kiyanovski, David Arinzon, Noam Dagan,
	Saeed Bishara, Rasesh Mody, Sudarsana Kalluru, GR-Linux-NIC-Dev,
	Dimitris Michailidis, Yisen Zhuang, Salil Mehta, Jesse Brandeburg,
	Tony Nguyen, Louis Peens, Shannon Nelson, Brett Creeley, drivers,
	K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Ronak Doshi,
	VMware PV-Drivers Reviewers, Andy Whitcroft, Joe Perches,
	Dwaipayan Ray, Lukas Bulwahn
  Cc: linux-kernel, netdev, Nick Desaulniers, Nathan Chancellor,
	Kees Cook, intel-wired-lan, oss-drivers, linux-hyperv,
	Justin Stitt

Add some warnings for using ethtool_sprintf() where a simple
ethtool_puts() would suffice.

The two cases are:

1) Use ethtool_sprintf() with just two arguments:
|       ethtool_sprintf(&data, driver[i].name);
or
2) Use ethtool_sprintf() with a standalone "%s" fmt string:
|       ethtool_sprintf(&data, "%s", driver[i].name);

The former may cause -Wformat-security warnings while the latter is just
not preferred. Both are safely in the category of warnings, not errors.

Signed-off-by: Justin Stitt <justinstitt@google.com>
---
 scripts/checkpatch.pl | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 7d16f863edf1..1ba9ce778746 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -7020,6 +7020,19 @@ sub process {
 			     "Prefer strscpy, strscpy_pad, or __nonstring over strncpy - see: https://github.com/KSPP/linux/issues/90\n" . $herecurr);
 		}
 
+# ethtool_sprintf uses that should likely be ethtool_puts
+		if (   $line =~ /\bethtool_sprintf\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\)/   ) {
+			WARN("ETHTOOL_SPRINTF",
+			     "Prefer ethtool_puts over ethtool_sprintf with only two arguments" . $herecurr);
+		}
+
+		# use $rawline because $line loses %s via sanitization and thus we can't match against it.
+		if (   $rawline =~ /\bethtool_sprintf\s*\(\s*$FuncArg\s*,\s*\"\%s\"\s*,\s*$FuncArg\s*\)/   ) {
+			WARN("ETHTOOL_SPRINTF2",
+			     "Prefer ethtool_puts over ethtool_sprintf with standalone \"%s\" specifier" . $herecurr);
+		}
+
+
 # typecasts on min/max could be min_t/max_t
 		if ($perl_version_ok &&
 		    defined $stat &&

-- 
2.42.0.758.gaed0368e0e-goog


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/3] treewide: Convert some ethtool_sprintf() to ethtool_puts()
  2023-10-25 23:40 ` [PATCH 2/3] treewide: Convert some ethtool_sprintf() to ethtool_puts() Justin Stitt
@ 2023-10-25 23:51   ` Joe Perches
  2023-10-25 23:59     ` Justin Stitt
  2023-10-26  9:23   ` Przemek Kitszel
                     ` (2 subsequent siblings)
  3 siblings, 1 reply; 19+ messages in thread
From: Joe Perches @ 2023-10-25 23:51 UTC (permalink / raw)
  To: Justin Stitt, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Shay Agroskin, Arthur Kiyanovski, David Arinzon,
	Noam Dagan, Saeed Bishara, Rasesh Mody, Sudarsana Kalluru,
	GR-Linux-NIC-Dev, Dimitris Michailidis, Yisen Zhuang, Salil Mehta,
	Jesse Brandeburg, Tony Nguyen, Louis Peens, Shannon Nelson,
	Brett Creeley, drivers, K. Y. Srinivasan, Haiyang Zhang, Wei Liu,
	Dexuan Cui, Ronak Doshi, VMware PV-Drivers Reviewers,
	Andy Whitcroft, Dwaipayan Ray, Lukas Bulwahn
  Cc: linux-kernel, netdev, Nick Desaulniers, Nathan Chancellor,
	Kees Cook, intel-wired-lan, oss-drivers, linux-hyperv

On Wed, 2023-10-25 at 23:40 +0000, Justin Stitt wrote:
> This patch converts some basic cases of ethtool_sprintf() to
> ethtool_puts().
> 
> The conversions are used in cases where ethtool_sprintf() was being used
> with just two arguments:
> >       ethtool_sprintf(&data, buffer[i].name);

OK.

> or when it's used with format string: "%s"
> >       ethtool_sprintf(&data, "%s", buffer[i].name);
> > which both now become:
> >       ethtool_puts(&data, buffer[i].name);

Why do you want this conversion?
Is it not possible for .name to contain a formatting field?


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/3] checkpatch: add ethtool_sprintf rules
  2023-10-25 23:40 ` [PATCH 3/3] checkpatch: add ethtool_sprintf rules Justin Stitt
@ 2023-10-25 23:52   ` Joe Perches
  2023-10-26  9:29   ` Przemek Kitszel
  2023-10-26 17:30   ` Joe Perches
  2 siblings, 0 replies; 19+ messages in thread
From: Joe Perches @ 2023-10-25 23:52 UTC (permalink / raw)
  To: Justin Stitt, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Shay Agroskin, Arthur Kiyanovski, David Arinzon,
	Noam Dagan, Saeed Bishara, Rasesh Mody, Sudarsana Kalluru,
	GR-Linux-NIC-Dev, Dimitris Michailidis, Yisen Zhuang, Salil Mehta,
	Jesse Brandeburg, Tony Nguyen, Louis Peens, Shannon Nelson,
	Brett Creeley, drivers, K. Y. Srinivasan, Haiyang Zhang, Wei Liu,
	Dexuan Cui, Ronak Doshi, VMware PV-Drivers Reviewers,
	Andy Whitcroft, Dwaipayan Ray, Lukas Bulwahn
  Cc: linux-kernel, netdev, Nick Desaulniers, Nathan Chancellor,
	Kees Cook, intel-wired-lan, oss-drivers, linux-hyperv

On Wed, 2023-10-25 at 23:40 +0000, Justin Stitt wrote:
> Add some warnings for using ethtool_sprintf() where a simple
> ethtool_puts() would suffice.
> 
> The two cases are:
> 
> 1) Use ethtool_sprintf() with just two arguments:
> >       ethtool_sprintf(&data, driver[i].name);

OK.

> or
> 2) Use ethtool_sprintf() with a standalone "%s" fmt string:
> >       ethtool_sprintf(&data, "%s", driver[i].name);

I'm rather doubt this is really desired or appropriate.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/3] treewide: Convert some ethtool_sprintf() to ethtool_puts()
  2023-10-25 23:51   ` Joe Perches
@ 2023-10-25 23:59     ` Justin Stitt
  0 siblings, 0 replies; 19+ messages in thread
From: Justin Stitt @ 2023-10-25 23:59 UTC (permalink / raw)
  To: Joe Perches
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Shay Agroskin, Arthur Kiyanovski, David Arinzon, Noam Dagan,
	Saeed Bishara, Rasesh Mody, Sudarsana Kalluru, GR-Linux-NIC-Dev,
	Dimitris Michailidis, Yisen Zhuang, Salil Mehta, Jesse Brandeburg,
	Tony Nguyen, Louis Peens, Shannon Nelson, Brett Creeley, drivers,
	K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Ronak Doshi,
	VMware PV-Drivers Reviewers, Andy Whitcroft, Dwaipayan Ray,
	Lukas Bulwahn, linux-kernel, netdev, Nick Desaulniers,
	Nathan Chancellor, Kees Cook, intel-wired-lan, oss-drivers,
	linux-hyperv

On Wed, Oct 25, 2023 at 4:51 PM Joe Perches <joe@perches.com> wrote:
>
> On Wed, 2023-10-25 at 23:40 +0000, Justin Stitt wrote:
> > This patch converts some basic cases of ethtool_sprintf() to
> > ethtool_puts().
> >
> > The conversions are used in cases where ethtool_sprintf() was being used
> > with just two arguments:
> > >       ethtool_sprintf(&data, buffer[i].name);
>
> OK.
>
> > or when it's used with format string: "%s"
> > >       ethtool_sprintf(&data, "%s", buffer[i].name);
> > > which both now become:
> > >       ethtool_puts(&data, buffer[i].name);
>
> Why do you want this conversion?
> Is it not possible for .name to contain a formatting field?

The case of using just two arguments to a ethtool_sprintf
call may cause -Wformat-security warnings. If it did indeed
have format specifiers then we would have more format
specifiers than arguments. Not ideal.

The second case of having a standalone "%s" isn't
necessarily bad or wrong. I used this exact approach to
replace some strncpy() usage in net drivers [1].

I'm working off guidance from Andrew Lunn [2] and Kees
who said it may be a good idea to tidy this up with a puts().

All in all, this patch doesn't do much but fix some warnings
and provide a more obvious interface. The number of
actual replacements are relatively low (around 20ish) so
I was hoping to sneak them in via this series.

>

[1]: https://lore.kernel.org/all/?q=dfb%3Aethtool_sprintf+AND+f%3Ajustinstitt
[2]: https://lore.kernel.org/all/a958d35e-98b6-4a95-b505-776482d1150c@lunn.ch/

Thanks
Justin

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/3] treewide: Convert some ethtool_sprintf() to ethtool_puts()
  2023-10-25 23:40 ` [PATCH 2/3] treewide: Convert some ethtool_sprintf() to ethtool_puts() Justin Stitt
  2023-10-25 23:51   ` Joe Perches
@ 2023-10-26  9:23   ` Przemek Kitszel
  2023-10-26 10:18     ` Kiyanovski, Arthur
  2023-10-26 14:24     ` Jakub Kicinski
  2023-10-26 14:48   ` Louis Peens
  2023-10-26 16:10   ` Nelson, Shannon
  3 siblings, 2 replies; 19+ messages in thread
From: Przemek Kitszel @ 2023-10-26  9:23 UTC (permalink / raw)
  To: Justin Stitt, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Shay Agroskin, Arthur Kiyanovski, David Arinzon,
	Noam Dagan, Saeed Bishara, Rasesh Mody, Sudarsana Kalluru,
	GR-Linux-NIC-Dev, Dimitris Michailidis, Yisen Zhuang, Salil Mehta,
	Jesse Brandeburg, Tony Nguyen, Louis Peens, Shannon Nelson,
	Brett Creeley, drivers, K. Y. Srinivasan, Haiyang Zhang, Wei Liu,
	Dexuan Cui, Ronak Doshi, VMware PV-Drivers Reviewers,
	Andy Whitcroft, Joe Perches, Dwaipayan Ray, Lukas Bulwahn
  Cc: linux-kernel, netdev, Nick Desaulniers, Nathan Chancellor,
	Kees Cook, intel-wired-lan, oss-drivers, linux-hyperv

On 10/26/23 01:40, Justin Stitt wrote:
> This patch converts some basic cases of ethtool_sprintf() to
> ethtool_puts().
> 
> The conversions are used in cases where ethtool_sprintf() was being used
> with just two arguments:
> |       ethtool_sprintf(&data, buffer[i].name);
> or when it's used with format string: "%s"
> |       ethtool_sprintf(&data, "%s", buffer[i].name);
> which both now become:
> |       ethtool_puts(&data, buffer[i].name);
> 
> There are some outstanding patches [1] that I've sent using plain "%s"
> with ethtool_sprintf() that should be ethtool_puts() now. Some have been
> picked up as-is but I will send new versions for the others.
> 
> [1]: https://lore.kernel.org/all/?q=dfb%3Aethtool_sprintf+AND+f%3Ajustinstitt
> 
> Signed-off-by: Justin Stitt <justinstitt@google.com>
> ---
>   drivers/net/ethernet/amazon/ena/ena_ethtool.c      |  4 +-
>   drivers/net/ethernet/brocade/bna/bnad_ethtool.c    |  2 +-
>   .../net/ethernet/fungible/funeth/funeth_ethtool.c  |  8 +--
>   drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c |  2 +-
>   .../net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c    |  2 +-
>   drivers/net/ethernet/hisilicon/hns/hns_ethtool.c   | 66 +++++++++++-----------
>   drivers/net/ethernet/intel/i40e/i40e_ethtool.c     |  4 +-
>   drivers/net/ethernet/intel/ice/ice_ethtool.c       | 10 ++--
>   drivers/net/ethernet/intel/igb/igb_ethtool.c       |  6 +-
>   drivers/net/ethernet/intel/igc/igc_ethtool.c       |  6 +-
>   drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c   |  5 +-
>   .../net/ethernet/netronome/nfp/nfp_net_ethtool.c   | 44 +++++++--------
>   drivers/net/ethernet/pensando/ionic/ionic_stats.c  |  4 +-
>   drivers/net/hyperv/netvsc_drv.c                    |  4 +-
>   drivers/net/vmxnet3/vmxnet3_ethtool.c              | 10 ++--
>   15 files changed, 87 insertions(+), 90 deletions(-)
> 
> diff --git a/drivers/net/ethernet/amazon/ena/ena_ethtool.c b/drivers/net/ethernet/amazon/ena/ena_ethtool.c
> index d671df4b76bc..e3ef081aa42b 100644
> --- a/drivers/net/ethernet/amazon/ena/ena_ethtool.c
> +++ b/drivers/net/ethernet/amazon/ena/ena_ethtool.c
> @@ -299,13 +299,13 @@ static void ena_get_strings(struct ena_adapter *adapter,
>   
>   	for (i = 0; i < ENA_STATS_ARRAY_GLOBAL; i++) {
>   		ena_stats = &ena_stats_global_strings[i];
> -		ethtool_sprintf(&data, ena_stats->name);
> +		ethtool_puts(&data, ena_stats->name);
>   	}
>   
>   	if (eni_stats_needed) {
>   		for (i = 0; i < ENA_STATS_ARRAY_ENI(adapter); i++) {
>   			ena_stats = &ena_stats_eni_strings[i];
> -			ethtool_sprintf(&data, ena_stats->name);
> +			ethtool_puts(&data, ena_stats->name);
>   		}
>   	}
>   
> diff --git a/drivers/net/ethernet/brocade/bna/bnad_ethtool.c b/drivers/net/ethernet/brocade/bna/bnad_ethtool.c
> index df10edff5603..d1ad6c9f8140 100644
> --- a/drivers/net/ethernet/brocade/bna/bnad_ethtool.c
> +++ b/drivers/net/ethernet/brocade/bna/bnad_ethtool.c
> @@ -608,7 +608,7 @@ bnad_get_strings(struct net_device *netdev, u32 stringset, u8 *string)
>   
>   	for (i = 0; i < BNAD_ETHTOOL_STATS_NUM; i++) {
>   		BUG_ON(!(strlen(bnad_net_stats_strings[i]) < ETH_GSTRING_LEN));
> -		ethtool_sprintf(&string, bnad_net_stats_strings[i]);
> +		ethtool_puts(&string, bnad_net_stats_strings[i]);
>   	}
>   
>   	bmap = bna_tx_rid_mask(&bnad->bna);
> diff --git a/drivers/net/ethernet/fungible/funeth/funeth_ethtool.c b/drivers/net/ethernet/fungible/funeth/funeth_ethtool.c
> index 31aa185f4d17..091c93bd7587 100644
> --- a/drivers/net/ethernet/fungible/funeth/funeth_ethtool.c
> +++ b/drivers/net/ethernet/fungible/funeth/funeth_ethtool.c
> @@ -655,7 +655,7 @@ static void fun_get_strings(struct net_device *netdev, u32 sset, u8 *data)
>   						i);
>   		}
>   		for (j = 0; j < ARRAY_SIZE(txq_stat_names); j++)
> -			ethtool_sprintf(&p, txq_stat_names[j]);
> +			ethtool_puts(&p, txq_stat_names[j]);
>   
>   		for (i = 0; i < fp->num_xdpqs; i++) {
>   			for (j = 0; j < ARRAY_SIZE(xdpq_stat_names); j++)
> @@ -663,7 +663,7 @@ static void fun_get_strings(struct net_device *netdev, u32 sset, u8 *data)
>   						xdpq_stat_names[j], i);
>   		}
>   		for (j = 0; j < ARRAY_SIZE(xdpq_stat_names); j++)
> -			ethtool_sprintf(&p, xdpq_stat_names[j]);
> +			ethtool_puts(&p, xdpq_stat_names[j]);
>   
>   		for (i = 0; i < netdev->real_num_rx_queues; i++) {
>   			for (j = 0; j < ARRAY_SIZE(rxq_stat_names); j++)
> @@ -671,10 +671,10 @@ static void fun_get_strings(struct net_device *netdev, u32 sset, u8 *data)
>   						i);
>   		}
>   		for (j = 0; j < ARRAY_SIZE(rxq_stat_names); j++)
> -			ethtool_sprintf(&p, rxq_stat_names[j]);
> +			ethtool_puts(&p, rxq_stat_names[j]);
>   
>   		for (j = 0; j < ARRAY_SIZE(tls_stat_names); j++)
> -			ethtool_sprintf(&p, tls_stat_names[j]);
> +			ethtool_puts(&p, tls_stat_names[j]);
>   		break;
>   	default:
>   		break;
> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
> index 8f391e2adcc0..bdb7afaabdd0 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
> @@ -678,7 +678,7 @@ static void hns_gmac_get_strings(u32 stringset, u8 *data)
>   		return;
>   
>   	for (i = 0; i < ARRAY_SIZE(g_gmac_stats_string); i++)
> -		ethtool_sprintf(&buff, g_gmac_stats_string[i].desc);
> +		ethtool_puts(&buff, g_gmac_stats_string[i].desc);
>   }
>   
>   static int hns_gmac_get_sset_count(int stringset)
> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c
> index fc26ffaae620..c58833eb4830 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c
> @@ -752,7 +752,7 @@ static void hns_xgmac_get_strings(u32 stringset, u8 *data)
>   		return;
>   
>   	for (i = 0; i < ARRAY_SIZE(g_xgmac_stats_string); i++)
> -		ethtool_sprintf(&buff, g_xgmac_stats_string[i].desc);
> +		ethtool_puts(&buff, g_xgmac_stats_string[i].desc);
>   }
>   
>   /**
> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
> index b54f3706fb97..b40415910e57 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
> @@ -912,42 +912,42 @@ static void hns_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
>   
>   	if (stringset == ETH_SS_TEST) {
>   		if (priv->ae_handle->phy_if != PHY_INTERFACE_MODE_XGMII)
> -			ethtool_sprintf(&buff,
> -					hns_nic_test_strs[MAC_INTERNALLOOP_MAC]);
> -		ethtool_sprintf(&buff,
> -				hns_nic_test_strs[MAC_INTERNALLOOP_SERDES]);
> +			ethtool_puts(&buff,
> +				     hns_nic_test_strs[MAC_INTERNALLOOP_MAC]);
> +		ethtool_puts(&buff,
> +			     hns_nic_test_strs[MAC_INTERNALLOOP_SERDES]);
>   		if ((netdev->phydev) && (!netdev->phydev->is_c45))
> -			ethtool_sprintf(&buff,
> -					hns_nic_test_strs[MAC_INTERNALLOOP_PHY]);
> +			ethtool_puts(&buff,
> +				     hns_nic_test_strs[MAC_INTERNALLOOP_PHY]);
>   
>   	} else {
> -		ethtool_sprintf(&buff, "rx_packets");
> -		ethtool_sprintf(&buff, "tx_packets");
> -		ethtool_sprintf(&buff, "rx_bytes");
> -		ethtool_sprintf(&buff, "tx_bytes");
> -		ethtool_sprintf(&buff, "rx_errors");
> -		ethtool_sprintf(&buff, "tx_errors");
> -		ethtool_sprintf(&buff, "rx_dropped");
> -		ethtool_sprintf(&buff, "tx_dropped");
> -		ethtool_sprintf(&buff, "multicast");
> -		ethtool_sprintf(&buff, "collisions");
> -		ethtool_sprintf(&buff, "rx_over_errors");
> -		ethtool_sprintf(&buff, "rx_crc_errors");
> -		ethtool_sprintf(&buff, "rx_frame_errors");
> -		ethtool_sprintf(&buff, "rx_fifo_errors");
> -		ethtool_sprintf(&buff, "rx_missed_errors");
> -		ethtool_sprintf(&buff, "tx_aborted_errors");
> -		ethtool_sprintf(&buff, "tx_carrier_errors");
> -		ethtool_sprintf(&buff, "tx_fifo_errors");
> -		ethtool_sprintf(&buff, "tx_heartbeat_errors");
> -		ethtool_sprintf(&buff, "rx_length_errors");
> -		ethtool_sprintf(&buff, "tx_window_errors");
> -		ethtool_sprintf(&buff, "rx_compressed");
> -		ethtool_sprintf(&buff, "tx_compressed");
> -		ethtool_sprintf(&buff, "netdev_rx_dropped");
> -		ethtool_sprintf(&buff, "netdev_tx_dropped");
> -
> -		ethtool_sprintf(&buff, "netdev_tx_timeout");
> +		ethtool_puts(&buff, "rx_packets");
> +		ethtool_puts(&buff, "tx_packets");
> +		ethtool_puts(&buff, "rx_bytes");
> +		ethtool_puts(&buff, "tx_bytes");
> +		ethtool_puts(&buff, "rx_errors");
> +		ethtool_puts(&buff, "tx_errors");
> +		ethtool_puts(&buff, "rx_dropped");
> +		ethtool_puts(&buff, "tx_dropped");
> +		ethtool_puts(&buff, "multicast");
> +		ethtool_puts(&buff, "collisions");
> +		ethtool_puts(&buff, "rx_over_errors");
> +		ethtool_puts(&buff, "rx_crc_errors");
> +		ethtool_puts(&buff, "rx_frame_errors");
> +		ethtool_puts(&buff, "rx_fifo_errors");
> +		ethtool_puts(&buff, "rx_missed_errors");
> +		ethtool_puts(&buff, "tx_aborted_errors");
> +		ethtool_puts(&buff, "tx_carrier_errors");
> +		ethtool_puts(&buff, "tx_fifo_errors");
> +		ethtool_puts(&buff, "tx_heartbeat_errors");
> +		ethtool_puts(&buff, "rx_length_errors");
> +		ethtool_puts(&buff, "tx_window_errors");
> +		ethtool_puts(&buff, "rx_compressed");
> +		ethtool_puts(&buff, "tx_compressed");
> +		ethtool_puts(&buff, "netdev_rx_dropped");
> +		ethtool_puts(&buff, "netdev_tx_dropped");
> +
> +		ethtool_puts(&buff, "netdev_tx_timeout");
>   
>   		h->dev->ops->get_strings(h, stringset, buff);
>   	}
> diff --git a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
> index bd1321bf7e26..2641b2a4fcb0 100644
> --- a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
> +++ b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
> @@ -2512,11 +2512,11 @@ static void i40e_get_priv_flag_strings(struct net_device *netdev, u8 *data)
>   	u8 *p = data;
>   
>   	for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++)
> -		ethtool_sprintf(&p, i40e_gstrings_priv_flags[i].flag_string);
> +		ethtool_puts(&p, i40e_gstrings_priv_flags[i].flag_string);
>   	if (pf->hw.pf_id != 0)
>   		return;
>   	for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++)
> -		ethtool_sprintf(&p, i40e_gl_gstrings_priv_flags[i].flag_string);
> +		ethtool_puts(&p, i40e_gl_gstrings_priv_flags[i].flag_string);
>   }
>   
>   static void i40e_get_strings(struct net_device *netdev, u32 stringset,
> diff --git a/drivers/net/ethernet/intel/ice/ice_ethtool.c b/drivers/net/ethernet/intel/ice/ice_ethtool.c
> index ad4d4702129f..7871bba4b099 100644
> --- a/drivers/net/ethernet/intel/ice/ice_ethtool.c
> +++ b/drivers/net/ethernet/intel/ice/ice_ethtool.c
> @@ -1060,8 +1060,8 @@ __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,
>   	switch (stringset) {
>   	case ETH_SS_STATS:
>   		for (i = 0; i < ICE_VSI_STATS_LEN; i++)
> -			ethtool_sprintf(&p,
> -					ice_gstrings_vsi_stats[i].stat_string);
> +			ethtool_puts(&p,
> +				     ice_gstrings_vsi_stats[i].stat_string);

this would now fit into one line
(perhaps it's the same in other cases, I just checked this one manually)

>   
>   		if (ice_is_port_repr_netdev(netdev))
>   			return;
> @@ -1080,8 +1080,8 @@ __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,
>   			return;
>   
>   		for (i = 0; i < ICE_PF_STATS_LEN; i++)
> -			ethtool_sprintf(&p,
> -					ice_gstrings_pf_stats[i].stat_string);
> +			ethtool_puts(&p,
> +				     ice_gstrings_pf_stats[i].stat_string);
>   
>   		for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
>   			ethtool_sprintf(&p, "tx_priority_%u_xon.nic", i);
> @@ -1097,7 +1097,7 @@ __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,
>   		break;
>   	case ETH_SS_PRIV_FLAGS:
>   		for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++)
> -			ethtool_sprintf(&p, ice_gstrings_priv_flags[i].name);
> +			ethtool_puts(&p, ice_gstrings_priv_flags[i].name);
>   		break;
>   	default:
>   		break;
> diff --git a/drivers/net/ethernet/intel/igb/igb_ethtool.c b/drivers/net/ethernet/intel/igb/igb_ethtool.c
> index 319ed601eaa1..e0a24c7c37f9 100644
> --- a/drivers/net/ethernet/intel/igb/igb_ethtool.c
> +++ b/drivers/net/ethernet/intel/igb/igb_ethtool.c
> @@ -2356,11 +2356,9 @@ static void igb_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
>   		break;
>   	case ETH_SS_STATS:
>   		for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++)
> -			ethtool_sprintf(&p,
> -					igb_gstrings_stats[i].stat_string);
> +			ethtool_puts(&p, igb_gstrings_stats[i].stat_string);
>   		for (i = 0; i < IGB_NETDEV_STATS_LEN; i++)
> -			ethtool_sprintf(&p,
> -					igb_gstrings_net_stats[i].stat_string);
> +			ethtool_puts(&p, igb_gstrings_net_stats[i].stat_string);
>   		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);
> diff --git a/drivers/net/ethernet/intel/igc/igc_ethtool.c b/drivers/net/ethernet/intel/igc/igc_ethtool.c
> index 7ab6dd58e400..2aac55ebdf5a 100644
> --- a/drivers/net/ethernet/intel/igc/igc_ethtool.c
> +++ b/drivers/net/ethernet/intel/igc/igc_ethtool.c
> @@ -773,10 +773,10 @@ static void igc_ethtool_get_strings(struct net_device *netdev, u32 stringset,
>   		break;
>   	case ETH_SS_STATS:
>   		for (i = 0; i < IGC_GLOBAL_STATS_LEN; i++)
> -			ethtool_sprintf(&p, igc_gstrings_stats[i].stat_string);
> +			ethtool_puts(&p, igc_gstrings_stats[i].stat_string);
>   		for (i = 0; i < IGC_NETDEV_STATS_LEN; i++)
> -			ethtool_sprintf(&p,
> -					igc_gstrings_net_stats[i].stat_string);
> +			ethtool_puts(&p,
> +				     igc_gstrings_net_stats[i].stat_string);
>   		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);
> diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
> index 0bbad4a5cc2f..dd722b0381e0 100644
> --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
> +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
> @@ -1413,12 +1413,11 @@ static void ixgbe_get_strings(struct net_device *netdev, u32 stringset,
>   	switch (stringset) {
>   	case ETH_SS_TEST:
>   		for (i = 0; i < IXGBE_TEST_LEN; i++)
> -			ethtool_sprintf(&p, ixgbe_gstrings_test[i]);
> +			ethtool_puts(&p, ixgbe_gstrings_test[i]);
>   		break;
>   	case ETH_SS_STATS:
>   		for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++)
> -			ethtool_sprintf(&p,
> -					ixgbe_gstrings_stats[i].stat_string);
> +			ethtool_puts(&p, ixgbe_gstrings_stats[i].stat_string);
>   		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);
> diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c b/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
> index e75cbb287625..1636ce61a3c0 100644
> --- a/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
> +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
> @@ -800,7 +800,7 @@ static void nfp_get_self_test_strings(struct net_device *netdev, u8 *data)
>   
>   	for (i = 0; i < NFP_TEST_TOTAL_NUM; i++)
>   		if (nfp_self_test[i].is_supported(netdev))
> -			ethtool_sprintf(&data, nfp_self_test[i].name);
> +			ethtool_puts(&data, nfp_self_test[i].name);
>   }
>   
>   static int nfp_get_self_test_count(struct net_device *netdev)
> @@ -852,24 +852,24 @@ static u8 *nfp_vnic_get_sw_stats_strings(struct net_device *netdev, u8 *data)
>   		ethtool_sprintf(&data, "rvec_%u_tx_busy", i);
>   	}
>   
> -	ethtool_sprintf(&data, "hw_rx_csum_ok");
> -	ethtool_sprintf(&data, "hw_rx_csum_inner_ok");
> -	ethtool_sprintf(&data, "hw_rx_csum_complete");
> -	ethtool_sprintf(&data, "hw_rx_csum_err");
> -	ethtool_sprintf(&data, "rx_replace_buf_alloc_fail");
> -	ethtool_sprintf(&data, "rx_tls_decrypted_packets");
> -	ethtool_sprintf(&data, "hw_tx_csum");
> -	ethtool_sprintf(&data, "hw_tx_inner_csum");
> -	ethtool_sprintf(&data, "tx_gather");
> -	ethtool_sprintf(&data, "tx_lso");
> -	ethtool_sprintf(&data, "tx_tls_encrypted_packets");
> -	ethtool_sprintf(&data, "tx_tls_ooo");
> -	ethtool_sprintf(&data, "tx_tls_drop_no_sync_data");
> -
> -	ethtool_sprintf(&data, "hw_tls_no_space");
> -	ethtool_sprintf(&data, "rx_tls_resync_req_ok");
> -	ethtool_sprintf(&data, "rx_tls_resync_req_ign");
> -	ethtool_sprintf(&data, "rx_tls_resync_sent");
> +	ethtool_puts(&data, "hw_rx_csum_ok");
> +	ethtool_puts(&data, "hw_rx_csum_inner_ok");
> +	ethtool_puts(&data, "hw_rx_csum_complete");
> +	ethtool_puts(&data, "hw_rx_csum_err");
> +	ethtool_puts(&data, "rx_replace_buf_alloc_fail");
> +	ethtool_puts(&data, "rx_tls_decrypted_packets");
> +	ethtool_puts(&data, "hw_tx_csum");
> +	ethtool_puts(&data, "hw_tx_inner_csum");
> +	ethtool_puts(&data, "tx_gather");
> +	ethtool_puts(&data, "tx_lso");
> +	ethtool_puts(&data, "tx_tls_encrypted_packets");
> +	ethtool_puts(&data, "tx_tls_ooo");
> +	ethtool_puts(&data, "tx_tls_drop_no_sync_data");
> +
> +	ethtool_puts(&data, "hw_tls_no_space");
> +	ethtool_puts(&data, "rx_tls_resync_req_ok");
> +	ethtool_puts(&data, "rx_tls_resync_req_ign");
> +	ethtool_puts(&data, "rx_tls_resync_sent");
>   
>   	return data;
>   }
> @@ -943,13 +943,13 @@ nfp_vnic_get_hw_stats_strings(u8 *data, unsigned int num_vecs, bool repr)
>   	swap_off = repr * NN_ET_SWITCH_STATS_LEN;
>   
>   	for (i = 0; i < NN_ET_SWITCH_STATS_LEN; i++)
> -		ethtool_sprintf(&data, nfp_net_et_stats[i + swap_off].name);
> +		ethtool_puts(&data, nfp_net_et_stats[i + swap_off].name);
>   
>   	for (i = NN_ET_SWITCH_STATS_LEN; i < NN_ET_SWITCH_STATS_LEN * 2; i++)
> -		ethtool_sprintf(&data, nfp_net_et_stats[i - swap_off].name);
> +		ethtool_puts(&data, nfp_net_et_stats[i - swap_off].name);
>   
>   	for (i = NN_ET_SWITCH_STATS_LEN * 2; i < NN_ET_GLOBAL_STATS_LEN; i++)
> -		ethtool_sprintf(&data, nfp_net_et_stats[i].name);
> +		ethtool_puts(&data, nfp_net_et_stats[i].name);
>   
>   	for (i = 0; i < num_vecs; i++) {
>   		ethtool_sprintf(&data, "rxq_%u_pkts", i);
> diff --git a/drivers/net/ethernet/pensando/ionic/ionic_stats.c b/drivers/net/ethernet/pensando/ionic/ionic_stats.c
> index 9859a4432985..1f6022fb7679 100644
> --- a/drivers/net/ethernet/pensando/ionic/ionic_stats.c
> +++ b/drivers/net/ethernet/pensando/ionic/ionic_stats.c
> @@ -258,10 +258,10 @@ static void ionic_sw_stats_get_strings(struct ionic_lif *lif, u8 **buf)
>   	int i, q_num;
>   
>   	for (i = 0; i < IONIC_NUM_LIF_STATS; i++)
> -		ethtool_sprintf(buf, ionic_lif_stats_desc[i].name);
> +		ethtool_puts(buf, ionic_lif_stats_desc[i].name);
>   
>   	for (i = 0; i < IONIC_NUM_PORT_STATS; i++)
> -		ethtool_sprintf(buf, ionic_port_stats_desc[i].name);
> +		ethtool_puts(buf, ionic_port_stats_desc[i].name);
>   
>   	for (q_num = 0; q_num < MAX_Q(lif); q_num++)
>   		ionic_sw_stats_get_tx_strings(lif, buf, q_num);
> diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
> index 3ba3c8fb28a5..cbd9405fc2f3 100644
> --- a/drivers/net/hyperv/netvsc_drv.c
> +++ b/drivers/net/hyperv/netvsc_drv.c
> @@ -1582,10 +1582,10 @@ static void netvsc_get_strings(struct net_device *dev, u32 stringset, u8 *data)
>   	switch (stringset) {
>   	case ETH_SS_STATS:
>   		for (i = 0; i < ARRAY_SIZE(netvsc_stats); i++)
> -			ethtool_sprintf(&p, netvsc_stats[i].name);
> +			ethtool_puts(&p, netvsc_stats[i].name);
>   
>   		for (i = 0; i < ARRAY_SIZE(vf_stats); i++)
> -			ethtool_sprintf(&p, vf_stats[i].name);
> +			ethtool_puts(&p, vf_stats[i].name);
>   
>   		for (i = 0; i < nvdev->num_chn; i++) {
>   			ethtool_sprintf(&p, "tx_queue_%u_packets", i);
> diff --git a/drivers/net/vmxnet3/vmxnet3_ethtool.c b/drivers/net/vmxnet3/vmxnet3_ethtool.c
> index 98c22d7d87a2..8f5f202cde39 100644
> --- a/drivers/net/vmxnet3/vmxnet3_ethtool.c
> +++ b/drivers/net/vmxnet3/vmxnet3_ethtool.c
> @@ -245,20 +245,20 @@ vmxnet3_get_strings(struct net_device *netdev, u32 stringset, u8 *buf)
>   
>   	for (j = 0; j < adapter->num_tx_queues; j++) {
>   		for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++)
> -			ethtool_sprintf(&buf, vmxnet3_tq_dev_stats[i].desc);
> +			ethtool_puts(&buf, vmxnet3_tq_dev_stats[i].desc);
>   		for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats); i++)
> -			ethtool_sprintf(&buf, vmxnet3_tq_driver_stats[i].desc);
> +			ethtool_puts(&buf, vmxnet3_tq_driver_stats[i].desc);
>   	}
>   
>   	for (j = 0; j < adapter->num_rx_queues; j++) {
>   		for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++)
> -			ethtool_sprintf(&buf, vmxnet3_rq_dev_stats[i].desc);
> +			ethtool_puts(&buf, vmxnet3_rq_dev_stats[i].desc);
>   		for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats); i++)
> -			ethtool_sprintf(&buf, vmxnet3_rq_driver_stats[i].desc);
> +			ethtool_puts(&buf, vmxnet3_rq_driver_stats[i].desc);
>   	}
>   
>   	for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++)
> -		ethtool_sprintf(&buf, vmxnet3_global_stats[i].desc);
> +		ethtool_puts(&buf, vmxnet3_global_stats[i].desc);
>   }
>   
>   netdev_features_t vmxnet3_fix_features(struct net_device *netdev,
> 


^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/3] checkpatch: add ethtool_sprintf rules
  2023-10-25 23:40 ` [PATCH 3/3] checkpatch: add ethtool_sprintf rules Justin Stitt
  2023-10-25 23:52   ` Joe Perches
@ 2023-10-26  9:29   ` Przemek Kitszel
  2023-10-26 17:30   ` Joe Perches
  2 siblings, 0 replies; 19+ messages in thread
From: Przemek Kitszel @ 2023-10-26  9:29 UTC (permalink / raw)
  To: Justin Stitt, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Shay Agroskin, Arthur Kiyanovski, David Arinzon,
	Noam Dagan, Saeed Bishara, Rasesh Mody, Sudarsana Kalluru,
	GR-Linux-NIC-Dev, Dimitris Michailidis, Yisen Zhuang, Salil Mehta,
	Jesse Brandeburg, Tony Nguyen, Louis Peens, Shannon Nelson,
	Brett Creeley, drivers, K. Y. Srinivasan, Haiyang Zhang, Wei Liu,
	Dexuan Cui, Ronak Doshi, VMware PV-Drivers Reviewers,
	Andy Whitcroft, Joe Perches, Dwaipayan Ray, Lukas Bulwahn
  Cc: linux-kernel, netdev, Nick Desaulniers, Nathan Chancellor,
	Kees Cook, intel-wired-lan, oss-drivers, linux-hyperv

On 10/26/23 01:40, Justin Stitt wrote:
> Add some warnings for using ethtool_sprintf() where a simple
> ethtool_puts() would suffice.
> 
> The two cases are:
> 
> 1) Use ethtool_sprintf() with just two arguments:
> |       ethtool_sprintf(&data, driver[i].name);
> or
> 2) Use ethtool_sprintf() with a standalone "%s" fmt string:
> |       ethtool_sprintf(&data, "%s", driver[i].name);
> 
> The former may cause -Wformat-security warnings while the latter is just
> not preferred. Both are safely in the category of warnings, not errors.
> 
> Signed-off-by: Justin Stitt <justinstitt@google.com>
> ---
>   scripts/checkpatch.pl | 13 +++++++++++++
>   1 file changed, 13 insertions(+)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 7d16f863edf1..1ba9ce778746 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -7020,6 +7020,19 @@ sub process {
>   			     "Prefer strscpy, strscpy_pad, or __nonstring over strncpy - see: https://github.com/KSPP/linux/issues/90\n" . $herecurr);
>   		}
>   
> +# ethtool_sprintf uses that should likely be ethtool_puts
> +		if (   $line =~ /\bethtool_sprintf\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\)/   ) {

no need for whitespace right after opening parenthesis, same at the end

Does it work for ethtool_sprintf(calls broken
				 into multiple lines)?

BTW, I really like this series!

> +			WARN("ETHTOOL_SPRINTF",
> +			     "Prefer ethtool_puts over ethtool_sprintf with only two arguments" . $herecurr);
> +		}
> +
> +		# use $rawline because $line loses %s via sanitization and thus we can't match against it.
> +		if (   $rawline =~ /\bethtool_sprintf\s*\(\s*$FuncArg\s*,\s*\"\%s\"\s*,\s*$FuncArg\s*\)/   ) {
> +			WARN("ETHTOOL_SPRINTF2",
> +			     "Prefer ethtool_puts over ethtool_sprintf with standalone \"%s\" specifier" . $herecurr);
> +		}
> +
> +
>   # typecasts on min/max could be min_t/max_t
>   		if ($perl_version_ok &&
>   		    defined $stat &&
> 


^ permalink raw reply	[flat|nested] 19+ messages in thread

* RE: [PATCH 2/3] treewide: Convert some ethtool_sprintf() to ethtool_puts()
  2023-10-26  9:23   ` Przemek Kitszel
@ 2023-10-26 10:18     ` Kiyanovski, Arthur
  2023-10-26 14:24     ` Jakub Kicinski
  1 sibling, 0 replies; 19+ messages in thread
From: Kiyanovski, Arthur @ 2023-10-26 10:18 UTC (permalink / raw)
  To: Przemek Kitszel, Justin Stitt, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Agroskin, Shay, Arinzon, David,
	Dagan, Noam, Bshara, Saeed, Rasesh Mody, Sudarsana Kalluru,
	GR-Linux-NIC-Dev@marvell.com, Dimitris Michailidis, Yisen Zhuang,
	Salil Mehta, Jesse Brandeburg, Tony Nguyen, Louis Peens,
	Shannon Nelson, Brett Creeley, drivers@pensando.io,
	K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Ronak Doshi,
	VMware PV-Drivers Reviewers, Andy Whitcroft, Joe Perches,
	Dwaipayan Ray, Lukas Bulwahn
  Cc: linux-kernel@vger.kernel.org, netdev@vger.kernel.org,
	Nick Desaulniers, Nathan Chancellor, Kees Cook,
	intel-wired-lan@lists.osuosl.org, oss-drivers@corigine.com,
	linux-hyperv@vger.kernel.org

> -----Original Message-----
> From: Przemek Kitszel <przemyslaw.kitszel@intel.com>
> Sent: Thursday, October 26, 2023 12:24 PM
> To: Justin Stitt <justinstitt@google.com>; David S. Miller
> <davem@davemloft.net>; Eric Dumazet <edumazet@google.com>; Jakub
> Kicinski <kuba@kernel.org>; Paolo Abeni <pabeni@redhat.com>; Agroskin, Shay
> <shayagr@amazon.com>; Kiyanovski, Arthur <akiyano@amazon.com>; Arinzon,
> David <darinzon@amazon.com>; Dagan, Noam <ndagan@amazon.com>;
> Bshara, Saeed <saeedb@amazon.com>; Rasesh Mody <rmody@marvell.com>;
> Sudarsana Kalluru <skalluru@marvell.com>; GR-Linux-NIC-Dev@marvell.com;
> Dimitris Michailidis <dmichail@fungible.com>; Yisen Zhuang
> <yisen.zhuang@huawei.com>; Salil Mehta <salil.mehta@huawei.com>; Jesse
> Brandeburg <jesse.brandeburg@intel.com>; Tony Nguyen
> <anthony.l.nguyen@intel.com>; Louis Peens <louis.peens@corigine.com>;
> Shannon Nelson <shannon.nelson@amd.com>; Brett Creeley
> <brett.creeley@amd.com>; drivers@pensando.io; K. Y. Srinivasan
> <kys@microsoft.com>; Haiyang Zhang <haiyangz@microsoft.com>; Wei Liu
> <wei.liu@kernel.org>; Dexuan Cui <decui@microsoft.com>; Ronak Doshi
> <doshir@vmware.com>; VMware PV-Drivers Reviewers <pv-
> drivers@vmware.com>; Andy Whitcroft <apw@canonical.com>; Joe Perches
> <joe@perches.com>; Dwaipayan Ray <dwaipayanray1@gmail.com>; Lukas
> Bulwahn <lukas.bulwahn@gmail.com>
> Cc: linux-kernel@vger.kernel.org; netdev@vger.kernel.org; Nick Desaulniers
> <ndesaulniers@google.com>; Nathan Chancellor <nathan@kernel.org>; Kees
> Cook <keescook@chromium.org>; intel-wired-lan@lists.osuosl.org; oss-
> drivers@corigine.com; linux-hyperv@vger.kernel.org
> Subject: RE: [EXTERNAL] [PATCH 2/3] treewide: Convert some ethtool_sprintf()
> to ethtool_puts()
> 
> CAUTION: This email originated from outside of the organization. Do not click
> links or open attachments unless you can confirm the sender and know the
> content is safe.
> 
> 
> 
> On 10/26/23 01:40, Justin Stitt wrote:
> > This patch converts some basic cases of ethtool_sprintf() to
> > ethtool_puts().
> >
> > The conversions are used in cases where ethtool_sprintf() was being
> > used with just two arguments:
> > |       ethtool_sprintf(&data, buffer[i].name);
> > or when it's used with format string: "%s"
> > |       ethtool_sprintf(&data, "%s", buffer[i].name);
> > which both now become:
> > |       ethtool_puts(&data, buffer[i].name);
> >
> > There are some outstanding patches [1] that I've sent using plain "%s"
> > with ethtool_sprintf() that should be ethtool_puts() now. Some have
> > been picked up as-is but I will send new versions for the others.
> >
> > [1]:
> > https://lore.kernel.org/all/?q=dfb%3Aethtool_sprintf+AND+f%3Ajustinsti
> > tt
> >
> > Signed-off-by: Justin Stitt <justinstitt@google.com>
> > ---
> >   drivers/net/ethernet/amazon/ena/ena_ethtool.c      |  4 +-
> >   drivers/net/ethernet/brocade/bna/bnad_ethtool.c    |  2 +-
> >   .../net/ethernet/fungible/funeth/funeth_ethtool.c  |  8 +--
> >   drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c |  2 +-
> >   .../net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c    |  2 +-
> >   drivers/net/ethernet/hisilicon/hns/hns_ethtool.c   | 66 +++++++++++-----------
> >   drivers/net/ethernet/intel/i40e/i40e_ethtool.c     |  4 +-
> >   drivers/net/ethernet/intel/ice/ice_ethtool.c       | 10 ++--
> >   drivers/net/ethernet/intel/igb/igb_ethtool.c       |  6 +-
> >   drivers/net/ethernet/intel/igc/igc_ethtool.c       |  6 +-
> >   drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c   |  5 +-
> >   .../net/ethernet/netronome/nfp/nfp_net_ethtool.c   | 44 +++++++--------
> >   drivers/net/ethernet/pensando/ionic/ionic_stats.c  |  4 +-
> >   drivers/net/hyperv/netvsc_drv.c                    |  4 +-
> >   drivers/net/vmxnet3/vmxnet3_ethtool.c              | 10 ++--
> >   15 files changed, 87 insertions(+), 90 deletions(-)
> >
> > diff --git a/drivers/net/ethernet/amazon/ena/ena_ethtool.c
> > b/drivers/net/ethernet/amazon/ena/ena_ethtool.c
> > index d671df4b76bc..e3ef081aa42b 100644
> > --- a/drivers/net/ethernet/amazon/ena/ena_ethtool.c
> > +++ b/drivers/net/ethernet/amazon/ena/ena_ethtool.c
> > @@ -299,13 +299,13 @@ static void ena_get_strings(struct ena_adapter
> > *adapter,
> >
> >       for (i = 0; i < ENA_STATS_ARRAY_GLOBAL; i++) {
> >               ena_stats = &ena_stats_global_strings[i];
> > -             ethtool_sprintf(&data, ena_stats->name);
> > +             ethtool_puts(&data, ena_stats->name);
> >       }
> >
> >       if (eni_stats_needed) {
> >               for (i = 0; i < ENA_STATS_ARRAY_ENI(adapter); i++) {
> >                       ena_stats = &ena_stats_eni_strings[i];
> > -                     ethtool_sprintf(&data, ena_stats->name);
> > +                     ethtool_puts(&data, ena_stats->name);
> >               }
> >       }
> >
> > diff --git a/drivers/net/ethernet/brocade/bna/bnad_ethtool.c
> > b/drivers/net/ethernet/brocade/bna/bnad_ethtool.c
> > index df10edff5603..d1ad6c9f8140 100644
> > --- a/drivers/net/ethernet/brocade/bna/bnad_ethtool.c
> > +++ b/drivers/net/ethernet/brocade/bna/bnad_ethtool.c
> > @@ -608,7 +608,7 @@ bnad_get_strings(struct net_device *netdev, u32
> > stringset, u8 *string)
> >
> >       for (i = 0; i < BNAD_ETHTOOL_STATS_NUM; i++) {
> >               BUG_ON(!(strlen(bnad_net_stats_strings[i]) < ETH_GSTRING_LEN));
> > -             ethtool_sprintf(&string, bnad_net_stats_strings[i]);
> > +             ethtool_puts(&string, bnad_net_stats_strings[i]);
> >       }
> >
> >       bmap = bna_tx_rid_mask(&bnad->bna); diff --git
> > a/drivers/net/ethernet/fungible/funeth/funeth_ethtool.c
> > b/drivers/net/ethernet/fungible/funeth/funeth_ethtool.c
> > index 31aa185f4d17..091c93bd7587 100644
> > --- a/drivers/net/ethernet/fungible/funeth/funeth_ethtool.c
> > +++ b/drivers/net/ethernet/fungible/funeth/funeth_ethtool.c
> > @@ -655,7 +655,7 @@ static void fun_get_strings(struct net_device *netdev,
> u32 sset, u8 *data)
> >                                               i);
> >               }
> >               for (j = 0; j < ARRAY_SIZE(txq_stat_names); j++)
> > -                     ethtool_sprintf(&p, txq_stat_names[j]);
> > +                     ethtool_puts(&p, txq_stat_names[j]);
> >
> >               for (i = 0; i < fp->num_xdpqs; i++) {
> >                       for (j = 0; j < ARRAY_SIZE(xdpq_stat_names);
> > j++) @@ -663,7 +663,7 @@ static void fun_get_strings(struct net_device
> *netdev, u32 sset, u8 *data)
> >                                               xdpq_stat_names[j], i);
> >               }
> >               for (j = 0; j < ARRAY_SIZE(xdpq_stat_names); j++)
> > -                     ethtool_sprintf(&p, xdpq_stat_names[j]);
> > +                     ethtool_puts(&p, xdpq_stat_names[j]);
> >
> >               for (i = 0; i < netdev->real_num_rx_queues; i++) {
> >                       for (j = 0; j < ARRAY_SIZE(rxq_stat_names); j++)
> > @@ -671,10 +671,10 @@ static void fun_get_strings(struct net_device
> *netdev, u32 sset, u8 *data)
> >                                               i);
> >               }
> >               for (j = 0; j < ARRAY_SIZE(rxq_stat_names); j++)
> > -                     ethtool_sprintf(&p, rxq_stat_names[j]);
> > +                     ethtool_puts(&p, rxq_stat_names[j]);
> >
> >               for (j = 0; j < ARRAY_SIZE(tls_stat_names); j++)
> > -                     ethtool_sprintf(&p, tls_stat_names[j]);
> > +                     ethtool_puts(&p, tls_stat_names[j]);
> >               break;
> >       default:
> >               break;
> > diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
> > b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
> > index 8f391e2adcc0..bdb7afaabdd0 100644
> > --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
> > +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
> > @@ -678,7 +678,7 @@ static void hns_gmac_get_strings(u32 stringset, u8
> *data)
> >               return;
> >
> >       for (i = 0; i < ARRAY_SIZE(g_gmac_stats_string); i++)
> > -             ethtool_sprintf(&buff, g_gmac_stats_string[i].desc);
> > +             ethtool_puts(&buff, g_gmac_stats_string[i].desc);
> >   }
> >
> >   static int hns_gmac_get_sset_count(int stringset) diff --git
> > a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c
> > b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c
> > index fc26ffaae620..c58833eb4830 100644
> > --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c
> > +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c
> > @@ -752,7 +752,7 @@ static void hns_xgmac_get_strings(u32 stringset, u8
> *data)
> >               return;
> >
> >       for (i = 0; i < ARRAY_SIZE(g_xgmac_stats_string); i++)
> > -             ethtool_sprintf(&buff, g_xgmac_stats_string[i].desc);
> > +             ethtool_puts(&buff, g_xgmac_stats_string[i].desc);
> >   }
> >
> >   /**
> > diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
> > b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
> > index b54f3706fb97..b40415910e57 100644
> > --- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
> > +++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
> > @@ -912,42 +912,42 @@ static void hns_get_strings(struct net_device
> > *netdev, u32 stringset, u8 *data)
> >
> >       if (stringset == ETH_SS_TEST) {
> >               if (priv->ae_handle->phy_if != PHY_INTERFACE_MODE_XGMII)
> > -                     ethtool_sprintf(&buff,
> > -                                     hns_nic_test_strs[MAC_INTERNALLOOP_MAC]);
> > -             ethtool_sprintf(&buff,
> > -                             hns_nic_test_strs[MAC_INTERNALLOOP_SERDES]);
> > +                     ethtool_puts(&buff,
> > +                                  hns_nic_test_strs[MAC_INTERNALLOOP_MAC]);
> > +             ethtool_puts(&buff,
> > +
> > + hns_nic_test_strs[MAC_INTERNALLOOP_SERDES]);
> >               if ((netdev->phydev) && (!netdev->phydev->is_c45))
> > -                     ethtool_sprintf(&buff,
> > -                                     hns_nic_test_strs[MAC_INTERNALLOOP_PHY]);
> > +                     ethtool_puts(&buff,
> > +
> > + hns_nic_test_strs[MAC_INTERNALLOOP_PHY]);
> >
> >       } else {
> > -             ethtool_sprintf(&buff, "rx_packets");
> > -             ethtool_sprintf(&buff, "tx_packets");
> > -             ethtool_sprintf(&buff, "rx_bytes");
> > -             ethtool_sprintf(&buff, "tx_bytes");
> > -             ethtool_sprintf(&buff, "rx_errors");
> > -             ethtool_sprintf(&buff, "tx_errors");
> > -             ethtool_sprintf(&buff, "rx_dropped");
> > -             ethtool_sprintf(&buff, "tx_dropped");
> > -             ethtool_sprintf(&buff, "multicast");
> > -             ethtool_sprintf(&buff, "collisions");
> > -             ethtool_sprintf(&buff, "rx_over_errors");
> > -             ethtool_sprintf(&buff, "rx_crc_errors");
> > -             ethtool_sprintf(&buff, "rx_frame_errors");
> > -             ethtool_sprintf(&buff, "rx_fifo_errors");
> > -             ethtool_sprintf(&buff, "rx_missed_errors");
> > -             ethtool_sprintf(&buff, "tx_aborted_errors");
> > -             ethtool_sprintf(&buff, "tx_carrier_errors");
> > -             ethtool_sprintf(&buff, "tx_fifo_errors");
> > -             ethtool_sprintf(&buff, "tx_heartbeat_errors");
> > -             ethtool_sprintf(&buff, "rx_length_errors");
> > -             ethtool_sprintf(&buff, "tx_window_errors");
> > -             ethtool_sprintf(&buff, "rx_compressed");
> > -             ethtool_sprintf(&buff, "tx_compressed");
> > -             ethtool_sprintf(&buff, "netdev_rx_dropped");
> > -             ethtool_sprintf(&buff, "netdev_tx_dropped");
> > -
> > -             ethtool_sprintf(&buff, "netdev_tx_timeout");
> > +             ethtool_puts(&buff, "rx_packets");
> > +             ethtool_puts(&buff, "tx_packets");
> > +             ethtool_puts(&buff, "rx_bytes");
> > +             ethtool_puts(&buff, "tx_bytes");
> > +             ethtool_puts(&buff, "rx_errors");
> > +             ethtool_puts(&buff, "tx_errors");
> > +             ethtool_puts(&buff, "rx_dropped");
> > +             ethtool_puts(&buff, "tx_dropped");
> > +             ethtool_puts(&buff, "multicast");
> > +             ethtool_puts(&buff, "collisions");
> > +             ethtool_puts(&buff, "rx_over_errors");
> > +             ethtool_puts(&buff, "rx_crc_errors");
> > +             ethtool_puts(&buff, "rx_frame_errors");
> > +             ethtool_puts(&buff, "rx_fifo_errors");
> > +             ethtool_puts(&buff, "rx_missed_errors");
> > +             ethtool_puts(&buff, "tx_aborted_errors");
> > +             ethtool_puts(&buff, "tx_carrier_errors");
> > +             ethtool_puts(&buff, "tx_fifo_errors");
> > +             ethtool_puts(&buff, "tx_heartbeat_errors");
> > +             ethtool_puts(&buff, "rx_length_errors");
> > +             ethtool_puts(&buff, "tx_window_errors");
> > +             ethtool_puts(&buff, "rx_compressed");
> > +             ethtool_puts(&buff, "tx_compressed");
> > +             ethtool_puts(&buff, "netdev_rx_dropped");
> > +             ethtool_puts(&buff, "netdev_tx_dropped");
> > +
> > +             ethtool_puts(&buff, "netdev_tx_timeout");
> >
> >               h->dev->ops->get_strings(h, stringset, buff);
> >       }
> > diff --git a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
> > b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
> > index bd1321bf7e26..2641b2a4fcb0 100644
> > --- a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
> > +++ b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
> > @@ -2512,11 +2512,11 @@ static void i40e_get_priv_flag_strings(struct
> net_device *netdev, u8 *data)
> >       u8 *p = data;
> >
> >       for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++)
> > -             ethtool_sprintf(&p, i40e_gstrings_priv_flags[i].flag_string);
> > +             ethtool_puts(&p,
> > + i40e_gstrings_priv_flags[i].flag_string);
> >       if (pf->hw.pf_id != 0)
> >               return;
> >       for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++)
> > -             ethtool_sprintf(&p, i40e_gl_gstrings_priv_flags[i].flag_string);
> > +             ethtool_puts(&p,
> > + i40e_gl_gstrings_priv_flags[i].flag_string);
> >   }
> >
> >   static void i40e_get_strings(struct net_device *netdev, u32
> > stringset, diff --git a/drivers/net/ethernet/intel/ice/ice_ethtool.c
> > b/drivers/net/ethernet/intel/ice/ice_ethtool.c
> > index ad4d4702129f..7871bba4b099 100644
> > --- a/drivers/net/ethernet/intel/ice/ice_ethtool.c
> > +++ b/drivers/net/ethernet/intel/ice/ice_ethtool.c
> > @@ -1060,8 +1060,8 @@ __ice_get_strings(struct net_device *netdev, u32
> stringset, u8 *data,
> >       switch (stringset) {
> >       case ETH_SS_STATS:
> >               for (i = 0; i < ICE_VSI_STATS_LEN; i++)
> > -                     ethtool_sprintf(&p,
> > -                                     ice_gstrings_vsi_stats[i].stat_string);
> > +                     ethtool_puts(&p,
> > +
> > + ice_gstrings_vsi_stats[i].stat_string);
> 
> this would now fit into one line
> (perhaps it's the same in other cases, I just checked this one manually)
> 
> >
> >               if (ice_is_port_repr_netdev(netdev))
> >                       return;
> > @@ -1080,8 +1080,8 @@ __ice_get_strings(struct net_device *netdev, u32
> stringset, u8 *data,
> >                       return;
> >
> >               for (i = 0; i < ICE_PF_STATS_LEN; i++)
> > -                     ethtool_sprintf(&p,
> > -                                     ice_gstrings_pf_stats[i].stat_string);
> > +                     ethtool_puts(&p,
> > +
> > + ice_gstrings_pf_stats[i].stat_string);
> >
> >               for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
> >                       ethtool_sprintf(&p, "tx_priority_%u_xon.nic",
> > i); @@ -1097,7 +1097,7 @@ __ice_get_strings(struct net_device *netdev, u32
> stringset, u8 *data,
> >               break;
> >       case ETH_SS_PRIV_FLAGS:
> >               for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++)
> > -                     ethtool_sprintf(&p, ice_gstrings_priv_flags[i].name);
> > +                     ethtool_puts(&p,
> > + ice_gstrings_priv_flags[i].name);
> >               break;
> >       default:
> >               break;
> > diff --git a/drivers/net/ethernet/intel/igb/igb_ethtool.c
> > b/drivers/net/ethernet/intel/igb/igb_ethtool.c
> > index 319ed601eaa1..e0a24c7c37f9 100644
> > --- a/drivers/net/ethernet/intel/igb/igb_ethtool.c
> > +++ b/drivers/net/ethernet/intel/igb/igb_ethtool.c
> > @@ -2356,11 +2356,9 @@ static void igb_get_strings(struct net_device
> *netdev, u32 stringset, u8 *data)
> >               break;
> >       case ETH_SS_STATS:
> >               for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++)
> > -                     ethtool_sprintf(&p,
> > -                                     igb_gstrings_stats[i].stat_string);
> > +                     ethtool_puts(&p,
> > + igb_gstrings_stats[i].stat_string);
> >               for (i = 0; i < IGB_NETDEV_STATS_LEN; i++)
> > -                     ethtool_sprintf(&p,
> > -                                     igb_gstrings_net_stats[i].stat_string);
> > +                     ethtool_puts(&p,
> > + igb_gstrings_net_stats[i].stat_string);
> >               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);
> > diff --git a/drivers/net/ethernet/intel/igc/igc_ethtool.c
> > b/drivers/net/ethernet/intel/igc/igc_ethtool.c
> > index 7ab6dd58e400..2aac55ebdf5a 100644
> > --- a/drivers/net/ethernet/intel/igc/igc_ethtool.c
> > +++ b/drivers/net/ethernet/intel/igc/igc_ethtool.c
> > @@ -773,10 +773,10 @@ static void igc_ethtool_get_strings(struct
> net_device *netdev, u32 stringset,
> >               break;
> >       case ETH_SS_STATS:
> >               for (i = 0; i < IGC_GLOBAL_STATS_LEN; i++)
> > -                     ethtool_sprintf(&p, igc_gstrings_stats[i].stat_string);
> > +                     ethtool_puts(&p,
> > + igc_gstrings_stats[i].stat_string);
> >               for (i = 0; i < IGC_NETDEV_STATS_LEN; i++)
> > -                     ethtool_sprintf(&p,
> > -                                     igc_gstrings_net_stats[i].stat_string);
> > +                     ethtool_puts(&p,
> > +
> > + igc_gstrings_net_stats[i].stat_string);
> >               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);
> > diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
> > b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
> > index 0bbad4a5cc2f..dd722b0381e0 100644
> > --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
> > +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
> > @@ -1413,12 +1413,11 @@ static void ixgbe_get_strings(struct net_device
> *netdev, u32 stringset,
> >       switch (stringset) {
> >       case ETH_SS_TEST:
> >               for (i = 0; i < IXGBE_TEST_LEN; i++)
> > -                     ethtool_sprintf(&p, ixgbe_gstrings_test[i]);
> > +                     ethtool_puts(&p, ixgbe_gstrings_test[i]);
> >               break;
> >       case ETH_SS_STATS:
> >               for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++)
> > -                     ethtool_sprintf(&p,
> > -                                     ixgbe_gstrings_stats[i].stat_string);
> > +                     ethtool_puts(&p,
> > + ixgbe_gstrings_stats[i].stat_string);
> >               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);
> > diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
> > b/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
> > index e75cbb287625..1636ce61a3c0 100644
> > --- a/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
> > +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
> > @@ -800,7 +800,7 @@ static void nfp_get_self_test_strings(struct
> > net_device *netdev, u8 *data)
> >
> >       for (i = 0; i < NFP_TEST_TOTAL_NUM; i++)
> >               if (nfp_self_test[i].is_supported(netdev))
> > -                     ethtool_sprintf(&data, nfp_self_test[i].name);
> > +                     ethtool_puts(&data, nfp_self_test[i].name);
> >   }
> >
> >   static int nfp_get_self_test_count(struct net_device *netdev) @@
> > -852,24 +852,24 @@ static u8 *nfp_vnic_get_sw_stats_strings(struct
> net_device *netdev, u8 *data)
> >               ethtool_sprintf(&data, "rvec_%u_tx_busy", i);
> >       }
> >
> > -     ethtool_sprintf(&data, "hw_rx_csum_ok");
> > -     ethtool_sprintf(&data, "hw_rx_csum_inner_ok");
> > -     ethtool_sprintf(&data, "hw_rx_csum_complete");
> > -     ethtool_sprintf(&data, "hw_rx_csum_err");
> > -     ethtool_sprintf(&data, "rx_replace_buf_alloc_fail");
> > -     ethtool_sprintf(&data, "rx_tls_decrypted_packets");
> > -     ethtool_sprintf(&data, "hw_tx_csum");
> > -     ethtool_sprintf(&data, "hw_tx_inner_csum");
> > -     ethtool_sprintf(&data, "tx_gather");
> > -     ethtool_sprintf(&data, "tx_lso");
> > -     ethtool_sprintf(&data, "tx_tls_encrypted_packets");
> > -     ethtool_sprintf(&data, "tx_tls_ooo");
> > -     ethtool_sprintf(&data, "tx_tls_drop_no_sync_data");
> > -
> > -     ethtool_sprintf(&data, "hw_tls_no_space");
> > -     ethtool_sprintf(&data, "rx_tls_resync_req_ok");
> > -     ethtool_sprintf(&data, "rx_tls_resync_req_ign");
> > -     ethtool_sprintf(&data, "rx_tls_resync_sent");
> > +     ethtool_puts(&data, "hw_rx_csum_ok");
> > +     ethtool_puts(&data, "hw_rx_csum_inner_ok");
> > +     ethtool_puts(&data, "hw_rx_csum_complete");
> > +     ethtool_puts(&data, "hw_rx_csum_err");
> > +     ethtool_puts(&data, "rx_replace_buf_alloc_fail");
> > +     ethtool_puts(&data, "rx_tls_decrypted_packets");
> > +     ethtool_puts(&data, "hw_tx_csum");
> > +     ethtool_puts(&data, "hw_tx_inner_csum");
> > +     ethtool_puts(&data, "tx_gather");
> > +     ethtool_puts(&data, "tx_lso");
> > +     ethtool_puts(&data, "tx_tls_encrypted_packets");
> > +     ethtool_puts(&data, "tx_tls_ooo");
> > +     ethtool_puts(&data, "tx_tls_drop_no_sync_data");
> > +
> > +     ethtool_puts(&data, "hw_tls_no_space");
> > +     ethtool_puts(&data, "rx_tls_resync_req_ok");
> > +     ethtool_puts(&data, "rx_tls_resync_req_ign");
> > +     ethtool_puts(&data, "rx_tls_resync_sent");
> >
> >       return data;
> >   }
> > @@ -943,13 +943,13 @@ nfp_vnic_get_hw_stats_strings(u8 *data, unsigned
> int num_vecs, bool repr)
> >       swap_off = repr * NN_ET_SWITCH_STATS_LEN;
> >
> >       for (i = 0; i < NN_ET_SWITCH_STATS_LEN; i++)
> > -             ethtool_sprintf(&data, nfp_net_et_stats[i + swap_off].name);
> > +             ethtool_puts(&data, nfp_net_et_stats[i +
> > + swap_off].name);
> >
> >       for (i = NN_ET_SWITCH_STATS_LEN; i < NN_ET_SWITCH_STATS_LEN * 2;
> i++)
> > -             ethtool_sprintf(&data, nfp_net_et_stats[i - swap_off].name);
> > +             ethtool_puts(&data, nfp_net_et_stats[i -
> > + swap_off].name);
> >
> >       for (i = NN_ET_SWITCH_STATS_LEN * 2; i < NN_ET_GLOBAL_STATS_LEN;
> i++)
> > -             ethtool_sprintf(&data, nfp_net_et_stats[i].name);
> > +             ethtool_puts(&data, nfp_net_et_stats[i].name);
> >
> >       for (i = 0; i < num_vecs; i++) {
> >               ethtool_sprintf(&data, "rxq_%u_pkts", i); diff --git
> > a/drivers/net/ethernet/pensando/ionic/ionic_stats.c
> > b/drivers/net/ethernet/pensando/ionic/ionic_stats.c
> > index 9859a4432985..1f6022fb7679 100644
> > --- a/drivers/net/ethernet/pensando/ionic/ionic_stats.c
> > +++ b/drivers/net/ethernet/pensando/ionic/ionic_stats.c
> > @@ -258,10 +258,10 @@ static void ionic_sw_stats_get_strings(struct
> ionic_lif *lif, u8 **buf)
> >       int i, q_num;
> >
> >       for (i = 0; i < IONIC_NUM_LIF_STATS; i++)
> > -             ethtool_sprintf(buf, ionic_lif_stats_desc[i].name);
> > +             ethtool_puts(buf, ionic_lif_stats_desc[i].name);
> >
> >       for (i = 0; i < IONIC_NUM_PORT_STATS; i++)
> > -             ethtool_sprintf(buf, ionic_port_stats_desc[i].name);
> > +             ethtool_puts(buf, ionic_port_stats_desc[i].name);
> >
> >       for (q_num = 0; q_num < MAX_Q(lif); q_num++)
> >               ionic_sw_stats_get_tx_strings(lif, buf, q_num); diff
> > --git a/drivers/net/hyperv/netvsc_drv.c
> > b/drivers/net/hyperv/netvsc_drv.c index 3ba3c8fb28a5..cbd9405fc2f3
> > 100644
> > --- a/drivers/net/hyperv/netvsc_drv.c
> > +++ b/drivers/net/hyperv/netvsc_drv.c
> > @@ -1582,10 +1582,10 @@ static void netvsc_get_strings(struct net_device
> *dev, u32 stringset, u8 *data)
> >       switch (stringset) {
> >       case ETH_SS_STATS:
> >               for (i = 0; i < ARRAY_SIZE(netvsc_stats); i++)
> > -                     ethtool_sprintf(&p, netvsc_stats[i].name);
> > +                     ethtool_puts(&p, netvsc_stats[i].name);
> >
> >               for (i = 0; i < ARRAY_SIZE(vf_stats); i++)
> > -                     ethtool_sprintf(&p, vf_stats[i].name);
> > +                     ethtool_puts(&p, vf_stats[i].name);
> >
> >               for (i = 0; i < nvdev->num_chn; i++) {
> >                       ethtool_sprintf(&p, "tx_queue_%u_packets", i);
> > diff --git a/drivers/net/vmxnet3/vmxnet3_ethtool.c
> > b/drivers/net/vmxnet3/vmxnet3_ethtool.c
> > index 98c22d7d87a2..8f5f202cde39 100644
> > --- a/drivers/net/vmxnet3/vmxnet3_ethtool.c
> > +++ b/drivers/net/vmxnet3/vmxnet3_ethtool.c
> > @@ -245,20 +245,20 @@ vmxnet3_get_strings(struct net_device *netdev,
> > u32 stringset, u8 *buf)
> >
> >       for (j = 0; j < adapter->num_tx_queues; j++) {
> >               for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++)
> > -                     ethtool_sprintf(&buf, vmxnet3_tq_dev_stats[i].desc);
> > +                     ethtool_puts(&buf,
> > + vmxnet3_tq_dev_stats[i].desc);
> >               for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats); i++)
> > -                     ethtool_sprintf(&buf, vmxnet3_tq_driver_stats[i].desc);
> > +                     ethtool_puts(&buf,
> > + vmxnet3_tq_driver_stats[i].desc);
> >       }
> >
> >       for (j = 0; j < adapter->num_rx_queues; j++) {
> >               for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++)
> > -                     ethtool_sprintf(&buf, vmxnet3_rq_dev_stats[i].desc);
> > +                     ethtool_puts(&buf,
> > + vmxnet3_rq_dev_stats[i].desc);
> >               for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats); i++)
> > -                     ethtool_sprintf(&buf, vmxnet3_rq_driver_stats[i].desc);
> > +                     ethtool_puts(&buf,
> > + vmxnet3_rq_driver_stats[i].desc);
> >       }
> >
> >       for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++)
> > -             ethtool_sprintf(&buf, vmxnet3_global_stats[i].desc);
> > +             ethtool_puts(&buf, vmxnet3_global_stats[i].desc);
> >   }
> >
> >   netdev_features_t vmxnet3_fix_features(struct net_device *netdev,
> >
> 

Thanks for submitting this patch

Acked-by: Arthur Kiyanovski <akiyano@amazon.com>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/3] treewide: Convert some ethtool_sprintf() to ethtool_puts()
  2023-10-26  9:23   ` Przemek Kitszel
  2023-10-26 10:18     ` Kiyanovski, Arthur
@ 2023-10-26 14:24     ` Jakub Kicinski
  1 sibling, 0 replies; 19+ messages in thread
From: Jakub Kicinski @ 2023-10-26 14:24 UTC (permalink / raw)
  To: Justin Stitt
  Cc: Przemek Kitszel, David S. Miller, Eric Dumazet, Paolo Abeni,
	Shay Agroskin, Arthur Kiyanovski, David Arinzon, Noam Dagan,
	Saeed Bishara, Rasesh Mody, Sudarsana Kalluru, GR-Linux-NIC-Dev,
	Dimitris Michailidis, Yisen Zhuang, Salil Mehta, Jesse Brandeburg,
	Tony Nguyen, Louis Peens, Shannon Nelson, Brett Creeley, drivers,
	K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Ronak Doshi,
	VMware PV-Drivers Reviewers, Andy Whitcroft, Joe Perches,
	Dwaipayan Ray, Lukas Bulwahn, linux-kernel, netdev,
	Nick Desaulniers, Nathan Chancellor, Kees Cook, intel-wired-lan,
	oss-drivers, linux-hyperv

On Thu, 26 Oct 2023 11:23:37 +0200 Przemek Kitszel wrote:
> this would now fit into one line
> (perhaps it's the same in other cases, I just checked this one manually)

I think cocci would fold lines automatically? Could be worth trying
spatch to do the conversion for that reason, if you aren't already.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/3] treewide: Convert some ethtool_sprintf() to ethtool_puts()
  2023-10-25 23:40 ` [PATCH 2/3] treewide: Convert some ethtool_sprintf() to ethtool_puts() Justin Stitt
  2023-10-25 23:51   ` Joe Perches
  2023-10-26  9:23   ` Przemek Kitszel
@ 2023-10-26 14:48   ` Louis Peens
  2023-10-26 14:52     ` Joe Perches
  2023-10-26 16:10   ` Nelson, Shannon
  3 siblings, 1 reply; 19+ messages in thread
From: Louis Peens @ 2023-10-26 14:48 UTC (permalink / raw)
  To: Justin Stitt
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Shay Agroskin, Arthur Kiyanovski, David Arinzon, Noam Dagan,
	Saeed Bishara, Rasesh Mody, Sudarsana Kalluru, GR-Linux-NIC-Dev,
	Dimitris Michailidis, Yisen Zhuang, Salil Mehta, Jesse Brandeburg,
	Tony Nguyen, Shannon Nelson, Brett Creeley, drivers,
	K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Ronak Doshi,
	VMware PV-Drivers Reviewers, Andy Whitcroft, Joe Perches,
	Dwaipayan Ray, Lukas Bulwahn, linux-kernel, netdev,
	Nick Desaulniers, Nathan Chancellor, Kees Cook, intel-wired-lan,
	oss-drivers, linux-hyperv

On Wed, Oct 25, 2023 at 11:40:33PM +0000, Justin Stitt wrote:
> This patch converts some basic cases of ethtool_sprintf() to
> ethtool_puts().
> 
> The conversions are used in cases where ethtool_sprintf() was being used
> with just two arguments:
> |       ethtool_sprintf(&data, buffer[i].name);
> or when it's used with format string: "%s"
> |       ethtool_sprintf(&data, "%s", buffer[i].name);
> which both now become:
> |       ethtool_puts(&data, buffer[i].name);
> 
> There are some outstanding patches [1] that I've sent using plain "%s"
> with ethtool_sprintf() that should be ethtool_puts() now. Some have been
> picked up as-is but I will send new versions for the others.
> 
> [1]: https://lore.kernel.org/all/?q=dfb%3Aethtool_sprintf+AND+f%3Ajustinstitt
> 
> Signed-off-by: Justin Stitt <justinstitt@google.com>
> ---
>  drivers/net/ethernet/amazon/ena/ena_ethtool.c      |  4 +-
>  drivers/net/ethernet/brocade/bna/bnad_ethtool.c    |  2 +-
>  .../net/ethernet/fungible/funeth/funeth_ethtool.c  |  8 +--
>  drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c |  2 +-
>  .../net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c    |  2 +-
>  drivers/net/ethernet/hisilicon/hns/hns_ethtool.c   | 66 +++++++++++-----------
>  drivers/net/ethernet/intel/i40e/i40e_ethtool.c     |  4 +-
>  drivers/net/ethernet/intel/ice/ice_ethtool.c       | 10 ++--
>  drivers/net/ethernet/intel/igb/igb_ethtool.c       |  6 +-
>  drivers/net/ethernet/intel/igc/igc_ethtool.c       |  6 +-
>  drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c   |  5 +-
>  .../net/ethernet/netronome/nfp/nfp_net_ethtool.c   | 44 +++++++--------
>  drivers/net/ethernet/pensando/ionic/ionic_stats.c  |  4 +-
>  drivers/net/hyperv/netvsc_drv.c                    |  4 +-
>  drivers/net/vmxnet3/vmxnet3_ethtool.c              | 10 ++--
>  15 files changed, 87 insertions(+), 90 deletions(-)
> 
> diff --git a/drivers/net/ethernet/amazon/ena/ena_ethtool.c b/drivers/net/ethernet/amazon/ena/ena_ethtool.c
> index d671df4b76bc..e3ef081aa42b 100644
> --- a/drivers/net/ethernet/amazon/ena/ena_ethtool.c
> +++ b/drivers/net/ethernet/amazon/ena/ena_ethtool.c
> @@ -299,13 +299,13 @@ static void ena_get_strings(struct ena_adapter *adapter,
>  
>  	for (i = 0; i < ENA_STATS_ARRAY_GLOBAL; i++) {
>  		ena_stats = &ena_stats_global_strings[i];
> -		ethtool_sprintf(&data, ena_stats->name);
> +		ethtool_puts(&data, ena_stats->name);
>  	}
>  
>  	if (eni_stats_needed) {
>  		for (i = 0; i < ENA_STATS_ARRAY_ENI(adapter); i++) {
>  			ena_stats = &ena_stats_eni_strings[i];
> -			ethtool_sprintf(&data, ena_stats->name);
> +			ethtool_puts(&data, ena_stats->name);
>  		}
>  	}
>  
> diff --git a/drivers/net/ethernet/brocade/bna/bnad_ethtool.c b/drivers/net/ethernet/brocade/bna/bnad_ethtool.c
> index df10edff5603..d1ad6c9f8140 100644
> --- a/drivers/net/ethernet/brocade/bna/bnad_ethtool.c
> +++ b/drivers/net/ethernet/brocade/bna/bnad_ethtool.c
> @@ -608,7 +608,7 @@ bnad_get_strings(struct net_device *netdev, u32 stringset, u8 *string)
>  
>  	for (i = 0; i < BNAD_ETHTOOL_STATS_NUM; i++) {
>  		BUG_ON(!(strlen(bnad_net_stats_strings[i]) < ETH_GSTRING_LEN));
> -		ethtool_sprintf(&string, bnad_net_stats_strings[i]);
> +		ethtool_puts(&string, bnad_net_stats_strings[i]);
>  	}
>  
>  	bmap = bna_tx_rid_mask(&bnad->bna);
> diff --git a/drivers/net/ethernet/fungible/funeth/funeth_ethtool.c b/drivers/net/ethernet/fungible/funeth/funeth_ethtool.c
> index 31aa185f4d17..091c93bd7587 100644
> --- a/drivers/net/ethernet/fungible/funeth/funeth_ethtool.c
> +++ b/drivers/net/ethernet/fungible/funeth/funeth_ethtool.c
> @@ -655,7 +655,7 @@ static void fun_get_strings(struct net_device *netdev, u32 sset, u8 *data)
>  						i);
>  		}
>  		for (j = 0; j < ARRAY_SIZE(txq_stat_names); j++)
> -			ethtool_sprintf(&p, txq_stat_names[j]);
> +			ethtool_puts(&p, txq_stat_names[j]);
>  
>  		for (i = 0; i < fp->num_xdpqs; i++) {
>  			for (j = 0; j < ARRAY_SIZE(xdpq_stat_names); j++)
> @@ -663,7 +663,7 @@ static void fun_get_strings(struct net_device *netdev, u32 sset, u8 *data)
>  						xdpq_stat_names[j], i);
>  		}
>  		for (j = 0; j < ARRAY_SIZE(xdpq_stat_names); j++)
> -			ethtool_sprintf(&p, xdpq_stat_names[j]);
> +			ethtool_puts(&p, xdpq_stat_names[j]);
>  
>  		for (i = 0; i < netdev->real_num_rx_queues; i++) {
>  			for (j = 0; j < ARRAY_SIZE(rxq_stat_names); j++)
> @@ -671,10 +671,10 @@ static void fun_get_strings(struct net_device *netdev, u32 sset, u8 *data)
>  						i);
>  		}
>  		for (j = 0; j < ARRAY_SIZE(rxq_stat_names); j++)
> -			ethtool_sprintf(&p, rxq_stat_names[j]);
> +			ethtool_puts(&p, rxq_stat_names[j]);
>  
>  		for (j = 0; j < ARRAY_SIZE(tls_stat_names); j++)
> -			ethtool_sprintf(&p, tls_stat_names[j]);
> +			ethtool_puts(&p, tls_stat_names[j]);
>  		break;
>  	default:
>  		break;
> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
> index 8f391e2adcc0..bdb7afaabdd0 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
> @@ -678,7 +678,7 @@ static void hns_gmac_get_strings(u32 stringset, u8 *data)
>  		return;
>  
>  	for (i = 0; i < ARRAY_SIZE(g_gmac_stats_string); i++)
> -		ethtool_sprintf(&buff, g_gmac_stats_string[i].desc);
> +		ethtool_puts(&buff, g_gmac_stats_string[i].desc);
>  }
>  
>  static int hns_gmac_get_sset_count(int stringset)
> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c
> index fc26ffaae620..c58833eb4830 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c
> @@ -752,7 +752,7 @@ static void hns_xgmac_get_strings(u32 stringset, u8 *data)
>  		return;
>  
>  	for (i = 0; i < ARRAY_SIZE(g_xgmac_stats_string); i++)
> -		ethtool_sprintf(&buff, g_xgmac_stats_string[i].desc);
> +		ethtool_puts(&buff, g_xgmac_stats_string[i].desc);
>  }
>  
>  /**
> diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
> index b54f3706fb97..b40415910e57 100644
> --- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
> +++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
> @@ -912,42 +912,42 @@ static void hns_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
>  
>  	if (stringset == ETH_SS_TEST) {
>  		if (priv->ae_handle->phy_if != PHY_INTERFACE_MODE_XGMII)
> -			ethtool_sprintf(&buff,
> -					hns_nic_test_strs[MAC_INTERNALLOOP_MAC]);
> -		ethtool_sprintf(&buff,
> -				hns_nic_test_strs[MAC_INTERNALLOOP_SERDES]);
> +			ethtool_puts(&buff,
> +				     hns_nic_test_strs[MAC_INTERNALLOOP_MAC]);
> +		ethtool_puts(&buff,
> +			     hns_nic_test_strs[MAC_INTERNALLOOP_SERDES]);
>  		if ((netdev->phydev) && (!netdev->phydev->is_c45))
> -			ethtool_sprintf(&buff,
> -					hns_nic_test_strs[MAC_INTERNALLOOP_PHY]);
> +			ethtool_puts(&buff,
> +				     hns_nic_test_strs[MAC_INTERNALLOOP_PHY]);
>  
>  	} else {
> -		ethtool_sprintf(&buff, "rx_packets");
> -		ethtool_sprintf(&buff, "tx_packets");
> -		ethtool_sprintf(&buff, "rx_bytes");
> -		ethtool_sprintf(&buff, "tx_bytes");
> -		ethtool_sprintf(&buff, "rx_errors");
> -		ethtool_sprintf(&buff, "tx_errors");
> -		ethtool_sprintf(&buff, "rx_dropped");
> -		ethtool_sprintf(&buff, "tx_dropped");
> -		ethtool_sprintf(&buff, "multicast");
> -		ethtool_sprintf(&buff, "collisions");
> -		ethtool_sprintf(&buff, "rx_over_errors");
> -		ethtool_sprintf(&buff, "rx_crc_errors");
> -		ethtool_sprintf(&buff, "rx_frame_errors");
> -		ethtool_sprintf(&buff, "rx_fifo_errors");
> -		ethtool_sprintf(&buff, "rx_missed_errors");
> -		ethtool_sprintf(&buff, "tx_aborted_errors");
> -		ethtool_sprintf(&buff, "tx_carrier_errors");
> -		ethtool_sprintf(&buff, "tx_fifo_errors");
> -		ethtool_sprintf(&buff, "tx_heartbeat_errors");
> -		ethtool_sprintf(&buff, "rx_length_errors");
> -		ethtool_sprintf(&buff, "tx_window_errors");
> -		ethtool_sprintf(&buff, "rx_compressed");
> -		ethtool_sprintf(&buff, "tx_compressed");
> -		ethtool_sprintf(&buff, "netdev_rx_dropped");
> -		ethtool_sprintf(&buff, "netdev_tx_dropped");
> -
> -		ethtool_sprintf(&buff, "netdev_tx_timeout");
> +		ethtool_puts(&buff, "rx_packets");
> +		ethtool_puts(&buff, "tx_packets");
> +		ethtool_puts(&buff, "rx_bytes");
> +		ethtool_puts(&buff, "tx_bytes");
> +		ethtool_puts(&buff, "rx_errors");
> +		ethtool_puts(&buff, "tx_errors");
> +		ethtool_puts(&buff, "rx_dropped");
> +		ethtool_puts(&buff, "tx_dropped");
> +		ethtool_puts(&buff, "multicast");
> +		ethtool_puts(&buff, "collisions");
> +		ethtool_puts(&buff, "rx_over_errors");
> +		ethtool_puts(&buff, "rx_crc_errors");
> +		ethtool_puts(&buff, "rx_frame_errors");
> +		ethtool_puts(&buff, "rx_fifo_errors");
> +		ethtool_puts(&buff, "rx_missed_errors");
> +		ethtool_puts(&buff, "tx_aborted_errors");
> +		ethtool_puts(&buff, "tx_carrier_errors");
> +		ethtool_puts(&buff, "tx_fifo_errors");
> +		ethtool_puts(&buff, "tx_heartbeat_errors");
> +		ethtool_puts(&buff, "rx_length_errors");
> +		ethtool_puts(&buff, "tx_window_errors");
> +		ethtool_puts(&buff, "rx_compressed");
> +		ethtool_puts(&buff, "tx_compressed");
> +		ethtool_puts(&buff, "netdev_rx_dropped");
> +		ethtool_puts(&buff, "netdev_tx_dropped");
> +
> +		ethtool_puts(&buff, "netdev_tx_timeout");
>  
>  		h->dev->ops->get_strings(h, stringset, buff);
>  	}
> diff --git a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
> index bd1321bf7e26..2641b2a4fcb0 100644
> --- a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
> +++ b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
> @@ -2512,11 +2512,11 @@ static void i40e_get_priv_flag_strings(struct net_device *netdev, u8 *data)
>  	u8 *p = data;
>  
>  	for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++)
> -		ethtool_sprintf(&p, i40e_gstrings_priv_flags[i].flag_string);
> +		ethtool_puts(&p, i40e_gstrings_priv_flags[i].flag_string);
>  	if (pf->hw.pf_id != 0)
>  		return;
>  	for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++)
> -		ethtool_sprintf(&p, i40e_gl_gstrings_priv_flags[i].flag_string);
> +		ethtool_puts(&p, i40e_gl_gstrings_priv_flags[i].flag_string);
>  }
>  
>  static void i40e_get_strings(struct net_device *netdev, u32 stringset,
> diff --git a/drivers/net/ethernet/intel/ice/ice_ethtool.c b/drivers/net/ethernet/intel/ice/ice_ethtool.c
> index ad4d4702129f..7871bba4b099 100644
> --- a/drivers/net/ethernet/intel/ice/ice_ethtool.c
> +++ b/drivers/net/ethernet/intel/ice/ice_ethtool.c
> @@ -1060,8 +1060,8 @@ __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,
>  	switch (stringset) {
>  	case ETH_SS_STATS:
>  		for (i = 0; i < ICE_VSI_STATS_LEN; i++)
> -			ethtool_sprintf(&p,
> -					ice_gstrings_vsi_stats[i].stat_string);
> +			ethtool_puts(&p,
> +				     ice_gstrings_vsi_stats[i].stat_string);
>  
>  		if (ice_is_port_repr_netdev(netdev))
>  			return;
> @@ -1080,8 +1080,8 @@ __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,
>  			return;
>  
>  		for (i = 0; i < ICE_PF_STATS_LEN; i++)
> -			ethtool_sprintf(&p,
> -					ice_gstrings_pf_stats[i].stat_string);
> +			ethtool_puts(&p,
> +				     ice_gstrings_pf_stats[i].stat_string);
>  
>  		for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
>  			ethtool_sprintf(&p, "tx_priority_%u_xon.nic", i);
> @@ -1097,7 +1097,7 @@ __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,
>  		break;
>  	case ETH_SS_PRIV_FLAGS:
>  		for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++)
> -			ethtool_sprintf(&p, ice_gstrings_priv_flags[i].name);
> +			ethtool_puts(&p, ice_gstrings_priv_flags[i].name);
>  		break;
>  	default:
>  		break;
> diff --git a/drivers/net/ethernet/intel/igb/igb_ethtool.c b/drivers/net/ethernet/intel/igb/igb_ethtool.c
> index 319ed601eaa1..e0a24c7c37f9 100644
> --- a/drivers/net/ethernet/intel/igb/igb_ethtool.c
> +++ b/drivers/net/ethernet/intel/igb/igb_ethtool.c
> @@ -2356,11 +2356,9 @@ static void igb_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
>  		break;
>  	case ETH_SS_STATS:
>  		for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++)
> -			ethtool_sprintf(&p,
> -					igb_gstrings_stats[i].stat_string);
> +			ethtool_puts(&p, igb_gstrings_stats[i].stat_string);
>  		for (i = 0; i < IGB_NETDEV_STATS_LEN; i++)
> -			ethtool_sprintf(&p,
> -					igb_gstrings_net_stats[i].stat_string);
> +			ethtool_puts(&p, igb_gstrings_net_stats[i].stat_string);
>  		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);
> diff --git a/drivers/net/ethernet/intel/igc/igc_ethtool.c b/drivers/net/ethernet/intel/igc/igc_ethtool.c
> index 7ab6dd58e400..2aac55ebdf5a 100644
> --- a/drivers/net/ethernet/intel/igc/igc_ethtool.c
> +++ b/drivers/net/ethernet/intel/igc/igc_ethtool.c
> @@ -773,10 +773,10 @@ static void igc_ethtool_get_strings(struct net_device *netdev, u32 stringset,
>  		break;
>  	case ETH_SS_STATS:
>  		for (i = 0; i < IGC_GLOBAL_STATS_LEN; i++)
> -			ethtool_sprintf(&p, igc_gstrings_stats[i].stat_string);
> +			ethtool_puts(&p, igc_gstrings_stats[i].stat_string);
>  		for (i = 0; i < IGC_NETDEV_STATS_LEN; i++)
> -			ethtool_sprintf(&p,
> -					igc_gstrings_net_stats[i].stat_string);
> +			ethtool_puts(&p,
> +				     igc_gstrings_net_stats[i].stat_string);
>  		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);
> diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
> index 0bbad4a5cc2f..dd722b0381e0 100644
> --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
> +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
> @@ -1413,12 +1413,11 @@ static void ixgbe_get_strings(struct net_device *netdev, u32 stringset,
>  	switch (stringset) {
>  	case ETH_SS_TEST:
>  		for (i = 0; i < IXGBE_TEST_LEN; i++)
> -			ethtool_sprintf(&p, ixgbe_gstrings_test[i]);
> +			ethtool_puts(&p, ixgbe_gstrings_test[i]);
>  		break;
>  	case ETH_SS_STATS:
>  		for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++)
> -			ethtool_sprintf(&p,
> -					ixgbe_gstrings_stats[i].stat_string);
> +			ethtool_puts(&p, ixgbe_gstrings_stats[i].stat_string);
>  		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);
> diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c b/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
> index e75cbb287625..1636ce61a3c0 100644
> --- a/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
> +++ b/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
> @@ -800,7 +800,7 @@ static void nfp_get_self_test_strings(struct net_device *netdev, u8 *data)
>  
>  	for (i = 0; i < NFP_TEST_TOTAL_NUM; i++)
>  		if (nfp_self_test[i].is_supported(netdev))
> -			ethtool_sprintf(&data, nfp_self_test[i].name);
> +			ethtool_puts(&data, nfp_self_test[i].name);
>  }
>  
>  static int nfp_get_self_test_count(struct net_device *netdev)
> @@ -852,24 +852,24 @@ static u8 *nfp_vnic_get_sw_stats_strings(struct net_device *netdev, u8 *data)
>  		ethtool_sprintf(&data, "rvec_%u_tx_busy", i);
>  	}
>  
> -	ethtool_sprintf(&data, "hw_rx_csum_ok");
> -	ethtool_sprintf(&data, "hw_rx_csum_inner_ok");
> -	ethtool_sprintf(&data, "hw_rx_csum_complete");
> -	ethtool_sprintf(&data, "hw_rx_csum_err");
> -	ethtool_sprintf(&data, "rx_replace_buf_alloc_fail");
> -	ethtool_sprintf(&data, "rx_tls_decrypted_packets");
> -	ethtool_sprintf(&data, "hw_tx_csum");
> -	ethtool_sprintf(&data, "hw_tx_inner_csum");
> -	ethtool_sprintf(&data, "tx_gather");
> -	ethtool_sprintf(&data, "tx_lso");
> -	ethtool_sprintf(&data, "tx_tls_encrypted_packets");
> -	ethtool_sprintf(&data, "tx_tls_ooo");
> -	ethtool_sprintf(&data, "tx_tls_drop_no_sync_data");
> -
> -	ethtool_sprintf(&data, "hw_tls_no_space");
> -	ethtool_sprintf(&data, "rx_tls_resync_req_ok");
> -	ethtool_sprintf(&data, "rx_tls_resync_req_ign");
> -	ethtool_sprintf(&data, "rx_tls_resync_sent");
> +	ethtool_puts(&data, "hw_rx_csum_ok");
> +	ethtool_puts(&data, "hw_rx_csum_inner_ok");
> +	ethtool_puts(&data, "hw_rx_csum_complete");
> +	ethtool_puts(&data, "hw_rx_csum_err");
> +	ethtool_puts(&data, "rx_replace_buf_alloc_fail");
> +	ethtool_puts(&data, "rx_tls_decrypted_packets");
> +	ethtool_puts(&data, "hw_tx_csum");
> +	ethtool_puts(&data, "hw_tx_inner_csum");
> +	ethtool_puts(&data, "tx_gather");
> +	ethtool_puts(&data, "tx_lso");
> +	ethtool_puts(&data, "tx_tls_encrypted_packets");
> +	ethtool_puts(&data, "tx_tls_ooo");
> +	ethtool_puts(&data, "tx_tls_drop_no_sync_data");
> +
> +	ethtool_puts(&data, "hw_tls_no_space");
> +	ethtool_puts(&data, "rx_tls_resync_req_ok");
> +	ethtool_puts(&data, "rx_tls_resync_req_ign");
> +	ethtool_puts(&data, "rx_tls_resync_sent");
>  
>  	return data;
>  }
> @@ -943,13 +943,13 @@ nfp_vnic_get_hw_stats_strings(u8 *data, unsigned int num_vecs, bool repr)
>  	swap_off = repr * NN_ET_SWITCH_STATS_LEN;
>  
>  	for (i = 0; i < NN_ET_SWITCH_STATS_LEN; i++)
> -		ethtool_sprintf(&data, nfp_net_et_stats[i + swap_off].name);
> +		ethtool_puts(&data, nfp_net_et_stats[i + swap_off].name);
>  
>  	for (i = NN_ET_SWITCH_STATS_LEN; i < NN_ET_SWITCH_STATS_LEN * 2; i++)
> -		ethtool_sprintf(&data, nfp_net_et_stats[i - swap_off].name);
> +		ethtool_puts(&data, nfp_net_et_stats[i - swap_off].name);
>  
>  	for (i = NN_ET_SWITCH_STATS_LEN * 2; i < NN_ET_GLOBAL_STATS_LEN; i++)
> -		ethtool_sprintf(&data, nfp_net_et_stats[i].name);
> +		ethtool_puts(&data, nfp_net_et_stats[i].name);
>  
>  	for (i = 0; i < num_vecs; i++) {
>  		ethtool_sprintf(&data, "rxq_%u_pkts", i);
> diff --git a/drivers/net/ethernet/pensando/ionic/ionic_stats.c b/drivers/net/ethernet/pensando/ionic/ionic_stats.c
> index 9859a4432985..1f6022fb7679 100644
> --- a/drivers/net/ethernet/pensando/ionic/ionic_stats.c
> +++ b/drivers/net/ethernet/pensando/ionic/ionic_stats.c
> @@ -258,10 +258,10 @@ static void ionic_sw_stats_get_strings(struct ionic_lif *lif, u8 **buf)
>  	int i, q_num;
>  
>  	for (i = 0; i < IONIC_NUM_LIF_STATS; i++)
> -		ethtool_sprintf(buf, ionic_lif_stats_desc[i].name);
> +		ethtool_puts(buf, ionic_lif_stats_desc[i].name);
>  
>  	for (i = 0; i < IONIC_NUM_PORT_STATS; i++)
> -		ethtool_sprintf(buf, ionic_port_stats_desc[i].name);
> +		ethtool_puts(buf, ionic_port_stats_desc[i].name);
>  
>  	for (q_num = 0; q_num < MAX_Q(lif); q_num++)
>  		ionic_sw_stats_get_tx_strings(lif, buf, q_num);
> diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
> index 3ba3c8fb28a5..cbd9405fc2f3 100644
> --- a/drivers/net/hyperv/netvsc_drv.c
> +++ b/drivers/net/hyperv/netvsc_drv.c
> @@ -1582,10 +1582,10 @@ static void netvsc_get_strings(struct net_device *dev, u32 stringset, u8 *data)
>  	switch (stringset) {
>  	case ETH_SS_STATS:
>  		for (i = 0; i < ARRAY_SIZE(netvsc_stats); i++)
> -			ethtool_sprintf(&p, netvsc_stats[i].name);
> +			ethtool_puts(&p, netvsc_stats[i].name);
>  
>  		for (i = 0; i < ARRAY_SIZE(vf_stats); i++)
> -			ethtool_sprintf(&p, vf_stats[i].name);
> +			ethtool_puts(&p, vf_stats[i].name);
>  
>  		for (i = 0; i < nvdev->num_chn; i++) {
>  			ethtool_sprintf(&p, "tx_queue_%u_packets", i);
> diff --git a/drivers/net/vmxnet3/vmxnet3_ethtool.c b/drivers/net/vmxnet3/vmxnet3_ethtool.c
> index 98c22d7d87a2..8f5f202cde39 100644
> --- a/drivers/net/vmxnet3/vmxnet3_ethtool.c
> +++ b/drivers/net/vmxnet3/vmxnet3_ethtool.c
> @@ -245,20 +245,20 @@ vmxnet3_get_strings(struct net_device *netdev, u32 stringset, u8 *buf)
>  
>  	for (j = 0; j < adapter->num_tx_queues; j++) {
>  		for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++)
> -			ethtool_sprintf(&buf, vmxnet3_tq_dev_stats[i].desc);
> +			ethtool_puts(&buf, vmxnet3_tq_dev_stats[i].desc);
>  		for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats); i++)
> -			ethtool_sprintf(&buf, vmxnet3_tq_driver_stats[i].desc);
> +			ethtool_puts(&buf, vmxnet3_tq_driver_stats[i].desc);
>  	}
>  
>  	for (j = 0; j < adapter->num_rx_queues; j++) {
>  		for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++)
> -			ethtool_sprintf(&buf, vmxnet3_rq_dev_stats[i].desc);
> +			ethtool_puts(&buf, vmxnet3_rq_dev_stats[i].desc);
>  		for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats); i++)
> -			ethtool_sprintf(&buf, vmxnet3_rq_driver_stats[i].desc);
> +			ethtool_puts(&buf, vmxnet3_rq_driver_stats[i].desc);
>  	}
>  
>  	for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++)
> -		ethtool_sprintf(&buf, vmxnet3_global_stats[i].desc);
> +		ethtool_puts(&buf, vmxnet3_global_stats[i].desc);
>  }
>  
>  netdev_features_t vmxnet3_fix_features(struct net_device *netdev,
> 

Thanks Justin. From my perspective the series looks good, though I've
not spent very long on it. For the nfp parts:

Acked-by: Louis Peens <louis.peens@corigine.com>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/3] treewide: Convert some ethtool_sprintf() to ethtool_puts()
  2023-10-26 14:48   ` Louis Peens
@ 2023-10-26 14:52     ` Joe Perches
  0 siblings, 0 replies; 19+ messages in thread
From: Joe Perches @ 2023-10-26 14:52 UTC (permalink / raw)
  To: Louis Peens, Justin Stitt
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Shay Agroskin, Arthur Kiyanovski, David Arinzon, Noam Dagan,
	Saeed Bishara, Rasesh Mody, Sudarsana Kalluru, GR-Linux-NIC-Dev,
	Dimitris Michailidis, Yisen Zhuang, Salil Mehta, Jesse Brandeburg,
	Tony Nguyen, Shannon Nelson, Brett Creeley, drivers,
	K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Ronak Doshi,
	VMware PV-Drivers Reviewers, Andy Whitcroft, Dwaipayan Ray,
	Lukas Bulwahn, linux-kernel, netdev, Nick Desaulniers,
	Nathan Chancellor, Kees Cook, intel-wired-lan, oss-drivers,
	linux-hyperv

On Thu, 2023-10-26 at 16:48 +0200, Louis Peens wrote:
> On Wed, Oct 25, 2023 at 11:40:33PM +0000, Justin Stitt wrote:
> > This patch converts some basic cases of ethtool_sprintf() to
> > ethtool_puts().

[30k of quoted content]

> Thanks Justin. From my perspective the series looks good, though I've
> not spent very long on it. For the nfp parts:
> 
> Acked-by: Louis Peens <louis.peens@corigine.com

Do please remember to trim your replies.

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 0/3] ethtool: Add ethtool_puts()
  2023-10-25 23:40 [PATCH 0/3] ethtool: Add ethtool_puts() Justin Stitt
                   ` (2 preceding siblings ...)
  2023-10-25 23:40 ` [PATCH 3/3] checkpatch: add ethtool_sprintf rules Justin Stitt
@ 2023-10-26 15:47 ` Kees Cook
  2023-10-26 16:33   ` Joe Perches
  3 siblings, 1 reply; 19+ messages in thread
From: Kees Cook @ 2023-10-26 15:47 UTC (permalink / raw)
  To: Justin Stitt
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Shay Agroskin, Arthur Kiyanovski, David Arinzon, Noam Dagan,
	Saeed Bishara, Rasesh Mody, Sudarsana Kalluru, GR-Linux-NIC-Dev,
	Dimitris Michailidis, Yisen Zhuang, Salil Mehta, Jesse Brandeburg,
	Tony Nguyen, Louis Peens, Shannon Nelson, Brett Creeley, drivers,
	K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Ronak Doshi,
	VMware PV-Drivers Reviewers, Andy Whitcroft, Joe Perches,
	Dwaipayan Ray, Lukas Bulwahn, linux-kernel, netdev,
	Nick Desaulniers, Nathan Chancellor, intel-wired-lan, oss-drivers,
	linux-hyperv

On Wed, Oct 25, 2023 at 11:40:31PM +0000, Justin Stitt wrote:
> @replace_2_args@
> identifier BUF;
> expression VAR;
> @@
> 
> -       ethtool_sprintf
> +       ethtool_puts
>         (&BUF, VAR)

I think cocci will do a better job at line folding if we adjust this
rule like I had to adjust the next rule: completely remove and re-add
the arguments:

-       ethtool_sprintf(&BUF, VAR)
+       ethtool_puts(&BUF, VAR)

Then I think the handful of weird line wraps in the treewide patch will
go away.

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 2/3] treewide: Convert some ethtool_sprintf() to ethtool_puts()
  2023-10-25 23:40 ` [PATCH 2/3] treewide: Convert some ethtool_sprintf() to ethtool_puts() Justin Stitt
                     ` (2 preceding siblings ...)
  2023-10-26 14:48   ` Louis Peens
@ 2023-10-26 16:10   ` Nelson, Shannon
  3 siblings, 0 replies; 19+ messages in thread
From: Nelson, Shannon @ 2023-10-26 16:10 UTC (permalink / raw)
  To: Justin Stitt, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Shay Agroskin, Arthur Kiyanovski, David Arinzon,
	Noam Dagan, Saeed Bishara, Rasesh Mody, Sudarsana Kalluru,
	GR-Linux-NIC-Dev, Dimitris Michailidis, Yisen Zhuang, Salil Mehta,
	Jesse Brandeburg, Tony Nguyen, Louis Peens, Brett Creeley,
	drivers, K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui,
	Ronak Doshi, VMware PV-Drivers Reviewers, Andy Whitcroft,
	Joe Perches, Dwaipayan Ray, Lukas Bulwahn
  Cc: linux-kernel, netdev, Nick Desaulniers, Nathan Chancellor,
	Kees Cook, intel-wired-lan, oss-drivers, linux-hyperv

On 10/25/2023 4:40 PM, Justin Stitt wrote:
> 
> This patch converts some basic cases of ethtool_sprintf() to
> ethtool_puts().
> 
> The conversions are used in cases where ethtool_sprintf() was being used
> with just two arguments:
> |       ethtool_sprintf(&data, buffer[i].name);
> or when it's used with format string: "%s"
> |       ethtool_sprintf(&data, "%s", buffer[i].name);
> which both now become:
> |       ethtool_puts(&data, buffer[i].name);
> 
> There are some outstanding patches [1] that I've sent using plain "%s"
> with ethtool_sprintf() that should be ethtool_puts() now. Some have been
> picked up as-is but I will send new versions for the others.
> 
> [1]: https://lore.kernel.org/all/?q=dfb%3Aethtool_sprintf+AND+f%3Ajustinstitt
> 
> Signed-off-by: Justin Stitt <justinstitt@google.com>

[...]

> diff --git a/drivers/net/ethernet/pensando/ionic/ionic_stats.c b/drivers/net/ethernet/pensando/ionic/ionic_stats.c
> index 9859a4432985..1f6022fb7679 100644
> --- a/drivers/net/ethernet/pensando/ionic/ionic_stats.c
> +++ b/drivers/net/ethernet/pensando/ionic/ionic_stats.c
> @@ -258,10 +258,10 @@ static void ionic_sw_stats_get_strings(struct ionic_lif *lif, u8 **buf)
>          int i, q_num;
> 
>          for (i = 0; i < IONIC_NUM_LIF_STATS; i++)
> -               ethtool_sprintf(buf, ionic_lif_stats_desc[i].name);
> +               ethtool_puts(buf, ionic_lif_stats_desc[i].name);
> 
>          for (i = 0; i < IONIC_NUM_PORT_STATS; i++)
> -               ethtool_sprintf(buf, ionic_port_stats_desc[i].name);
> +               ethtool_puts(buf, ionic_port_stats_desc[i].name);
> 
>          for (q_num = 0; q_num < MAX_Q(lif); q_num++)
>                  ionic_sw_stats_get_tx_strings(lif, buf, q_num);

This works for me for the ionic driver

Reviewed-by: Shannon Nelson <shannon.nelson@amd.com>

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 0/3] ethtool: Add ethtool_puts()
  2023-10-26 15:47 ` [PATCH 0/3] ethtool: Add ethtool_puts() Kees Cook
@ 2023-10-26 16:33   ` Joe Perches
  2023-10-26 17:49     ` Kees Cook
  0 siblings, 1 reply; 19+ messages in thread
From: Joe Perches @ 2023-10-26 16:33 UTC (permalink / raw)
  To: Kees Cook, Justin Stitt
  Cc: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Shay Agroskin, Arthur Kiyanovski, David Arinzon, Noam Dagan,
	Saeed Bishara, Rasesh Mody, Sudarsana Kalluru, GR-Linux-NIC-Dev,
	Dimitris Michailidis, Yisen Zhuang, Salil Mehta, Jesse Brandeburg,
	Tony Nguyen, Louis Peens, Shannon Nelson, Brett Creeley, drivers,
	K. Y. Srinivasan, Haiyang Zhang, Wei Liu, Dexuan Cui, Ronak Doshi,
	VMware PV-Drivers Reviewers, Andy Whitcroft, Dwaipayan Ray,
	Lukas Bulwahn, linux-kernel, netdev, Nick Desaulniers,
	Nathan Chancellor, intel-wired-lan, oss-drivers, linux-hyperv

On Thu, 2023-10-26 at 08:47 -0700, Kees Cook wrote:
> On Wed, Oct 25, 2023 at 11:40:31PM +0000, Justin Stitt wrote:
> > @replace_2_args@
> > identifier BUF;
> > expression VAR;
> > @@
> > 
> > -       ethtool_sprintf
> > +       ethtool_puts
> >         (&BUF, VAR)
> 
> I think cocci will do a better job at line folding if we adjust this
> rule like I had to adjust the next rule: completely remove and re-add
> the arguments:
> 
> -       ethtool_sprintf(&BUF, VAR)
> +       ethtool_puts(&BUF, VAR)
> 
> Then I think the handful of weird line wraps in the treewide patch will
> go away.
> 

Perhaps this, but i believe spatch needs
	 --max-width=80
to fill all 80 columns

$ cat ethtool_puts.cocci
@@
expression a, b;
@@

-	ethtool_sprintf(a, b)
+	ethtool_puts(a, b)

@@
expression a, b;
@@

-	ethtool_sprintf(a, "%s", b)
+	ethtool_puts(a, b)

$ spatch -sp-file ethtool_puts.cocci --in-place --max-width=80 drivers/net
$ git diff --stat -p drivers/net
 drivers/net/dsa/lantiq_gswip.c                     |  2 +-
 drivers/net/dsa/mt7530.c                           |  2 +-
 drivers/net/dsa/qca/qca8k-common.c                 |  2 +-
 drivers/net/dsa/realtek/rtl8365mb.c                |  2 +-
 drivers/net/dsa/realtek/rtl8366-core.c             |  2 +-
 drivers/net/dsa/vitesse-vsc73xx-core.c             |  8 +--
 drivers/net/ethernet/amazon/ena/ena_ethtool.c      |  4 +-
 drivers/net/ethernet/brocade/bna/bnad_ethtool.c    |  2 +-
 drivers/net/ethernet/freescale/fec_main.c          |  4 +-
 .../net/ethernet/fungible/funeth/funeth_ethtool.c  |  8 +--
 drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c |  2 +-
 .../net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c    |  2 +-
 drivers/net/ethernet/hisilicon/hns/hns_ethtool.c   | 65 +++++++++++-----------
 drivers/net/ethernet/intel/i40e/i40e_ethtool.c     |  6 +-
 drivers/net/ethernet/intel/iavf/iavf_ethtool.c     |  3 +-
 drivers/net/ethernet/intel/ice/ice_ethtool.c       |  9 +--
 drivers/net/ethernet/intel/idpf/idpf_ethtool.c     |  2 +-
 drivers/net/ethernet/intel/igb/igb_ethtool.c       |  6 +-
 drivers/net/ethernet/intel/igc/igc_ethtool.c       |  6 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c   |  5 +-
 .../net/ethernet/microchip/sparx5/sparx5_ethtool.c |  2 +-
 .../net/ethernet/netronome/nfp/nfp_net_ethtool.c   | 44 +++++++--------
 drivers/net/ethernet/pensando/ionic/ionic_stats.c  |  4 +-
 drivers/net/ethernet/wangxun/libwx/wx_ethtool.c    |  2 +-
 drivers/net/hyperv/netvsc_drv.c                    |  4 +-
 drivers/net/phy/nxp-tja11xx.c                      |  2 +-
 drivers/net/phy/smsc.c                             |  2 +-
 drivers/net/vmxnet3/vmxnet3_ethtool.c              | 10 ++--
 28 files changed, 100 insertions(+), 112 deletions(-)

diff --git a/drivers/net/dsa/lantiq_gswip.c b/drivers/net/dsa/lantiq_gswip.c
index 1a2d5797bf98c..ff67bbf5a789b 100644
--- a/drivers/net/dsa/lantiq_gswip.c
+++ b/drivers/net/dsa/lantiq_gswip.c
@@ -1759,7 +1759,7 @@ static void gswip_get_strings(struct dsa_switch *ds, int port, u32 stringset,
 		return;
 
 	for (i = 0; i < ARRAY_SIZE(gswip_rmon_cnt); i++)
-		ethtool_sprintf(&data, "%s", gswip_rmon_cnt[i].name);
+		ethtool_puts(&data, gswip_rmon_cnt[i].name);
 }
 
 static u32 gswip_bcm_ram_entry_read(struct gswip_priv *priv, u32 table,
diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c
index ecf5d3deb36eb..3c2cce442facf 100644
--- a/drivers/net/dsa/mt7530.c
+++ b/drivers/net/dsa/mt7530.c
@@ -836,7 +836,7 @@ mt7530_get_strings(struct dsa_switch *ds, int port, u32 stringset,
 		return;
 
 	for (i = 0; i < ARRAY_SIZE(mt7530_mib); i++)
-		ethtool_sprintf(&data, "%s", mt7530_mib[i].name);
+		ethtool_puts(&data, mt7530_mib[i].name);
 }
 
 static void
diff --git a/drivers/net/dsa/qca/qca8k-common.c b/drivers/net/dsa/qca/qca8k-common.c
index 9ff0a3c1cb91d..94a949e27445f 100644
--- a/drivers/net/dsa/qca/qca8k-common.c
+++ b/drivers/net/dsa/qca/qca8k-common.c
@@ -487,7 +487,7 @@ void qca8k_get_strings(struct dsa_switch *ds, int port, u32 stringset,
 		return;
 
 	for (i = 0; i < priv->info->mib_count; i++)
-		ethtool_sprintf(&data, "%s", ar8327_mib[i].name);
+		ethtool_puts(&data, ar8327_mib[i].name);
 }
 
 void qca8k_get_ethtool_stats(struct dsa_switch *ds, int port,
diff --git a/drivers/net/dsa/realtek/rtl8365mb.c b/drivers/net/dsa/realtek/rtl8365mb.c
index d171c18dd354c..ba0bafaca9aa9 100644
--- a/drivers/net/dsa/realtek/rtl8365mb.c
+++ b/drivers/net/dsa/realtek/rtl8365mb.c
@@ -1303,7 +1303,7 @@ static void rtl8365mb_get_strings(struct dsa_switch *ds, int port, u32 stringset
 
 	for (i = 0; i < RTL8365MB_MIB_END; i++) {
 		struct rtl8365mb_mib_counter *mib = &rtl8365mb_mib_counters[i];
-		ethtool_sprintf(&data, "%s", mib->name);
+		ethtool_puts(&data, mib->name);
 	}
 }
 
diff --git a/drivers/net/dsa/realtek/rtl8366-core.c b/drivers/net/dsa/realtek/rtl8366-core.c
index 82e267b8fddb1..59f98d2c8769b 100644
--- a/drivers/net/dsa/realtek/rtl8366-core.c
+++ b/drivers/net/dsa/realtek/rtl8366-core.c
@@ -401,7 +401,7 @@ void rtl8366_get_strings(struct dsa_switch *ds, int port, u32 stringset,
 		return;
 
 	for (i = 0; i < priv->num_mib_counters; i++)
-		ethtool_sprintf(&data, "%s", priv->mib_counters[i].name);
+		ethtool_puts(&data, priv->mib_counters[i].name);
 }
 EXPORT_SYMBOL_GPL(rtl8366_get_strings);
 
diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c
index e6f29e4e508c1..dd50502e21229 100644
--- a/drivers/net/dsa/vitesse-vsc73xx-core.c
+++ b/drivers/net/dsa/vitesse-vsc73xx-core.c
@@ -949,7 +949,7 @@ static void vsc73xx_get_strings(struct dsa_switch *ds, int port, u32 stringset,
 	indices[5] = ((val >> 26) & 0x1f); /* TX counter 2 */
 
 	/* The first counters is the RX octets */
-	ethtool_sprintf(&buf, "RxEtherStatsOctets");
+	ethtool_puts(&buf, "RxEtherStatsOctets");
 
 	/* Each port supports recording 3 RX counters and 3 TX counters,
 	 * figure out what counters we use in this set-up and return the
@@ -959,15 +959,15 @@ static void vsc73xx_get_strings(struct dsa_switch *ds, int port, u32 stringset,
 	 */
 	for (i = 0; i < 3; i++) {
 		cnt = vsc73xx_find_counter(vsc, indices[i], false);
-		ethtool_sprintf(&buf, "%s", cnt ? cnt->name : "");
+		ethtool_puts(&buf, cnt ? cnt->name : "");
 	}
 
 	/* TX stats begins with the number of TX octets */
-	ethtool_sprintf(&buf, "TxEtherStatsOctets");
+	ethtool_puts(&buf, "TxEtherStatsOctets");
 
 	for (i = 3; i < 6; i++) {
 		cnt = vsc73xx_find_counter(vsc, indices[i], true);
-		ethtool_sprintf(&buf, "%s", cnt ? cnt->name : "");
+		ethtool_puts(&buf, cnt ? cnt->name : "");
 
 	}
 }
diff --git a/drivers/net/ethernet/amazon/ena/ena_ethtool.c b/drivers/net/ethernet/amazon/ena/ena_ethtool.c
index d671df4b76bc7..e3ef081aa42bc 100644
--- a/drivers/net/ethernet/amazon/ena/ena_ethtool.c
+++ b/drivers/net/ethernet/amazon/ena/ena_ethtool.c
@@ -299,13 +299,13 @@ static void ena_get_strings(struct ena_adapter *adapter,
 
 	for (i = 0; i < ENA_STATS_ARRAY_GLOBAL; i++) {
 		ena_stats = &ena_stats_global_strings[i];
-		ethtool_sprintf(&data, ena_stats->name);
+		ethtool_puts(&data, ena_stats->name);
 	}
 
 	if (eni_stats_needed) {
 		for (i = 0; i < ENA_STATS_ARRAY_ENI(adapter); i++) {
 			ena_stats = &ena_stats_eni_strings[i];
-			ethtool_sprintf(&data, ena_stats->name);
+			ethtool_puts(&data, ena_stats->name);
 		}
 	}
 
diff --git a/drivers/net/ethernet/brocade/bna/bnad_ethtool.c b/drivers/net/ethernet/brocade/bna/bnad_ethtool.c
index df10edff5603a..d1ad6c9f81404 100644
--- a/drivers/net/ethernet/brocade/bna/bnad_ethtool.c
+++ b/drivers/net/ethernet/brocade/bna/bnad_ethtool.c
@@ -608,7 +608,7 @@ bnad_get_strings(struct net_device *netdev, u32 stringset, u8 *string)
 
 	for (i = 0; i < BNAD_ETHTOOL_STATS_NUM; i++) {
 		BUG_ON(!(strlen(bnad_net_stats_strings[i]) < ETH_GSTRING_LEN));
-		ethtool_sprintf(&string, bnad_net_stats_strings[i]);
+		ethtool_puts(&string, bnad_net_stats_strings[i]);
 	}
 
 	bmap = bna_tx_rid_mask(&bnad->bna);
diff --git a/drivers/net/ethernet/freescale/fec_main.c b/drivers/net/ethernet/freescale/fec_main.c
index 032c15b541ff2..b53554225945f 100644
--- a/drivers/net/ethernet/freescale/fec_main.c
+++ b/drivers/net/ethernet/freescale/fec_main.c
@@ -2864,10 +2864,10 @@ static void fec_enet_get_strings(struct net_device *netdev,
 	switch (stringset) {
 	case ETH_SS_STATS:
 		for (i = 0; i < ARRAY_SIZE(fec_stats); i++) {
-			ethtool_sprintf(&data, "%s", fec_stats[i].name);
+			ethtool_puts(&data, fec_stats[i].name);
 		}
 		for (i = 0; i < ARRAY_SIZE(fec_xdp_stat_strs); i++) {
-			ethtool_sprintf(&data, "%s", fec_xdp_stat_strs[i]);
+			ethtool_puts(&data, fec_xdp_stat_strs[i]);
 		}
 		page_pool_ethtool_stats_get_strings(data);
 
diff --git a/drivers/net/ethernet/fungible/funeth/funeth_ethtool.c b/drivers/net/ethernet/fungible/funeth/funeth_ethtool.c
index 31aa185f4d17b..091c93bd75872 100644
--- a/drivers/net/ethernet/fungible/funeth/funeth_ethtool.c
+++ b/drivers/net/ethernet/fungible/funeth/funeth_ethtool.c
@@ -655,7 +655,7 @@ static void fun_get_strings(struct net_device *netdev, u32 sset, u8 *data)
 						i);
 		}
 		for (j = 0; j < ARRAY_SIZE(txq_stat_names); j++)
-			ethtool_sprintf(&p, txq_stat_names[j]);
+			ethtool_puts(&p, txq_stat_names[j]);
 
 		for (i = 0; i < fp->num_xdpqs; i++) {
 			for (j = 0; j < ARRAY_SIZE(xdpq_stat_names); j++)
@@ -663,7 +663,7 @@ static void fun_get_strings(struct net_device *netdev, u32 sset, u8 *data)
 						xdpq_stat_names[j], i);
 		}
 		for (j = 0; j < ARRAY_SIZE(xdpq_stat_names); j++)
-			ethtool_sprintf(&p, xdpq_stat_names[j]);
+			ethtool_puts(&p, xdpq_stat_names[j]);
 
 		for (i = 0; i < netdev->real_num_rx_queues; i++) {
 			for (j = 0; j < ARRAY_SIZE(rxq_stat_names); j++)
@@ -671,10 +671,10 @@ static void fun_get_strings(struct net_device *netdev, u32 sset, u8 *data)
 						i);
 		}
 		for (j = 0; j < ARRAY_SIZE(rxq_stat_names); j++)
-			ethtool_sprintf(&p, rxq_stat_names[j]);
+			ethtool_puts(&p, rxq_stat_names[j]);
 
 		for (j = 0; j < ARRAY_SIZE(tls_stat_names); j++)
-			ethtool_sprintf(&p, tls_stat_names[j]);
+			ethtool_puts(&p, tls_stat_names[j]);
 		break;
 	default:
 		break;
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
index 8f391e2adcc0b..bdb7afaabdd06 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_gmac.c
@@ -678,7 +678,7 @@ static void hns_gmac_get_strings(u32 stringset, u8 *data)
 		return;
 
 	for (i = 0; i < ARRAY_SIZE(g_gmac_stats_string); i++)
-		ethtool_sprintf(&buff, g_gmac_stats_string[i].desc);
+		ethtool_puts(&buff, g_gmac_stats_string[i].desc);
 }
 
 static int hns_gmac_get_sset_count(int stringset)
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c
index fc26ffaae6202..c58833eb48306 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_dsaf_xgmac.c
@@ -752,7 +752,7 @@ static void hns_xgmac_get_strings(u32 stringset, u8 *data)
 		return;
 
 	for (i = 0; i < ARRAY_SIZE(g_xgmac_stats_string); i++)
-		ethtool_sprintf(&buff, g_xgmac_stats_string[i].desc);
+		ethtool_puts(&buff, g_xgmac_stats_string[i].desc);
 }
 
 /**
diff --git a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
index b54f3706fb974..fe40cceb0f794 100644
--- a/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
+++ b/drivers/net/ethernet/hisilicon/hns/hns_ethtool.c
@@ -912,42 +912,41 @@ static void hns_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
 
 	if (stringset == ETH_SS_TEST) {
 		if (priv->ae_handle->phy_if != PHY_INTERFACE_MODE_XGMII)
-			ethtool_sprintf(&buff,
-					hns_nic_test_strs[MAC_INTERNALLOOP_MAC]);
-		ethtool_sprintf(&buff,
-				hns_nic_test_strs[MAC_INTERNALLOOP_SERDES]);
+			ethtool_puts(&buff,
+				     hns_nic_test_strs[MAC_INTERNALLOOP_MAC]);
+		ethtool_puts(&buff, hns_nic_test_strs[MAC_INTERNALLOOP_SERDES]);
 		if ((netdev->phydev) && (!netdev->phydev->is_c45))
-			ethtool_sprintf(&buff,
-					hns_nic_test_strs[MAC_INTERNALLOOP_PHY]);
+			ethtool_puts(&buff,
+				     hns_nic_test_strs[MAC_INTERNALLOOP_PHY]);
 
 	} else {
-		ethtool_sprintf(&buff, "rx_packets");
-		ethtool_sprintf(&buff, "tx_packets");
-		ethtool_sprintf(&buff, "rx_bytes");
-		ethtool_sprintf(&buff, "tx_bytes");
-		ethtool_sprintf(&buff, "rx_errors");
-		ethtool_sprintf(&buff, "tx_errors");
-		ethtool_sprintf(&buff, "rx_dropped");
-		ethtool_sprintf(&buff, "tx_dropped");
-		ethtool_sprintf(&buff, "multicast");
-		ethtool_sprintf(&buff, "collisions");
-		ethtool_sprintf(&buff, "rx_over_errors");
-		ethtool_sprintf(&buff, "rx_crc_errors");
-		ethtool_sprintf(&buff, "rx_frame_errors");
-		ethtool_sprintf(&buff, "rx_fifo_errors");
-		ethtool_sprintf(&buff, "rx_missed_errors");
-		ethtool_sprintf(&buff, "tx_aborted_errors");
-		ethtool_sprintf(&buff, "tx_carrier_errors");
-		ethtool_sprintf(&buff, "tx_fifo_errors");
-		ethtool_sprintf(&buff, "tx_heartbeat_errors");
-		ethtool_sprintf(&buff, "rx_length_errors");
-		ethtool_sprintf(&buff, "tx_window_errors");
-		ethtool_sprintf(&buff, "rx_compressed");
-		ethtool_sprintf(&buff, "tx_compressed");
-		ethtool_sprintf(&buff, "netdev_rx_dropped");
-		ethtool_sprintf(&buff, "netdev_tx_dropped");
-
-		ethtool_sprintf(&buff, "netdev_tx_timeout");
+		ethtool_puts(&buff, "rx_packets");
+		ethtool_puts(&buff, "tx_packets");
+		ethtool_puts(&buff, "rx_bytes");
+		ethtool_puts(&buff, "tx_bytes");
+		ethtool_puts(&buff, "rx_errors");
+		ethtool_puts(&buff, "tx_errors");
+		ethtool_puts(&buff, "rx_dropped");
+		ethtool_puts(&buff, "tx_dropped");
+		ethtool_puts(&buff, "multicast");
+		ethtool_puts(&buff, "collisions");
+		ethtool_puts(&buff, "rx_over_errors");
+		ethtool_puts(&buff, "rx_crc_errors");
+		ethtool_puts(&buff, "rx_frame_errors");
+		ethtool_puts(&buff, "rx_fifo_errors");
+		ethtool_puts(&buff, "rx_missed_errors");
+		ethtool_puts(&buff, "tx_aborted_errors");
+		ethtool_puts(&buff, "tx_carrier_errors");
+		ethtool_puts(&buff, "tx_fifo_errors");
+		ethtool_puts(&buff, "tx_heartbeat_errors");
+		ethtool_puts(&buff, "rx_length_errors");
+		ethtool_puts(&buff, "tx_window_errors");
+		ethtool_puts(&buff, "rx_compressed");
+		ethtool_puts(&buff, "tx_compressed");
+		ethtool_puts(&buff, "netdev_rx_dropped");
+		ethtool_puts(&buff, "netdev_tx_dropped");
+
+		ethtool_puts(&buff, "netdev_tx_timeout");
 
 		h->dev->ops->get_strings(h, stringset, buff);
 	}
diff --git a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
index fd7163128c4da..79c3e7968a857 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_ethtool.c
@@ -2514,13 +2514,11 @@ static void i40e_get_priv_flag_strings(struct net_device *netdev, u8 *data)
 	u8 *p = data;
 
 	for (i = 0; i < I40E_PRIV_FLAGS_STR_LEN; i++)
-		ethtool_sprintf(&p, "%s",
-				i40e_gstrings_priv_flags[i].flag_string);
+		ethtool_puts(&p, i40e_gstrings_priv_flags[i].flag_string);
 	if (pf->hw.pf_id != 0)
 		return;
 	for (i = 0; i < I40E_GL_PRIV_FLAGS_STR_LEN; i++)
-		ethtool_sprintf(&p, "%s",
-				i40e_gl_gstrings_priv_flags[i].flag_string);
+		ethtool_puts(&p, i40e_gl_gstrings_priv_flags[i].flag_string);
 }
 
 static void i40e_get_strings(struct net_device *netdev, u32 stringset,
diff --git a/drivers/net/ethernet/intel/iavf/iavf_ethtool.c b/drivers/net/ethernet/intel/iavf/iavf_ethtool.c
index 6f236d1a6444e..75d433dc19742 100644
--- a/drivers/net/ethernet/intel/iavf/iavf_ethtool.c
+++ b/drivers/net/ethernet/intel/iavf/iavf_ethtool.c
@@ -396,8 +396,7 @@ static void iavf_get_priv_flag_strings(struct net_device *netdev, u8 *data)
 	unsigned int i;
 
 	for (i = 0; i < IAVF_PRIV_FLAGS_STR_LEN; i++)
-		ethtool_sprintf(&data, "%s",
-				iavf_gstrings_priv_flags[i].flag_string);
+		ethtool_puts(&data, iavf_gstrings_priv_flags[i].flag_string);
 }
 
 /**
diff --git a/drivers/net/ethernet/intel/ice/ice_ethtool.c b/drivers/net/ethernet/intel/ice/ice_ethtool.c
index 7870a39845473..e16c04924d10c 100644
--- a/drivers/net/ethernet/intel/ice/ice_ethtool.c
+++ b/drivers/net/ethernet/intel/ice/ice_ethtool.c
@@ -1133,8 +1133,7 @@ __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,
 	switch (stringset) {
 	case ETH_SS_STATS:
 		for (i = 0; i < ICE_VSI_STATS_LEN; i++)
-			ethtool_sprintf(&p, "%s",
-					ice_gstrings_vsi_stats[i].stat_string);
+			ethtool_puts(&p, ice_gstrings_vsi_stats[i].stat_string);
 
 		if (ice_is_port_repr_netdev(netdev))
 			return;
@@ -1153,8 +1152,7 @@ __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,
 			return;
 
 		for (i = 0; i < ICE_PF_STATS_LEN; i++)
-			ethtool_sprintf(&p, "%s",
-					ice_gstrings_pf_stats[i].stat_string);
+			ethtool_puts(&p, ice_gstrings_pf_stats[i].stat_string);
 
 		for (i = 0; i < ICE_MAX_USER_PRIORITY; i++) {
 			ethtool_sprintf(&p, "tx_priority_%u_xon.nic", i);
@@ -1170,8 +1168,7 @@ __ice_get_strings(struct net_device *netdev, u32 stringset, u8 *data,
 		break;
 	case ETH_SS_PRIV_FLAGS:
 		for (i = 0; i < ICE_PRIV_FLAG_ARRAY_SIZE; i++)
-			ethtool_sprintf(&p, "%s",
-					ice_gstrings_priv_flags[i].name);
+			ethtool_puts(&p, ice_gstrings_priv_flags[i].name);
 		break;
 	default:
 		break;
diff --git a/drivers/net/ethernet/intel/idpf/idpf_ethtool.c b/drivers/net/ethernet/intel/idpf/idpf_ethtool.c
index 52ea38669f85b..bf58989a573e4 100644
--- a/drivers/net/ethernet/intel/idpf/idpf_ethtool.c
+++ b/drivers/net/ethernet/intel/idpf/idpf_ethtool.c
@@ -532,7 +532,7 @@ static void idpf_add_stat_strings(u8 **p, const struct idpf_stats *stats,
 	unsigned int i;
 
 	for (i = 0; i < size; i++)
-		ethtool_sprintf(p, "%s", stats[i].stat_string);
+		ethtool_puts(p, stats[i].stat_string);
 }
 
 /**
diff --git a/drivers/net/ethernet/intel/igb/igb_ethtool.c b/drivers/net/ethernet/intel/igb/igb_ethtool.c
index 9cbd35b6df43d..e0a24c7c37f9b 100644
--- a/drivers/net/ethernet/intel/igb/igb_ethtool.c
+++ b/drivers/net/ethernet/intel/igb/igb_ethtool.c
@@ -2356,11 +2356,9 @@ static void igb_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
 		break;
 	case ETH_SS_STATS:
 		for (i = 0; i < IGB_GLOBAL_STATS_LEN; i++)
-			ethtool_sprintf(&p, "%s",
-					igb_gstrings_stats[i].stat_string);
+			ethtool_puts(&p, igb_gstrings_stats[i].stat_string);
 		for (i = 0; i < IGB_NETDEV_STATS_LEN; i++)
-			ethtool_sprintf(&p, "%s",
-					igb_gstrings_net_stats[i].stat_string);
+			ethtool_puts(&p, igb_gstrings_net_stats[i].stat_string);
 		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);
diff --git a/drivers/net/ethernet/intel/igc/igc_ethtool.c b/drivers/net/ethernet/intel/igc/igc_ethtool.c
index bf4f611286ae3..22a09d3cd65f8 100644
--- a/drivers/net/ethernet/intel/igc/igc_ethtool.c
+++ b/drivers/net/ethernet/intel/igc/igc_ethtool.c
@@ -773,11 +773,9 @@ static void igc_ethtool_get_strings(struct net_device *netdev, u32 stringset,
 		break;
 	case ETH_SS_STATS:
 		for (i = 0; i < IGC_GLOBAL_STATS_LEN; i++)
-			ethtool_sprintf(&p, "%s",
-					igc_gstrings_stats[i].stat_string);
+			ethtool_puts(&p, igc_gstrings_stats[i].stat_string);
 		for (i = 0; i < IGC_NETDEV_STATS_LEN; i++)
-			ethtool_sprintf(&p, "%s",
-					igc_gstrings_net_stats[i].stat_string);
+			ethtool_puts(&p, igc_gstrings_net_stats[i].stat_string);
 		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);
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
index 4dd897806fa5a..dd722b0381e04 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ethtool.c
@@ -1413,12 +1413,11 @@ static void ixgbe_get_strings(struct net_device *netdev, u32 stringset,
 	switch (stringset) {
 	case ETH_SS_TEST:
 		for (i = 0; i < IXGBE_TEST_LEN; i++)
-			ethtool_sprintf(&p, "%s", ixgbe_gstrings_test[i]);
+			ethtool_puts(&p, ixgbe_gstrings_test[i]);
 		break;
 	case ETH_SS_STATS:
 		for (i = 0; i < IXGBE_GLOBAL_STATS_LEN; i++)
-			ethtool_sprintf(&p, "%s",
-					ixgbe_gstrings_stats[i].stat_string);
+			ethtool_puts(&p, ixgbe_gstrings_stats[i].stat_string);
 		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);
diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c b/drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c
index 37d2584b48a7c..a06dc5a9b3551 100644
--- a/drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c
+++ b/drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c
@@ -1012,7 +1012,7 @@ static void sparx5_get_sset_strings(struct net_device *ndev, u32 sset, u8 *data)
 		return;
 
 	for (idx = 0; idx < sparx5->num_ethtool_stats; idx++)
-		ethtool_sprintf(&data, "%s", sparx5->stats_layout[idx]);
+		ethtool_puts(&data, sparx5->stats_layout[idx]);
 }
 
 static void sparx5_get_sset_data(struct net_device *ndev,
diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c b/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
index e75cbb287625f..1636ce61a3c07 100644
--- a/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
+++ b/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
@@ -800,7 +800,7 @@ static void nfp_get_self_test_strings(struct net_device *netdev, u8 *data)
 
 	for (i = 0; i < NFP_TEST_TOTAL_NUM; i++)
 		if (nfp_self_test[i].is_supported(netdev))
-			ethtool_sprintf(&data, nfp_self_test[i].name);
+			ethtool_puts(&data, nfp_self_test[i].name);
 }
 
 static int nfp_get_self_test_count(struct net_device *netdev)
@@ -852,24 +852,24 @@ static u8 *nfp_vnic_get_sw_stats_strings(struct net_device *netdev, u8 *data)
 		ethtool_sprintf(&data, "rvec_%u_tx_busy", i);
 	}
 
-	ethtool_sprintf(&data, "hw_rx_csum_ok");
-	ethtool_sprintf(&data, "hw_rx_csum_inner_ok");
-	ethtool_sprintf(&data, "hw_rx_csum_complete");
-	ethtool_sprintf(&data, "hw_rx_csum_err");
-	ethtool_sprintf(&data, "rx_replace_buf_alloc_fail");
-	ethtool_sprintf(&data, "rx_tls_decrypted_packets");
-	ethtool_sprintf(&data, "hw_tx_csum");
-	ethtool_sprintf(&data, "hw_tx_inner_csum");
-	ethtool_sprintf(&data, "tx_gather");
-	ethtool_sprintf(&data, "tx_lso");
-	ethtool_sprintf(&data, "tx_tls_encrypted_packets");
-	ethtool_sprintf(&data, "tx_tls_ooo");
-	ethtool_sprintf(&data, "tx_tls_drop_no_sync_data");
-
-	ethtool_sprintf(&data, "hw_tls_no_space");
-	ethtool_sprintf(&data, "rx_tls_resync_req_ok");
-	ethtool_sprintf(&data, "rx_tls_resync_req_ign");
-	ethtool_sprintf(&data, "rx_tls_resync_sent");
+	ethtool_puts(&data, "hw_rx_csum_ok");
+	ethtool_puts(&data, "hw_rx_csum_inner_ok");
+	ethtool_puts(&data, "hw_rx_csum_complete");
+	ethtool_puts(&data, "hw_rx_csum_err");
+	ethtool_puts(&data, "rx_replace_buf_alloc_fail");
+	ethtool_puts(&data, "rx_tls_decrypted_packets");
+	ethtool_puts(&data, "hw_tx_csum");
+	ethtool_puts(&data, "hw_tx_inner_csum");
+	ethtool_puts(&data, "tx_gather");
+	ethtool_puts(&data, "tx_lso");
+	ethtool_puts(&data, "tx_tls_encrypted_packets");
+	ethtool_puts(&data, "tx_tls_ooo");
+	ethtool_puts(&data, "tx_tls_drop_no_sync_data");
+
+	ethtool_puts(&data, "hw_tls_no_space");
+	ethtool_puts(&data, "rx_tls_resync_req_ok");
+	ethtool_puts(&data, "rx_tls_resync_req_ign");
+	ethtool_puts(&data, "rx_tls_resync_sent");
 
 	return data;
 }
@@ -943,13 +943,13 @@ nfp_vnic_get_hw_stats_strings(u8 *data, unsigned int num_vecs, bool repr)
 	swap_off = repr * NN_ET_SWITCH_STATS_LEN;
 
 	for (i = 0; i < NN_ET_SWITCH_STATS_LEN; i++)
-		ethtool_sprintf(&data, nfp_net_et_stats[i + swap_off].name);
+		ethtool_puts(&data, nfp_net_et_stats[i + swap_off].name);
 
 	for (i = NN_ET_SWITCH_STATS_LEN; i < NN_ET_SWITCH_STATS_LEN * 2; i++)
-		ethtool_sprintf(&data, nfp_net_et_stats[i - swap_off].name);
+		ethtool_puts(&data, nfp_net_et_stats[i - swap_off].name);
 
 	for (i = NN_ET_SWITCH_STATS_LEN * 2; i < NN_ET_GLOBAL_STATS_LEN; i++)
-		ethtool_sprintf(&data, nfp_net_et_stats[i].name);
+		ethtool_puts(&data, nfp_net_et_stats[i].name);
 
 	for (i = 0; i < num_vecs; i++) {
 		ethtool_sprintf(&data, "rxq_%u_pkts", i);
diff --git a/drivers/net/ethernet/pensando/ionic/ionic_stats.c b/drivers/net/ethernet/pensando/ionic/ionic_stats.c
index 9859a44329851..1f6022fb76797 100644
--- a/drivers/net/ethernet/pensando/ionic/ionic_stats.c
+++ b/drivers/net/ethernet/pensando/ionic/ionic_stats.c
@@ -258,10 +258,10 @@ static void ionic_sw_stats_get_strings(struct ionic_lif *lif, u8 **buf)
 	int i, q_num;
 
 	for (i = 0; i < IONIC_NUM_LIF_STATS; i++)
-		ethtool_sprintf(buf, ionic_lif_stats_desc[i].name);
+		ethtool_puts(buf, ionic_lif_stats_desc[i].name);
 
 	for (i = 0; i < IONIC_NUM_PORT_STATS; i++)
-		ethtool_sprintf(buf, ionic_port_stats_desc[i].name);
+		ethtool_puts(buf, ionic_port_stats_desc[i].name);
 
 	for (q_num = 0; q_num < MAX_Q(lif); q_num++)
 		ionic_sw_stats_get_tx_strings(lif, buf, q_num);
diff --git a/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c b/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c
index ddc5f6d20b9c8..6e9e5f01c1525 100644
--- a/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c
+++ b/drivers/net/ethernet/wangxun/libwx/wx_ethtool.c
@@ -75,7 +75,7 @@ void wx_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
 	switch (stringset) {
 	case ETH_SS_STATS:
 		for (i = 0; i < WX_GLOBAL_STATS_LEN; i++)
-			ethtool_sprintf(&p, wx_gstrings_stats[i].stat_string);
+			ethtool_puts(&p, wx_gstrings_stats[i].stat_string);
 		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);
diff --git a/drivers/net/hyperv/netvsc_drv.c b/drivers/net/hyperv/netvsc_drv.c
index 3ba3c8fb28a5d..cbd9405fc2f38 100644
--- a/drivers/net/hyperv/netvsc_drv.c
+++ b/drivers/net/hyperv/netvsc_drv.c
@@ -1582,10 +1582,10 @@ static void netvsc_get_strings(struct net_device *dev, u32 stringset, u8 *data)
 	switch (stringset) {
 	case ETH_SS_STATS:
 		for (i = 0; i < ARRAY_SIZE(netvsc_stats); i++)
-			ethtool_sprintf(&p, netvsc_stats[i].name);
+			ethtool_puts(&p, netvsc_stats[i].name);
 
 		for (i = 0; i < ARRAY_SIZE(vf_stats); i++)
-			ethtool_sprintf(&p, vf_stats[i].name);
+			ethtool_puts(&p, vf_stats[i].name);
 
 		for (i = 0; i < nvdev->num_chn; i++) {
 			ethtool_sprintf(&p, "tx_queue_%u_packets", i);
diff --git a/drivers/net/phy/nxp-tja11xx.c b/drivers/net/phy/nxp-tja11xx.c
index a713999651421..2c263ae44b4f3 100644
--- a/drivers/net/phy/nxp-tja11xx.c
+++ b/drivers/net/phy/nxp-tja11xx.c
@@ -415,7 +415,7 @@ static void tja11xx_get_strings(struct phy_device *phydev, u8 *data)
 	int i;
 
 	for (i = 0; i < ARRAY_SIZE(tja11xx_hw_stats); i++)
-		ethtool_sprintf(&data, "%s", tja11xx_hw_stats[i].string);
+		ethtool_puts(&data, tja11xx_hw_stats[i].string);
 }
 
 static void tja11xx_get_stats(struct phy_device *phydev,
diff --git a/drivers/net/phy/smsc.c b/drivers/net/phy/smsc.c
index 1c7306a1af131..150aea7c9c367 100644
--- a/drivers/net/phy/smsc.c
+++ b/drivers/net/phy/smsc.c
@@ -508,7 +508,7 @@ static void smsc_get_strings(struct phy_device *phydev, u8 *data)
 	int i;
 
 	for (i = 0; i < ARRAY_SIZE(smsc_hw_stats); i++)
-		ethtool_sprintf(&data, "%s", smsc_hw_stats[i].string);
+		ethtool_puts(&data, smsc_hw_stats[i].string);
 }
 
 static u64 smsc_get_stat(struct phy_device *phydev, int i)
diff --git a/drivers/net/vmxnet3/vmxnet3_ethtool.c b/drivers/net/vmxnet3/vmxnet3_ethtool.c
index 98c22d7d87a2a..8f5f202cde39b 100644
--- a/drivers/net/vmxnet3/vmxnet3_ethtool.c
+++ b/drivers/net/vmxnet3/vmxnet3_ethtool.c
@@ -245,20 +245,20 @@ vmxnet3_get_strings(struct net_device *netdev, u32 stringset, u8 *buf)
 
 	for (j = 0; j < adapter->num_tx_queues; j++) {
 		for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_dev_stats); i++)
-			ethtool_sprintf(&buf, vmxnet3_tq_dev_stats[i].desc);
+			ethtool_puts(&buf, vmxnet3_tq_dev_stats[i].desc);
 		for (i = 0; i < ARRAY_SIZE(vmxnet3_tq_driver_stats); i++)
-			ethtool_sprintf(&buf, vmxnet3_tq_driver_stats[i].desc);
+			ethtool_puts(&buf, vmxnet3_tq_driver_stats[i].desc);
 	}
 
 	for (j = 0; j < adapter->num_rx_queues; j++) {
 		for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_dev_stats); i++)
-			ethtool_sprintf(&buf, vmxnet3_rq_dev_stats[i].desc);
+			ethtool_puts(&buf, vmxnet3_rq_dev_stats[i].desc);
 		for (i = 0; i < ARRAY_SIZE(vmxnet3_rq_driver_stats); i++)
-			ethtool_sprintf(&buf, vmxnet3_rq_driver_stats[i].desc);
+			ethtool_puts(&buf, vmxnet3_rq_driver_stats[i].desc);
 	}
 
 	for (i = 0; i < ARRAY_SIZE(vmxnet3_global_stats); i++)
-		ethtool_sprintf(&buf, vmxnet3_global_stats[i].desc);
+		ethtool_puts(&buf, vmxnet3_global_stats[i].desc);
 }
 
 netdev_features_t vmxnet3_fix_features(struct net_device *netdev,


^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH 3/3] checkpatch: add ethtool_sprintf rules
  2023-10-25 23:40 ` [PATCH 3/3] checkpatch: add ethtool_sprintf rules Justin Stitt
  2023-10-25 23:52   ` Joe Perches
  2023-10-26  9:29   ` Przemek Kitszel
@ 2023-10-26 17:30   ` Joe Perches
  2 siblings, 0 replies; 19+ messages in thread
From: Joe Perches @ 2023-10-26 17:30 UTC (permalink / raw)
  To: Justin Stitt, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Shay Agroskin, Arthur Kiyanovski, David Arinzon,
	Noam Dagan, Saeed Bishara, Rasesh Mody, Sudarsana Kalluru,
	GR-Linux-NIC-Dev, Dimitris Michailidis, Yisen Zhuang, Salil Mehta,
	Jesse Brandeburg, Tony Nguyen, Louis Peens, Shannon Nelson,
	Brett Creeley, drivers, K. Y. Srinivasan, Haiyang Zhang, Wei Liu,
	Dexuan Cui, Ronak Doshi, VMware PV-Drivers Reviewers,
	Andy Whitcroft, Dwaipayan Ray, Lukas Bulwahn
  Cc: linux-kernel, netdev, Nick Desaulniers, Nathan Chancellor,
	Kees Cook, intel-wired-lan, oss-drivers, linux-hyperv

On Wed, 2023-10-25 at 23:40 +0000, Justin Stitt wrote:
> Add some warnings for using ethtool_sprintf() where a simple
> ethtool_puts() would suffice.

Hi again Justin.

After I read patch 1/3 I don't object at all.

spatch/cocci will always be a better option than checkpatch
for conversions like this because it's a proper grammar parser
and checkpatch is a stupid little perl script.

If you resubmit this please:


> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -7020,6 +7020,19 @@ sub process {
>  			     "Prefer strscpy, strscpy_pad, or __nonstring over strncpy - see: https://github.com/KSPP/linux/issues/90\n" . $herecurr);
>  		}
>  
> +# ethtool_sprintf uses that should likely be ethtool_puts
> +		if (   $line =~ /\bethtool_sprintf\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\)/   ) {
> +			WARN("ETHTOOL_SPRINTF",
> +			     "Prefer ethtool_puts over ethtool_sprintf with only two arguments" . $herecurr);
> +		}
> +
> +		# use $rawline because $line loses %s via sanitization and thus we can't match against it.
> +		if (   $rawline =~ /\bethtool_sprintf\s*\(\s*$FuncArg\s*,\s*\"\%s\"\s*,\s*$FuncArg\s*\)/   ) {
> +			WARN("ETHTOOL_SPRINTF2",
> +			     "Prefer ethtool_puts over ethtool_sprintf with standalone \"%s\" specifier" . $herecurr);
> +		}

o remove the whitespace before and after the parentheses
o use the same type "ETHTOOL_SPRINTF" or maybe "PREFER_ETHTOOL_PUTS"
  for both warnings.
o Add a newline on the message output
o Add a --fix option

Something like:
---
 scripts/checkpatch.pl | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 25fdb7fda1128..6924731110d87 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -7011,6 +7011,25 @@ sub process {
 			     "Prefer strscpy, strscpy_pad, or __nonstring over strncpy - see: https://github.com/KSPP/linux/issues/90\n" . $herecurr);
 		}
 
+# ethtool_sprintf uses that should likely be ethtool_puts
+		if ($line =~ /\bethtool_sprintf\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\)/) {
+			if (WARN("PREFER_ETHTOOL_PUTS",
+				 "Prefer ethtool_puts over ethtool_sprintf with only two arguments\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/\bethtool_sprintf\s*\(\s*($FuncArg)\s*,\s*($FuncArg)/ethtool_puts($1, $7)/;
+			}
+		}
+
+		# use $rawline because $line loses %s via sanitization and thus we can't match against it.
+		if ($rawline =~ /\bethtool_sprintf\s*\(\s*$FuncArg\s*,\s*\"\%s\"\s*,\s*$FuncArg\s*\)/) {
+			if (WARN("PREFER_ETHTOOL_PUTS",
+				 "Prefer ethtool_puts over ethtool_sprintf with standalone \"%s\" specifier\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/\bethtool_sprintf\s*\(\s*($FuncArg)\s*,\s*"\%s"\s*,\s*($FuncArg)/ethtool_puts($1, $7)/;
+			}
+		}
+
+
 # typecasts on min/max could be min_t/max_t
 		if ($perl_version_ok &&
 		    defined $stat &&




^ permalink raw reply related	[flat|nested] 19+ messages in thread

* Re: [PATCH 0/3] ethtool: Add ethtool_puts()
  2023-10-26 16:33   ` Joe Perches
@ 2023-10-26 17:49     ` Kees Cook
  2023-10-26 17:57       ` Joe Perches
  0 siblings, 1 reply; 19+ messages in thread
From: Kees Cook @ 2023-10-26 17:49 UTC (permalink / raw)
  To: Joe Perches
  Cc: Justin Stitt, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Shay Agroskin, Arthur Kiyanovski, David Arinzon,
	Noam Dagan, Saeed Bishara, Rasesh Mody, Sudarsana Kalluru,
	GR-Linux-NIC-Dev, Dimitris Michailidis, Yisen Zhuang, Salil Mehta,
	Jesse Brandeburg, Tony Nguyen, Louis Peens, Shannon Nelson,
	Brett Creeley, drivers, K. Y. Srinivasan, Haiyang Zhang, Wei Liu,
	Dexuan Cui, Ronak Doshi, VMware PV-Drivers Reviewers,
	Andy Whitcroft, Dwaipayan Ray, Lukas Bulwahn, linux-kernel,
	netdev, Nick Desaulniers, Nathan Chancellor, intel-wired-lan,
	oss-drivers, linux-hyperv

On Thu, Oct 26, 2023 at 09:33:17AM -0700, Joe Perches wrote:
> On Thu, 2023-10-26 at 08:47 -0700, Kees Cook wrote:
> > On Wed, Oct 25, 2023 at 11:40:31PM +0000, Justin Stitt wrote:
> > > @replace_2_args@
> > > identifier BUF;
> > > expression VAR;
> > > @@
> > > 
> > > -       ethtool_sprintf
> > > +       ethtool_puts
> > >         (&BUF, VAR)
> > 
> > I think cocci will do a better job at line folding if we adjust this
> > rule like I had to adjust the next rule: completely remove and re-add
> > the arguments:
> > 
> > -       ethtool_sprintf(&BUF, VAR)
> > +       ethtool_puts(&BUF, VAR)
> > 
> > Then I think the handful of weird line wraps in the treewide patch will
> > go away.
> > 
> 
> Perhaps this, but i believe spatch needs
> 	 --max-width=80
> to fill all 80 columns

Ah, yeah. Default is 78. Current coding style max is 100... I'll adjust
my local wrappers.

-- 
Kees Cook

^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: [PATCH 0/3] ethtool: Add ethtool_puts()
  2023-10-26 17:49     ` Kees Cook
@ 2023-10-26 17:57       ` Joe Perches
  0 siblings, 0 replies; 19+ messages in thread
From: Joe Perches @ 2023-10-26 17:57 UTC (permalink / raw)
  To: Kees Cook
  Cc: Justin Stitt, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Shay Agroskin, Arthur Kiyanovski, David Arinzon,
	Noam Dagan, Saeed Bishara, Rasesh Mody, Sudarsana Kalluru,
	GR-Linux-NIC-Dev, Dimitris Michailidis, Yisen Zhuang, Salil Mehta,
	Jesse Brandeburg, Tony Nguyen, Louis Peens, Shannon Nelson,
	Brett Creeley, drivers, K. Y. Srinivasan, Haiyang Zhang, Wei Liu,
	Dexuan Cui, Ronak Doshi, VMware PV-Drivers Reviewers,
	Andy Whitcroft, Dwaipayan Ray, Lukas Bulwahn, linux-kernel,
	netdev, Nick Desaulniers, Nathan Chancellor, intel-wired-lan,
	oss-drivers, linux-hyperv

On Thu, 2023-10-26 at 10:49 -0700, Kees Cook wrote:
> On Thu, Oct 26, 2023 at 09:33:17AM -0700, Joe Perches wrote:
> > On Thu, 2023-10-26 at 08:47 -0700, Kees Cook wrote:
> > > On Wed, Oct 25, 2023 at 11:40:31PM +0000, Justin Stitt wrote:
> > > > @replace_2_args@
> > > > identifier BUF;
> > > > expression VAR;
> > > > @@
> > > > 
> > > > -       ethtool_sprintf
> > > > +       ethtool_puts
> > > >         (&BUF, VAR)
> > > 
> > > I think cocci will do a better job at line folding if we adjust this
> > > rule like I had to adjust the next rule: completely remove and re-add
> > > the arguments:
> > > 
> > > -       ethtool_sprintf(&BUF, VAR)
> > > +       ethtool_puts(&BUF, VAR)
> > > 
> > > Then I think the handful of weird line wraps in the treewide patch will
> > > go away.
> > > 
> > 
> > Perhaps this, but i believe spatch needs
> > 	 --max-width=80
> > to fill all 80 columns
> 
> Ah, yeah. Default is 78. Current coding style max is 100... I'll adjust
> my local wrappers.

Coding style max is still 80 with exceptions allowed to 100
not a generic use of 100.



^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2023-10-26 17:57 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-10-25 23:40 [PATCH 0/3] ethtool: Add ethtool_puts() Justin Stitt
2023-10-25 23:40 ` [PATCH 1/3] ethtool: Implement ethtool_puts() Justin Stitt
2023-10-25 23:40 ` [PATCH 2/3] treewide: Convert some ethtool_sprintf() to ethtool_puts() Justin Stitt
2023-10-25 23:51   ` Joe Perches
2023-10-25 23:59     ` Justin Stitt
2023-10-26  9:23   ` Przemek Kitszel
2023-10-26 10:18     ` Kiyanovski, Arthur
2023-10-26 14:24     ` Jakub Kicinski
2023-10-26 14:48   ` Louis Peens
2023-10-26 14:52     ` Joe Perches
2023-10-26 16:10   ` Nelson, Shannon
2023-10-25 23:40 ` [PATCH 3/3] checkpatch: add ethtool_sprintf rules Justin Stitt
2023-10-25 23:52   ` Joe Perches
2023-10-26  9:29   ` Przemek Kitszel
2023-10-26 17:30   ` Joe Perches
2023-10-26 15:47 ` [PATCH 0/3] ethtool: Add ethtool_puts() Kees Cook
2023-10-26 16:33   ` Joe Perches
2023-10-26 17:49     ` Kees Cook
2023-10-26 17:57       ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).