DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	Andrew Boyer <andrew.boyer@amd.com>,
	Rosen Xu <rosen.xu@intel.com>
Subject: [PATCH 20/25] net/ionic: replace snprintf with strlcpy
Date: Thu,  1 Jun 2023 08:01:01 -0700	[thread overview]
Message-ID: <20230601150106.18375-21-stephen@networkplumber.org> (raw)
In-Reply-To: <20230601150106.18375-1-stephen@networkplumber.org>

Suggested by devtools/cocci/strlcpy-with-header.cocci

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/ionic/ionic_ethdev.c        | 15 +++++++--------
 drivers/net/ipn3ke/ipn3ke_representor.c | 17 +++++++----------
 2 files changed, 14 insertions(+), 18 deletions(-)

diff --git a/drivers/net/ionic/ionic_ethdev.c b/drivers/net/ionic/ionic_ethdev.c
index 340fd0cd5923..c6f6342e52f8 100644
--- a/drivers/net/ionic/ionic_ethdev.c
+++ b/drivers/net/ionic/ionic_ethdev.c
@@ -208,8 +208,7 @@ ionic_dev_fw_version_get(struct rte_eth_dev *eth_dev,
 	struct ionic_adapter *adapter = lif->adapter;
 	int ret;
 
-	ret = snprintf(fw_version, fw_size, "%s",
-		 adapter->fw_version);
+	ret = strlcpy(fw_version, adapter->fw_version, fw_size);
 	if (ret < 0)
 		return -EINVAL;
 
@@ -705,9 +704,9 @@ ionic_dev_xstats_get_names(__rte_unused struct rte_eth_dev *eth_dev,
 
 	if (xstats_names != NULL) {
 		for (i = 0; i < IONIC_NB_HW_STATS; i++) {
-			snprintf(xstats_names[i].name,
-					sizeof(xstats_names[i].name),
-					"%s", rte_ionic_xstats_strings[i].name);
+			strlcpy(xstats_names[i].name,
+				rte_ionic_xstats_strings[i].name,
+				sizeof(xstats_names[i].name));
 		}
 	}
 
@@ -725,9 +724,9 @@ ionic_dev_xstats_get_names_by_id(struct rte_eth_dev *eth_dev,
 	if (!ids) {
 		if (xstats_names != NULL) {
 			for (i = 0; i < IONIC_NB_HW_STATS; i++) {
-				snprintf(xstats_names[i].name,
-					sizeof(xstats_names[i].name),
-					"%s", rte_ionic_xstats_strings[i].name);
+				strlcpy(xstats_names[i].name,
+					rte_ionic_xstats_strings[i].name,
+					sizeof(xstats_names[i].name));
 			}
 		}
 
diff --git a/drivers/net/ipn3ke/ipn3ke_representor.c b/drivers/net/ipn3ke/ipn3ke_representor.c
index e50fc73f43c4..feafe9679907 100644
--- a/drivers/net/ipn3ke/ipn3ke_representor.c
+++ b/drivers/net/ipn3ke/ipn3ke_representor.c
@@ -124,8 +124,7 @@ ipn3ke_rpst_dev_start(struct rte_eth_dev *dev)
 	rawdev = hw->rawdev;
 
 	memset(attr_name, 0, sizeof(attr_name));
-	snprintf(attr_name, IPN3KE_RAWDEV_ATTR_LEN_MAX, "%s",
-			"LineSideBaseMAC");
+	strlcpy(attr_name, "LineSideBaseMAC", IPN3KE_RAWDEV_ATTR_LEN_MAX);
 	rawdev->dev_ops->attr_get(rawdev, attr_name, &base_mac);
 	rte_ether_addr_copy((struct rte_ether_addr *)&base_mac,
 			&rpst->mac_addr);
@@ -2330,19 +2329,17 @@ __rte_unused unsigned int limit)
 
 	/* Get stats from ipn3ke_rpst_stats */
 	for (i = 0; i < IPN3KE_RPST_ETH_XSTATS_CNT; i++) {
-		snprintf(xstats_names[count].name,
-			 sizeof(xstats_names[count].name),
-			 "%s",
-			 ipn3ke_rpst_stats_strings[i].name);
+		strlcpy(xstats_names[count].name,
+			ipn3ke_rpst_stats_strings[i].name,
+			sizeof(xstats_names[count].name));
 		count++;
 	}
 
 	/* Get individual stats from ipn3ke_rpst_hw_port */
 	for (i = 0; i < IPN3KE_RPST_HW_PORT_XSTATS_CNT; i++) {
-		snprintf(xstats_names[count].name,
-			 sizeof(xstats_names[count].name),
-			 "%s",
-			 ipn3ke_rpst_hw_port_strings[i].name);
+		strlcpy(xstats_names[count].name,
+			ipn3ke_rpst_hw_port_strings[i].name,
+			sizeof(xstats_names[count].name));
 		count++;
 	}
 
-- 
2.39.2


  parent reply	other threads:[~2023-06-01 15:04 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-01 15:00 [PATCH 00/25] " Stephen Hemminger
2023-06-01 15:00 ` [PATCH 01/25] app: use strlcpy in tests Stephen Hemminger
2023-06-01 15:00 ` [PATCH 02/25] examples: use strlcpy instead of snprintf Stephen Hemminger
2023-06-01 15:00 ` [PATCH 03/25] lib: " Stephen Hemminger
2023-06-01 15:00 ` [PATCH 04/25] raw/ifpga: replace snprintf with strlcpy Stephen Hemminger
2023-06-02  6:04   ` Xu, Rosen
2023-06-01 15:00 ` [PATCH 05/25] common/cnxk: replace snprint " Stephen Hemminger
2023-06-01 15:00 ` [PATCH 06/25] common/mlx5: replace snprintf " Stephen Hemminger
2023-06-01 15:00 ` [PATCH 07/25] drivers/gpu: " Stephen Hemminger
2023-06-01 15:00 ` [PATCH 08/25] crypto/ipsec_mb: remove unnecessary snprintf Stephen Hemminger
2023-06-01 15:00 ` [PATCH 09/25] crypto/dpaa_sec: replace snprintf with strlcpy Stephen Hemminger
2023-06-02  4:24   ` Hemant Agrawal
2023-06-01 15:00 ` [PATCH 10/25] event/cnxk: " Stephen Hemminger
2023-06-01 15:00 ` [PATCH 11/25] net/atlantic: " Stephen Hemminger
2023-06-01 15:00 ` [PATCH 12/25] net/axgbe: " Stephen Hemminger
2023-06-01 15:00 ` [PATCH 13/25] net/bnxt: " Stephen Hemminger
2023-06-01 15:00 ` [PATCH 14/25] net/cpfl: " Stephen Hemminger
2023-06-01 15:00 ` [PATCH 15/25] net/cxgbe: " Stephen Hemminger
2023-06-01 15:00 ` [PATCH 16/25] net/dpaa*: " Stephen Hemminger
2023-06-02  4:24   ` Hemant Agrawal
2023-06-01 15:00 ` [PATCH 17/25] net/hinic: replace snptintf " Stephen Hemminger
2023-06-01 15:00 ` [PATCH 18/25] net/hns3: replace snprint " Stephen Hemminger
2023-06-01 15:01 ` [PATCH 19/25] net/intel: replace snprintf " Stephen Hemminger
2023-06-01 15:01 ` Stephen Hemminger [this message]
2023-06-02  6:05   ` [PATCH 20/25] net/ionic: " Xu, Rosen
2023-06-01 15:01 ` [PATCH 21/25] net/mlx5: " Stephen Hemminger
2023-06-01 15:01 ` [PATCH 22/25] net/nfp: " Stephen Hemminger
2023-06-05 11:10   ` Niklas Söderlund
2023-06-01 15:01 ` [PATCH 23/25] net/ngbe: " Stephen Hemminger
2023-06-01 15:01 ` [PATCH 24/25] net/qede: " Stephen Hemminger
2023-06-01 15:01 ` [PATCH 25/25] net/txgbe: " Stephen Hemminger
2023-06-02 20:01 ` [PATCH 00/25] " Tyler Retzlaff

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=20230601150106.18375-21-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=andrew.boyer@amd.com \
    --cc=dev@dpdk.org \
    --cc=rosen.xu@intel.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).