[18/25] net/hns3: replace snprint with strlcpy

Message ID 20230601150106.18375-19-stephen@networkplumber.org (mailing list archive)
State Rejected
Delegated to: Thomas Monjalon
Headers
Series replace snprintf with strlcpy |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger June 1, 2023, 3 p.m. UTC
  Suggested by devtools/cocci/strlcpy-with-header.cocci

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/hns3/hns3_fdir.c  |  2 +-
 drivers/net/hns3/hns3_rxtx.c  |  8 ++++----
 drivers/net/hns3/hns3_stats.c | 22 +++++++++++-----------
 3 files changed, 16 insertions(+), 16 deletions(-)
  

Patch

diff --git a/drivers/net/hns3/hns3_fdir.c b/drivers/net/hns3/hns3_fdir.c
index 48a91fb517de..766416432c57 100644
--- a/drivers/net/hns3/hns3_fdir.c
+++ b/drivers/net/hns3/hns3_fdir.c
@@ -843,7 +843,7 @@  int hns3_fdir_filter_init(struct hns3_adapter *hns)
 
 	fdir_hash_params.socket_id = rte_socket_id();
 	TAILQ_INIT(&fdir_info->fdir_list);
-	snprintf(fdir_hash_name, RTE_HASH_NAMESIZE, "%s", hns->hw.data->name);
+	strlcpy(fdir_hash_name, hns->hw.data->name, RTE_HASH_NAMESIZE);
 	fdir_info->hash_handle = rte_hash_create(&fdir_hash_params);
 	if (fdir_info->hash_handle == NULL) {
 		PMD_INIT_LOG(ERR, "Create FDIR hash handle fail!");
diff --git a/drivers/net/hns3/hns3_rxtx.c b/drivers/net/hns3/hns3_rxtx.c
index 4065c519c329..78921edcc9ab 100644
--- a/drivers/net/hns3/hns3_rxtx.c
+++ b/drivers/net/hns3/hns3_rxtx.c
@@ -2795,8 +2795,8 @@  hns3_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
 
 	for (i = 0; i < RTE_DIM(burst_infos); i++) {
 		if (pkt_burst == burst_infos[i].pkt_burst) {
-			snprintf(mode->info, sizeof(mode->info), "%s",
-				 burst_infos[i].info);
+			strlcpy(mode->info, burst_infos[i].info,
+				sizeof(mode->info));
 			ret = 0;
 			break;
 		}
@@ -4290,8 +4290,8 @@  hns3_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
 
 	for (i = 0; i < RTE_DIM(burst_infos); i++) {
 		if (pkt_burst == burst_infos[i].pkt_burst) {
-			snprintf(mode->info, sizeof(mode->info), "%s",
-				 burst_infos[i].info);
+			strlcpy(mode->info, burst_infos[i].info,
+				sizeof(mode->info));
 			ret = 0;
 			break;
 		}
diff --git a/drivers/net/hns3/hns3_stats.c b/drivers/net/hns3/hns3_stats.c
index bad65fcbed8b..2fd460813919 100644
--- a/drivers/net/hns3/hns3_stats.c
+++ b/drivers/net/hns3/hns3_stats.c
@@ -1176,9 +1176,9 @@  hns3_imissed_stats_name_get(struct rte_eth_dev *dev,
 	imissed_stats_num = hns3_get_imissed_stats_num(hns);
 
 	for (i = 0; i < imissed_stats_num; i++) {
-		snprintf(xstats_names[cnt].name,
-			 sizeof(xstats_names[cnt].name),
-			 "%s", hns3_imissed_stats_strings[i].name);
+		strlcpy(xstats_names[cnt].name,
+			hns3_imissed_stats_strings[i].name,
+			sizeof(xstats_names[cnt].name));
 		cnt++;
 	}
 
@@ -1228,9 +1228,9 @@  hns3_dev_xstats_get_names(struct rte_eth_dev *dev,
 	if (!hns->is_vf) {
 		/* Get MAC name from hw->hw_xstats.mac_stats struct */
 		for (i = 0; i < HNS3_NUM_MAC_STATS; i++) {
-			snprintf(xstats_names[count].name,
-				 sizeof(xstats_names[count].name),
-				 "%s", hns3_mac_strings[i].name);
+			strlcpy(xstats_names[count].name,
+				hns3_mac_strings[i].name,
+				sizeof(xstats_names[count].name));
 			count++;
 		}
 	}
@@ -1238,9 +1238,9 @@  hns3_dev_xstats_get_names(struct rte_eth_dev *dev,
 	hns3_imissed_stats_name_get(dev, xstats_names, &count);
 
 	for (i = 0; i < HNS3_NUM_RESET_XSTATS; i++) {
-		snprintf(xstats_names[count].name,
-			 sizeof(xstats_names[count].name),
-			 "%s", hns3_reset_stats_strings[i].name);
+		strlcpy(xstats_names[count].name,
+			hns3_reset_stats_strings[i].name,
+			sizeof(xstats_names[count].name));
 		count++;
 	}
 
@@ -1418,8 +1418,8 @@  hns3_dev_xstats_get_names_by_id(struct rte_eth_dev *dev,
 			rte_free(names_copy);
 			return -EINVAL;
 		}
-		snprintf(xstats_names[i].name, sizeof(xstats_names[i].name),
-			 "%s", names_copy[ids[i]].name);
+		strlcpy(xstats_names[i].name, names_copy[ids[i]].name,
+			sizeof(xstats_names[i].name));
 	}
 
 	rte_free(names_copy);