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>,
	Ziyang Xuan <xuanziyang2@huawei.com>,
	Xiaoyun Wang <cloud.wangxiaoyun@huawei.com>,
	Guoyang Zhou <zhouguoyang@huawei.com>
Subject: [PATCH 17/25] net/hinic: replace snptintf with strlcpy
Date: Thu,  1 Jun 2023 08:00:58 -0700	[thread overview]
Message-ID: <20230601150106.18375-18-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/hinic/base/hinic_compat.h     |  1 +
 drivers/net/hinic/base/hinic_pmd_niccfg.c |  4 +---
 drivers/net/hinic/hinic_pmd_ethdev.c      | 14 +++++++-------
 3 files changed, 9 insertions(+), 10 deletions(-)

diff --git a/drivers/net/hinic/base/hinic_compat.h b/drivers/net/hinic/base/hinic_compat.h
index aea332046ede..e8d0badb792a 100644
--- a/drivers/net/hinic/base/hinic_compat.h
+++ b/drivers/net/hinic/base/hinic_compat.h
@@ -19,6 +19,7 @@
 #include <rte_spinlock.h>
 #include <rte_cycles.h>
 #include <rte_log.h>
+#include <rte_string_fns.h>
 
 typedef uint8_t   u8;
 typedef int8_t    s8;
diff --git a/drivers/net/hinic/base/hinic_pmd_niccfg.c b/drivers/net/hinic/base/hinic_pmd_niccfg.c
index 8c08d63286df..eb127a308a0b 100644
--- a/drivers/net/hinic/base/hinic_pmd_niccfg.c
+++ b/drivers/net/hinic/base/hinic_pmd_niccfg.c
@@ -1337,7 +1337,7 @@ int hinic_get_mgmt_version(void *hwdev, char *fw)
 		return -EIO;
 	}
 
-	snprintf(fw, HINIC_MGMT_VERSION_MAX_LEN, "%s", fw_ver.ver);
+	strlcpy(fw, (const char *)fw_ver.ver, HINIC_MGMT_VERSION_MAX_LEN);
 
 	return 0;
 }
@@ -2115,5 +2115,3 @@ int hinic_set_fdir_tcam_rule_filter(void *hwdev, bool enable)
 
 	return err;
 }
-
-
diff --git a/drivers/net/hinic/hinic_pmd_ethdev.c b/drivers/net/hinic/hinic_pmd_ethdev.c
index 7aa5e7d8e929..bb4d5a3f0f85 100644
--- a/drivers/net/hinic/hinic_pmd_ethdev.c
+++ b/drivers/net/hinic/hinic_pmd_ethdev.c
@@ -786,7 +786,7 @@ static int hinic_fw_version_get(struct rte_eth_dev *dev, char *fw_version,
 	if (fw_size < strlen(fw_ver) + 1)
 		return (strlen(fw_ver) + 1);
 
-	snprintf(fw_version, fw_size, "%s", fw_ver);
+	strlcpy(fw_version, fw_ver, fw_size);
 
 	return 0;
 }
@@ -2302,9 +2302,9 @@ static int hinic_dev_xstats_get_names(struct rte_eth_dev *dev,
 
 	/* get vport stats */
 	for (i = 0; i < HINIC_VPORT_XSTATS_NUM; i++) {
-		snprintf(xstats_names[count].name,
-			 sizeof(xstats_names[count].name),
-			 "%s", hinic_vport_stats_strings[i].name);
+		strlcpy(xstats_names[count].name,
+			hinic_vport_stats_strings[i].name,
+			sizeof(xstats_names[count].name));
 		count++;
 	}
 
@@ -2313,9 +2313,9 @@ static int hinic_dev_xstats_get_names(struct rte_eth_dev *dev,
 
 	/* get phy port stats */
 	for (i = 0; i < HINIC_PHYPORT_XSTATS_NUM; i++) {
-		snprintf(xstats_names[count].name,
-			 sizeof(xstats_names[count].name),
-			 "%s", hinic_phyport_stats_strings[i].name);
+		strlcpy(xstats_names[count].name,
+			hinic_phyport_stats_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] replace snprintf " 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 ` Stephen Hemminger [this message]
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 ` [PATCH 20/25] net/ionic: " Stephen Hemminger
2023-06-02  6:05   ` 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-18-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=cloud.wangxiaoyun@huawei.com \
    --cc=dev@dpdk.org \
    --cc=xuanziyang2@huawei.com \
    --cc=zhouguoyang@huawei.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).