[20/25] net/ionic: replace snprintf with strlcpy

Message ID 20230601150106.18375-21-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:01 p.m. UTC
  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(-)
  

Comments

Xu, Rosen June 2, 2023, 6:05 a.m. UTC | #1
Hi,

> -----Original Message-----
> From: Stephen Hemminger <stephen@networkplumber.org>
> Sent: Thursday, June 1, 2023 11:01 PM
> To: dev@dpdk.org
> Cc: Stephen Hemminger <stephen@networkplumber.org>; Andrew Boyer
> <andrew.boyer@amd.com>; Xu, Rosen <rosen.xu@intel.com>
> Subject: [PATCH 20/25] net/ionic: replace snprintf with strlcpy
> 
> Suggested by devtools/cocci/strlcpy-with-header.cocci
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  drivers/net/ipn3ke/ipn3ke_representor.c | 17 +++++++----------


> 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

Reviewed-by: Rosen Xu <rosen.xu@intel.com>
  

Patch

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++;
 	}