netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <jakub.kicinski@netronome.com>
To: netdev@vger.kernel.org
Cc: oss-drivers@netronome.com, Jakub Kicinski <jakub.kicinski@netronome.com>
Subject: [PATCH net-next 05/12] nfp: add helper for printing ethtool strings
Date: Fri, 18 Aug 2017 15:48:15 -0700	[thread overview]
Message-ID: <20170818224822.8409-6-jakub.kicinski@netronome.com> (raw)
In-Reply-To: <20170818224822.8409-1-jakub.kicinski@netronome.com>

Add a helper for printing ethtool strings and advancing the
pointer correctly.

Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: Simon Horman <simon.horman@netronome.com>
---
 .../net/ethernet/netronome/nfp/nfp_net_ethtool.c   | 65 +++++++++++-----------
 1 file changed, 32 insertions(+), 33 deletions(-)

diff --git a/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c b/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
index 1753bfbc8b47..ba1c28b8791b 100644
--- a/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
+++ b/drivers/net/ethernet/netronome/nfp/nfp_net_ethtool.c
@@ -335,53 +335,52 @@ static int nfp_net_set_ringparam(struct net_device *netdev,
 	return nfp_net_set_ring_size(nn, rxd_cnt, txd_cnt);
 }
 
+static __printf(2, 3) u8 *nfp_pr_et(u8 *data, const char *fmt, ...)
+{
+	va_list args;
+
+	va_start(args, fmt);
+	vsnprintf(data, ETH_GSTRING_LEN, fmt, args);
+	va_end(args);
+
+	return data + ETH_GSTRING_LEN;
+}
+
 static void nfp_net_get_strings(struct net_device *netdev,
 				u32 stringset, u8 *data)
 {
 	struct nfp_net *nn = netdev_priv(netdev);
-	u8 *p = data;
 	int i;
 
 	switch (stringset) {
 	case ETH_SS_STATS:
-		for (i = 0; i < NN_ET_GLOBAL_STATS_LEN; i++) {
-			memcpy(p, nfp_net_et_stats[i].name, ETH_GSTRING_LEN);
-			p += ETH_GSTRING_LEN;
-		}
+		for (i = 0; i < NN_ET_GLOBAL_STATS_LEN; i++)
+			data = nfp_pr_et(data, nfp_net_et_stats[i].name);
+
 		for (i = 0; i < nn->dp.num_r_vecs; i++) {
-			sprintf(p, "rvec_%u_rx_pkts", i);
-			p += ETH_GSTRING_LEN;
-			sprintf(p, "rvec_%u_tx_pkts", i);
-			p += ETH_GSTRING_LEN;
-			sprintf(p, "rvec_%u_tx_busy", i);
-			p += ETH_GSTRING_LEN;
+			data = nfp_pr_et(data, "rvec_%u_rx_pkts", i);
+			data = nfp_pr_et(data, "rvec_%u_tx_pkts", i);
+			data = nfp_pr_et(data, "rvec_%u_tx_busy", i);
 		}
-		strncpy(p, "hw_rx_csum_ok", ETH_GSTRING_LEN);
-		p += ETH_GSTRING_LEN;
-		strncpy(p, "hw_rx_csum_inner_ok", ETH_GSTRING_LEN);
-		p += ETH_GSTRING_LEN;
-		strncpy(p, "hw_rx_csum_err", ETH_GSTRING_LEN);
-		p += ETH_GSTRING_LEN;
-		strncpy(p, "hw_tx_csum", ETH_GSTRING_LEN);
-		p += ETH_GSTRING_LEN;
-		strncpy(p, "hw_tx_inner_csum", ETH_GSTRING_LEN);
-		p += ETH_GSTRING_LEN;
-		strncpy(p, "tx_gather", ETH_GSTRING_LEN);
-		p += ETH_GSTRING_LEN;
-		strncpy(p, "tx_lso", ETH_GSTRING_LEN);
-		p += ETH_GSTRING_LEN;
+
+		data = nfp_pr_et(data, "hw_rx_csum_ok");
+		data = nfp_pr_et(data, "hw_rx_csum_inner_ok");
+		data = nfp_pr_et(data, "hw_rx_csum_err");
+		data = nfp_pr_et(data, "hw_tx_csum");
+		data = nfp_pr_et(data, "hw_tx_inner_csum");
+		data = nfp_pr_et(data, "tx_gather");
+		data = nfp_pr_et(data, "tx_lso");
+
 		for (i = 0; i < nn->dp.num_tx_rings; i++) {
-			sprintf(p, "txq_%u_pkts", i);
-			p += ETH_GSTRING_LEN;
-			sprintf(p, "txq_%u_bytes", i);
-			p += ETH_GSTRING_LEN;
+			data = nfp_pr_et(data, "txq_%u_pkts", i);
+			data = nfp_pr_et(data, "txq_%u_bytes", i);
 		}
+
 		for (i = 0; i < nn->dp.num_rx_rings; i++) {
-			sprintf(p, "rxq_%u_pkts", i);
-			p += ETH_GSTRING_LEN;
-			sprintf(p, "rxq_%u_bytes", i);
-			p += ETH_GSTRING_LEN;
+			data = nfp_pr_et(data, "rxq_%u_pkts", i);
+			data = nfp_pr_et(data, "rxq_%u_bytes", i);
 		}
+
 		break;
 	}
 }
-- 
2.11.0

  parent reply	other threads:[~2017-08-18 22:49 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-18 22:48 [PATCH net-next 00/12] nfp: add basic ethtool callbacks to representors Jakub Kicinski
2017-08-18 22:48 ` [PATCH net-next 01/12] nfp: link basic ethtool ops " Jakub Kicinski
2017-08-18 22:48 ` [PATCH net-next 02/12] nfp: provide ethtool_drvinfo on representors Jakub Kicinski
2017-08-18 22:48 ` [PATCH net-next 03/12] nfp: allow retreiving management FW logs " Jakub Kicinski
2017-08-18 22:48 ` [PATCH net-next 04/12] nfp: don't report standard netdev statistics in ethtool Jakub Kicinski
2017-08-18 22:48 ` Jakub Kicinski [this message]
2017-08-18 22:48 ` [PATCH net-next 06/12] nfp: split software and hardware vNIC statistics Jakub Kicinski
2017-08-18 22:48 ` [PATCH net-next 07/12] nfp: store pointer to MAC statistics in nfp_port Jakub Kicinski
2017-08-18 22:48 ` [PATCH net-next 08/12] nfp: report MAC statistics in ethtool Jakub Kicinski
2017-08-18 22:48 ` [PATCH net-next 09/12] nfp: add pointer to vNIC config memory to nfp_port structure Jakub Kicinski
2017-08-18 22:48 ` [PATCH net-next 10/12] nfp: add ethtool statistics for representors Jakub Kicinski
2017-08-18 22:48 ` [PATCH net-next 11/12] nfp: fix copy paste in names and messages regarding vNICs Jakub Kicinski
2017-08-18 22:48 ` [PATCH net-next 12/12] nfp: don't reuse pointers in ring dumping Jakub Kicinski
2017-08-19  1:04 ` [PATCH net-next 00/12] nfp: add basic ethtool callbacks to representors David Miller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170818224822.8409-6-jakub.kicinski@netronome.com \
    --to=jakub.kicinski@netronome.com \
    --cc=netdev@vger.kernel.org \
    --cc=oss-drivers@netronome.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).