DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH 00/25] replace snprintf with strlcpy
@ 2023-06-01 15:00 Stephen Hemminger
  2023-06-01 15:00 ` [PATCH 01/25] app: use strlcpy in tests Stephen Hemminger
                   ` (25 more replies)
  0 siblings, 26 replies; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:00 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger

This patch series was generated by using the existing
Coccinelle script to find where snprintf() is used but
strlcpy() could be used instead.

Manually replaced fixed some trigraphs and paren's where
needed. Also one instance the whole temporary string
copy was not needed at all.

Stephen Hemminger (25):
  app: use strlcpy in tests
  examples: use strlcpy instead of snprintf
  lib: use strlcpy instead of snprintf
  raw/ifpga: replace snprintf with strlcpy
  common/cnxk: replace snprint with strlcpy
  common/mlx5: replace snprintf with strlcpy
  drivers/gpu: replace snprintf with strlcpy
  crypto/ipsec_mb: remove unnecessary snprintf
  crypto/dpaa_sec: replace snprintf with strlcpy
  event/cnxk: replace snprintf with strlcpy
  net/atlantic: replace snprintf with strlcpy
  net/axgbe: replace snprintf with strlcpy
  net/bnxt: replace snprintf with strlcpy
  net/cpfl: replace snprintf with strlcpy
  net/cxgbe: replace snprintf with strlcpy
  net/dpaa*: replace snprintf with strlcpy
  net/hinic: replace snptintf with strlcpy
  net/hns3: replace snprint with strlcpy
  net/intel: replace snprintf with strlcpy
  net/ionic: replace snprintf with strlcpy
  net/mlx5: replace snprintf with strlcpy
  net/nfp: replace snprintf with strlcpy
  net/ngbe: replace snprintf with strlcpy
  net/qede: replace snprintf with strlcpy
  net/txgbe: replace snprintf with strlcpy

 app/test-bbdev/main.c                         |  5 ++--
 app/test-pmd/cmdline_flow.c                   |  6 ++--
 app/test/process.h                            |  2 +-
 app/test/test_graph_perf.c                    | 29 ++++++++++---------
 drivers/common/cnxk/roc_nix_stats.c           |  4 +--
 drivers/common/mlx5/linux/mlx5_common_os.c    |  2 +-
 drivers/common/mlx5/mlx5_common_utils.c       |  5 ++--
 drivers/crypto/dpaa_sec/dpaa_sec.c            |  2 +-
 drivers/crypto/ipsec_mb/ipsec_mb_ops.c        |  7 +----
 drivers/event/cnxk/cnxk_eventdev_stats.c      | 11 ++++---
 drivers/gpu/cuda/cuda.c                       |  2 +-
 drivers/gpu/cuda/gdrcopy.c                    |  2 +-
 drivers/net/atlantic/atl_ethdev.c             |  5 ++--
 drivers/net/axgbe/axgbe_ethdev.c              |  6 ++--
 drivers/net/bnxt/bnxt_ethdev.c                |  8 ++---
 drivers/net/cpfl/cpfl_ethdev.c                |  6 ++--
 drivers/net/cxgbe/cxgbe_ethdev.c              |  9 +++---
 drivers/net/dpaa/dpaa_ethdev.c                |  8 ++---
 drivers/net/dpaa2/dpaa2_ethdev.c              |  8 ++---
 drivers/net/fm10k/fm10k_ethdev.c              |  6 ++--
 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 ++++-----
 drivers/net/hns3/hns3_fdir.c                  |  2 +-
 drivers/net/hns3/hns3_rxtx.c                  |  8 ++---
 drivers/net/hns3/hns3_stats.c                 | 22 +++++++-------
 drivers/net/i40e/i40e_rxtx.c                  |  8 ++---
 drivers/net/iavf/iavf_ethdev.c                |  6 ++--
 drivers/net/ice/ice_dcf_ethdev.c              |  6 ++--
 drivers/net/ice/ice_rxtx.c                    |  8 ++---
 drivers/net/idpf/idpf_ethdev.c                |  6 ++--
 drivers/net/ionic/ionic_ethdev.c              | 15 +++++-----
 drivers/net/ipn3ke/ipn3ke_representor.c       | 17 +++++------
 drivers/net/mlx5/mlx5_rx.c                    | 16 +++++-----
 .../net/nfp/flower/nfp_flower_representor.c   |  4 +--
 drivers/net/ngbe/ngbe_rxtx.c                  |  8 ++---
 drivers/net/qede/qede_ethdev.c                | 10 +++----
 drivers/net/txgbe/txgbe_ethdev_vf.c           |  6 ++--
 drivers/raw/ifpga/afu_pmd_core.c              |  3 +-
 examples/fips_validation/fips_validation.c    |  8 ++---
 examples/l3fwd-graph/main.c                   |  2 +-
 examples/pipeline/cli.c                       |  2 +-
 examples/vhost_blk/vhost_blk.c                |  5 ++--
 lib/bbdev/rte_bbdev.c                         |  2 +-
 lib/ethdev/sff_8636.c                         | 11 ++++---
 45 files changed, 157 insertions(+), 170 deletions(-)

-- 
2.39.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 01/25] app: use strlcpy in tests
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
@ 2023-06-01 15:00 ` Stephen Hemminger
  2023-06-01 15:00 ` [PATCH 02/25] examples: use strlcpy instead of snprintf Stephen Hemminger
                   ` (24 subsequent siblings)
  25 siblings, 0 replies; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:00 UTC (permalink / raw)
  To: dev
  Cc: Stephen Hemminger, Nicolas Chautru, Ori Kam, Aman Singh,
	Yuying Zhang, Jerin Jacob, Kiran Kumar K, Nithin Dabilpuram

Prefer using strlcpy over snprintf().

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 app/test-bbdev/main.c       |  5 ++---
 app/test-pmd/cmdline_flow.c |  6 +++---
 app/test/process.h          |  2 +-
 app/test/test_graph_perf.c  | 29 ++++++++++++++++-------------
 4 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/app/test-bbdev/main.c b/app/test-bbdev/main.c
index ec830eb32bc8..b1f2d79f4b07 100644
--- a/app/test-bbdev/main.c
+++ b/app/test-bbdev/main.c
@@ -251,9 +251,8 @@ parse_args(int argc, char **argv, struct test_params *tp)
 			TEST_ASSERT(strlen(optarg) > 0,
 					"Config file name is null");
 
-			snprintf(tp->test_vector_filename,
-					sizeof(tp->test_vector_filename),
-					"%s", optarg);
+			strlcpy(tp->test_vector_filename, optarg,
+				sizeof(tp->test_vector_filename));
 			break;
 		case 's':
 			TEST_ASSERT(strlen(optarg) > 0,
diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 58939ec321d6..40f67d126b4b 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -10028,7 +10028,7 @@ parse_hex_string(const char *src, uint8_t *dst, uint32_t *size)
 		char tmp[3], *end = tmp;
 		uint32_t read_lim = left & 1 ? 1 : 2;
 
-		snprintf(tmp, read_lim + 1, "%s", src);
+		strlcpy(tmp, src, read_lim + 1);
 		*dst = strtoul(tmp, &end, 16);
 		if (*end) {
 			*dst = 0;
@@ -11404,7 +11404,7 @@ cmd_flow_get_help(cmdline_parse_token_hdr_t *hdr, char *dst, unsigned int size)
 	if (!size)
 		return -1;
 	/* Set token type and update global help with details. */
-	strlcpy(dst, (token->type ? token->type : "TOKEN"), size);
+	strlcpy(dst, token->type ? : "TOKEN", size);
 	if (token->help)
 		cmd_flow.help_str = token->help;
 	else
@@ -12220,7 +12220,7 @@ cmd_set_raw_get_help(cmdline_parse_token_hdr_t *hdr, char *dst,
 	if (!size)
 		return -1;
 	/* Set token type and update global help with details. */
-	snprintf(dst, size, "%s", (token->type ? token->type : "TOKEN"));
+	strlcpy(dst, token->type ? : "TOKEN", size);
 	if (token->help)
 		cmd_set_raw.help_str = token->help;
 	else
diff --git a/app/test/process.h b/app/test/process.h
index 1f073b9c5c2a..e2bdecb9c807 100644
--- a/app/test/process.h
+++ b/app/test/process.h
@@ -176,7 +176,7 @@ get_current_prefix(char *prefix, int size)
 		return NULL;
 
 	/* get the prefix */
-	snprintf(prefix, size, "%s", basename(dirname(buf)));
+	strlcpy(prefix, basename(dirname(buf)), size);
 
 	return prefix;
 }
diff --git a/app/test/test_graph_perf.c b/app/test/test_graph_perf.c
index c5b463f700cd..521d4077600d 100644
--- a/app/test/test_graph_perf.c
+++ b/app/test/test_graph_perf.c
@@ -294,8 +294,9 @@ graph_node_count_edges(uint32_t stage, uint16_t node, uint16_t nodes_per_stage,
 	for (i = 0; i < nodes_per_stage && edges < MAX_EDGES_PER_NODE; i++) {
 		if (edge_map[stage + 1][i][node]) {
 			ename[edges] = malloc(sizeof(char) * RTE_NODE_NAMESIZE);
-			snprintf(ename[edges], RTE_NODE_NAMESIZE, "%s",
-				 rte_node_id_to_name(node_map[stage + 1][i]));
+			strlcpy(ename[edges],
+				rte_node_id_to_name(node_map[stage + 1][i]),
+				RTE_NODE_NAMESIZE);
 			node_data->next_nodes[edges] = node_map[stage + 1][i];
 			node_data->next_percentage[edges] =
 				edge_map[stage + 1][i][node];
@@ -405,9 +406,9 @@ graph_init(const char *gname, uint8_t nb_srcs, uint8_t nb_sinks,
 				graph_data->nb_nodes++;
 				goto pattern_name_free;
 			}
-			snprintf(node_patterns[graph_data->nb_nodes],
-				 RTE_NODE_NAMESIZE, "%s",
-				 rte_node_id_to_name(node_map[i][j]));
+			strlcpy(node_patterns[graph_data->nb_nodes],
+				rte_node_id_to_name(node_map[i][j]),
+				RTE_NODE_NAMESIZE);
 			node_data =
 				&graph_data->node_data[graph_data->nb_nodes];
 			node_data->node_id = node_map[i][j];
@@ -467,8 +468,8 @@ graph_init(const char *gname, uint8_t nb_srcs, uint8_t nb_sinks,
 			graph_data->nb_nodes++;
 			goto pattern_name_free;
 		}
-		snprintf(node_patterns[graph_data->nb_nodes], RTE_NODE_NAMESIZE,
-			 "%s", rte_node_id_to_name(src_nodes[i]));
+		strlcpy(node_patterns[graph_data->nb_nodes],
+			rte_node_id_to_name(src_nodes[i]), RTE_NODE_NAMESIZE);
 		node_data = &graph_data->node_data[graph_data->nb_nodes];
 		node_data->node_id = src_nodes[i];
 		node_data->is_sink = false;
@@ -479,8 +480,9 @@ graph_init(const char *gname, uint8_t nb_srcs, uint8_t nb_sinks,
 			if (!src_map[i][j])
 				continue;
 			ename[edges] = malloc(sizeof(char) * RTE_NODE_NAMESIZE);
-			snprintf(ename[edges], RTE_NODE_NAMESIZE, "%s",
-				 rte_node_id_to_name(node_map[0][j]));
+			strlcpy(ename[edges],
+				rte_node_id_to_name(node_map[0][j]),
+				RTE_NODE_NAMESIZE);
 			node_data->next_nodes[edges] = node_map[0][j];
 			node_data->next_percentage[edges] = src_map[i][j];
 			edges++;
@@ -524,8 +526,8 @@ graph_init(const char *gname, uint8_t nb_srcs, uint8_t nb_sinks,
 			graph_data->nb_nodes++;
 			goto pattern_name_free;
 		}
-		snprintf(node_patterns[graph_data->nb_nodes], RTE_NODE_NAMESIZE,
-			 "%s", rte_node_id_to_name(snk_nodes[i]));
+		strlcpy(node_patterns[graph_data->nb_nodes],
+			rte_node_id_to_name(snk_nodes[i]), RTE_NODE_NAMESIZE);
 		node_data = &graph_data->node_data[graph_data->nb_nodes];
 		node_data->node_id = snk_nodes[i];
 		node_data->is_sink = true;
@@ -543,8 +545,9 @@ graph_init(const char *gname, uint8_t nb_srcs, uint8_t nb_sinks,
 			if (!snk_map[i][j])
 				continue;
 			ename[edges] = malloc(sizeof(char) * RTE_NODE_NAMESIZE);
-			snprintf(ename[edges], RTE_NODE_NAMESIZE, "%s",
-				 rte_node_id_to_name(snk_nodes[j]));
+			strlcpy(ename[edges],
+				rte_node_id_to_name(snk_nodes[j]),
+				RTE_NODE_NAMESIZE);
 			node_data->next_nodes[edges] = snk_nodes[j];
 			node_data->next_percentage[edges] = snk_map[i][j];
 			edges++;
-- 
2.39.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 02/25] examples: use strlcpy instead of snprintf
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
  2023-06-01 15:00 ` [PATCH 01/25] app: use strlcpy in tests Stephen Hemminger
@ 2023-06-01 15:00 ` Stephen Hemminger
  2023-06-01 15:00 ` [PATCH 03/25] lib: " Stephen Hemminger
                   ` (23 subsequent siblings)
  25 siblings, 0 replies; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:00 UTC (permalink / raw)
  To: dev
  Cc: Stephen Hemminger, Brian Dooley, Gowrishankar Muthukrishnan,
	Jerin Jacob, Kiran Kumar K, Nithin Dabilpuram,
	Cristian Dumitrescu, Maxime Coquelin, Chenbo Xia

Replace snprintf() with strlcpy() where possible.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 examples/fips_validation/fips_validation.c | 8 ++++----
 examples/l3fwd-graph/main.c                | 2 +-
 examples/pipeline/cli.c                    | 2 +-
 examples/vhost_blk/vhost_blk.c             | 5 ++---
 4 files changed, 8 insertions(+), 9 deletions(-)

diff --git a/examples/fips_validation/fips_validation.c b/examples/fips_validation/fips_validation.c
index f840804009ed..6e913898074d 100644
--- a/examples/fips_validation/fips_validation.c
+++ b/examples/fips_validation/fips_validation.c
@@ -505,8 +505,8 @@ fips_test_parse_one_json_group(void)
 
 			switch (json_typeof(param)) {
 			case JSON_STRING:
-				snprintf(json_value, sizeof(json_value), "%s",
-						 json_string_value(param));
+				strlcpy(json_value, json_string_value(param),
+					sizeof(json_value));
 				break;
 
 			case JSON_INTEGER:
@@ -550,8 +550,8 @@ fips_test_parse_one_json_case(void)
 
 		switch (json_typeof(param)) {
 		case JSON_STRING:
-			snprintf(info.one_line_text, MAX_LINE_CHAR, "%s",
-					 json_string_value(param));
+			strlcpy(info.one_line_text, json_string_value(param),
+				MAX_LINE_CHAR);
 			break;
 
 		case JSON_INTEGER:
diff --git a/examples/l3fwd-graph/main.c b/examples/l3fwd-graph/main.c
index 5feeab4f0fb0..ee8f247108ad 100644
--- a/examples/l3fwd-graph/main.c
+++ b/examples/l3fwd-graph/main.c
@@ -546,7 +546,7 @@ parse_args(int argc, char **argv)
 			break;
 
 		case CMD_LINE_OPT_PCAP_FILENAME_CAP:
-			rte_strlcpy(pcap_filename, optarg,
+			strlcpy(pcap_filename, optarg,
 				    sizeof(pcap_filename));
 			printf("Pcap file name: %s\n", pcap_filename);
 			break;
diff --git a/examples/pipeline/cli.c b/examples/pipeline/cli.c
index 2ae6cc579ff2..514b6d779212 100644
--- a/examples/pipeline/cli.c
+++ b/examples/pipeline/cli.c
@@ -3164,7 +3164,7 @@ cmd_ipsec_sa_add(char **tokens,
 			goto free;
 		}
 
-		snprintf(out, out_size, "%s", line);
+		strlcpy(out, line, out_size);
 		out_size -= strlen(out);
 		out += strlen(out);
 
diff --git a/examples/vhost_blk/vhost_blk.c b/examples/vhost_blk/vhost_blk.c
index 3709d7ed06ba..3b05df390cce 100644
--- a/examples/vhost_blk/vhost_blk.c
+++ b/examples/vhost_blk/vhost_blk.c
@@ -771,9 +771,8 @@ vhost_blk_bdev_construct(const char *bdev_name,
 	if (!bdev)
 		return NULL;
 
-	snprintf(bdev->name, sizeof(bdev->name), "%s", bdev_name);
-	snprintf(bdev->product_name, sizeof(bdev->product_name), "%s",
-		 bdev_serial);
+	strlcpy(bdev->name, bdev_name, sizeof(bdev->name));
+	strlcpy(bdev->product_name, bdev_serial, sizeof(bdev->product_name));
 	bdev->blocklen = blk_size;
 	bdev->blockcnt = blk_cnt;
 	bdev->write_cache = wce_enable;
-- 
2.39.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 03/25] lib: use strlcpy instead of snprintf
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy 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 ` Stephen Hemminger
  2023-06-01 15:00 ` [PATCH 04/25] raw/ifpga: replace snprintf with strlcpy Stephen Hemminger
                   ` (22 subsequent siblings)
  25 siblings, 0 replies; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:00 UTC (permalink / raw)
  To: dev
  Cc: Stephen Hemminger, Nicolas Chautru, Thomas Monjalon,
	Ferruh Yigit, Andrew Rybchenko

Replace snprintf with strlcpy where possible.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/bbdev/rte_bbdev.c |  2 +-
 lib/ethdev/sff_8636.c | 11 +++++++----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/bbdev/rte_bbdev.c b/lib/bbdev/rte_bbdev.c
index 581509b5a213..7cc126a0e7be 100644
--- a/lib/bbdev/rte_bbdev.c
+++ b/lib/bbdev/rte_bbdev.c
@@ -212,7 +212,7 @@ rte_bbdev_allocate(const char *name)
 	bbdev->data->dev_id = dev_id;
 	bbdev->state = RTE_BBDEV_INITIALIZED;
 
-	ret = snprintf(bbdev->data->name, RTE_BBDEV_NAME_MAX_LEN, "%s", name);
+	ret = strlcpy(bbdev->data->name, name, RTE_BBDEV_NAME_MAX_LEN);
 	if ((ret < 0) || (ret >= RTE_BBDEV_NAME_MAX_LEN)) {
 		rte_bbdev_log(ERR, "Copying device name \"%s\" failed", name);
 		return NULL;
diff --git a/lib/ethdev/sff_8636.c b/lib/ethdev/sff_8636.c
index 6b65f47efedf..a623e0d065d8 100644
--- a/lib/ethdev/sff_8636.c
+++ b/lib/ethdev/sff_8636.c
@@ -203,16 +203,19 @@ static void sff_8636_show_ext_identifier(const uint8_t *data, struct rte_tel_dat
 
 	switch (data[SFF_8636_EXT_ID_OFFSET] & SFF_8636_EXT_ID_EPWR_CLASS_MASK) {
 	case SFF_8636_EXT_ID_PWR_CLASS_LEGACY:
-		snprintf(val_string, sizeof(val_string), "%s", "");
+		strlcpy(val_string, "", sizeof(val_string));
 		break;
 	case SFF_8636_EXT_ID_PWR_CLASS_5:
-		snprintf(val_string, sizeof(val_string), "%s", "4.0W max. Power consumption, ");
+		strlcpy(val_string, "4.0W max. Power consumption, ",
+			sizeof(val_string));
 		break;
 	case SFF_8636_EXT_ID_PWR_CLASS_6:
-		snprintf(val_string, sizeof(val_string), "%s", "4.5W max. Power consumption, ");
+		strlcpy(val_string, "4.5W max. Power consumption, ",
+			sizeof(val_string));
 		break;
 	case SFF_8636_EXT_ID_PWR_CLASS_7:
-		snprintf(val_string, sizeof(val_string), "%s", "5.0W max. Power consumption, ");
+		strlcpy(val_string, "5.0W max. Power consumption, ",
+			sizeof(val_string));
 		break;
 	}
 
-- 
2.39.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 04/25] raw/ifpga: replace snprintf with strlcpy
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
                   ` (2 preceding siblings ...)
  2023-06-01 15:00 ` [PATCH 03/25] lib: " Stephen Hemminger
@ 2023-06-01 15:00 ` Stephen Hemminger
  2023-06-02  6:04   ` Xu, Rosen
  2023-06-01 15:00 ` [PATCH 05/25] common/cnxk: replace snprint " Stephen Hemminger
                   ` (21 subsequent siblings)
  25 siblings, 1 reply; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:00 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Rosen Xu, Tianfei Zhang

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

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/raw/ifpga/afu_pmd_core.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/drivers/raw/ifpga/afu_pmd_core.c b/drivers/raw/ifpga/afu_pmd_core.c
index 3ab1f47ac1a4..e969897dbe7d 100644
--- a/drivers/raw/ifpga/afu_pmd_core.c
+++ b/drivers/raw/ifpga/afu_pmd_core.c
@@ -16,6 +16,7 @@
 #include <rte_malloc.h>
 #include <rte_memzone.h>
 #include <rte_rawdev_pmd.h>
+#include <rte_string_fns.h>
 
 #include "afu_pmd_core.h"
 
@@ -225,7 +226,7 @@ static int afu_shared_data_alloc(const char *name,
 		return -EINVAL;
 
 	/* name format is afu_?|??:??.? which is unique */
-	snprintf(mz_name, sizeof(mz_name), "%s", name);
+	strlcpy(mz_name, name, sizeof(mz_name));
 
 	mz = rte_memzone_lookup(mz_name);
 	if (!mz) {
-- 
2.39.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 05/25] common/cnxk: replace snprint with strlcpy
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
                   ` (3 preceding siblings ...)
  2023-06-01 15:00 ` [PATCH 04/25] raw/ifpga: replace snprintf with strlcpy Stephen Hemminger
@ 2023-06-01 15:00 ` Stephen Hemminger
  2023-06-01 15:00 ` [PATCH 06/25] common/mlx5: replace snprintf " Stephen Hemminger
                   ` (20 subsequent siblings)
  25 siblings, 0 replies; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:00 UTC (permalink / raw)
  To: dev
  Cc: Stephen Hemminger, Nithin Dabilpuram, Kiran Kumar K,
	Sunil Kumar Kori, Satha Rao

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

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/common/cnxk/roc_nix_stats.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/common/cnxk/roc_nix_stats.c b/drivers/common/cnxk/roc_nix_stats.c
index 6b5803af8442..b2e1c8cd05ad 100644
--- a/drivers/common/cnxk/roc_nix_stats.c
+++ b/drivers/common/cnxk/roc_nix_stats.c
@@ -16,9 +16,7 @@
 #define NIX_XSTATS_NAME_PRINT(xstats_names, count, xstats, index)              \
 	do {                                                                   \
 		if (xstats_names)                                              \
-			snprintf(xstats_names[count].name,                     \
-				 sizeof(xstats_names[count].name), "%s",       \
-				 xstats[index].name);                          \
+			strlcpy(xstats_names[count].name, xstats[index].name, sizeof(xstats_names[count].name));                          \
 	} while (0)
 
 int
-- 
2.39.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 06/25] common/mlx5: replace snprintf with strlcpy
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
                   ` (4 preceding siblings ...)
  2023-06-01 15:00 ` [PATCH 05/25] common/cnxk: replace snprint " Stephen Hemminger
@ 2023-06-01 15:00 ` Stephen Hemminger
  2023-06-01 15:00 ` [PATCH 07/25] drivers/gpu: " Stephen Hemminger
                   ` (19 subsequent siblings)
  25 siblings, 0 replies; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:00 UTC (permalink / raw)
  To: dev
  Cc: Stephen Hemminger, Matan Azrad, Viacheslav Ovsiienko, Ori Kam,
	Suanming Mou

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

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/common/mlx5/linux/mlx5_common_os.c | 2 +-
 drivers/common/mlx5/mlx5_common_utils.c    | 5 ++---
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/common/mlx5/linux/mlx5_common_os.c b/drivers/common/mlx5/linux/mlx5_common_os.c
index aafff60eeb38..c4ceeccf3825 100644
--- a/drivers/common/mlx5/linux/mlx5_common_os.c
+++ b/drivers/common/mlx5/linux/mlx5_common_os.c
@@ -897,7 +897,7 @@ mlx5_get_device_guid(const struct rte_pci_addr *dev, uint8_t *guid, size_t len)
 		}
 	} while (strchr(ptr->d_name, '.') || strchr(ptr->d_name, '_') ||
 		 strchr(ptr->d_name, 'v'));
-	snprintf(cur_ifname, sizeof(cur_ifname), "%s", ptr->d_name);
+	strlcpy(cur_ifname, ptr->d_name, sizeof(cur_ifname));
 	closedir(dir);
 	snprintf(tmp + strlen(tmp), sizeof(tmp) - strlen(tmp),
 			"/%s/phys_switch_id", cur_ifname);
diff --git a/drivers/common/mlx5/mlx5_common_utils.c b/drivers/common/mlx5/mlx5_common_utils.c
index e69d06878c2e..3e809b409854 100644
--- a/drivers/common/mlx5/mlx5_common_utils.c
+++ b/drivers/common/mlx5/mlx5_common_utils.c
@@ -49,8 +49,7 @@ mlx5_list_create(const char *name, void *ctx, bool lcores_share,
 	if (!list)
 		return NULL;
 	if (name)
-		snprintf(list->l_const.name,
-			 sizeof(list->l_const.name), "%s", name);
+		strlcpy(list->l_const.name, name, sizeof(list->l_const.name));
 	list->l_const.ctx = ctx;
 	list->l_const.lcores_share = lcores_share;
 	list->l_const.cb_create = cb_create;
@@ -422,7 +421,7 @@ mlx5_hlist_create(const char *name, uint32_t size, bool direct_key,
 		return NULL;
 	}
 	if (name)
-		snprintf(h->l_const.name, sizeof(h->l_const.name), "%s", name);
+		strlcpy(h->l_const.name, name, sizeof(h->l_const.name));
 	h->l_const.ctx = ctx;
 	h->l_const.lcores_share = lcores_share;
 	h->l_const.cb_create = cb_create;
-- 
2.39.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 07/25] drivers/gpu: replace snprintf with strlcpy
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
                   ` (5 preceding siblings ...)
  2023-06-01 15:00 ` [PATCH 06/25] common/mlx5: replace snprintf " Stephen Hemminger
@ 2023-06-01 15:00 ` Stephen Hemminger
  2023-06-01 15:00 ` [PATCH 08/25] crypto/ipsec_mb: remove unnecessary snprintf Stephen Hemminger
                   ` (18 subsequent siblings)
  25 siblings, 0 replies; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:00 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Elena Agostini

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

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/gpu/cuda/cuda.c    | 2 +-
 drivers/gpu/cuda/gdrcopy.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/cuda/cuda.c b/drivers/gpu/cuda/cuda.c
index a552aabeb82d..01875816d592 100644
--- a/drivers/gpu/cuda/cuda.c
+++ b/drivers/gpu/cuda/cuda.c
@@ -291,7 +291,7 @@ cuda_loader(void)
 	char cuda_path[1024];
 
 	if (getenv("CUDA_PATH_L") == NULL)
-		snprintf(cuda_path, 1024, "%s", "libcuda.so");
+		strlcpy(cuda_path, "libcuda.so", 1024);
 	else
 		snprintf(cuda_path, 1024, "%s/%s", getenv("CUDA_PATH_L"), "libcuda.so");
 
diff --git a/drivers/gpu/cuda/gdrcopy.c b/drivers/gpu/cuda/gdrcopy.c
index 322a5dbeb207..ad7809a99b00 100644
--- a/drivers/gpu/cuda/gdrcopy.c
+++ b/drivers/gpu/cuda/gdrcopy.c
@@ -20,7 +20,7 @@ gdrcopy_loader(void)
 	char gdrcopy_path[1024];
 
 	if (getenv("GDRCOPY_PATH_L") == NULL)
-		snprintf(gdrcopy_path, 1024, "%s", "libgdrapi.so");
+		strlcpy(gdrcopy_path, "libgdrapi.so", 1024);
 	else
 		snprintf(gdrcopy_path, 1024, "%s/%s", getenv("GDRCOPY_PATH_L"), "libgdrapi.so");
 
-- 
2.39.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 08/25] crypto/ipsec_mb: remove unnecessary snprintf
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
                   ` (6 preceding siblings ...)
  2023-06-01 15:00 ` [PATCH 07/25] drivers/gpu: " Stephen Hemminger
@ 2023-06-01 15:00 ` Stephen Hemminger
  2023-06-01 15:00 ` [PATCH 09/25] crypto/dpaa_sec: replace snprintf with strlcpy Stephen Hemminger
                   ` (17 subsequent siblings)
  25 siblings, 0 replies; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:00 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Kai Ji, Pablo de Lara

Can just use the ring name directly.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/crypto/ipsec_mb/ipsec_mb_ops.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/crypto/ipsec_mb/ipsec_mb_ops.c b/drivers/crypto/ipsec_mb/ipsec_mb_ops.c
index 3e52f9567401..4af6592f12c5 100644
--- a/drivers/crypto/ipsec_mb/ipsec_mb_ops.c
+++ b/drivers/crypto/ipsec_mb/ipsec_mb_ops.c
@@ -185,12 +185,7 @@ static struct rte_ring
 	struct ipsec_mb_qp *qp, unsigned int ring_size, int socket_id)
 {
 	struct rte_ring *r;
-	char ring_name[RTE_CRYPTODEV_NAME_MAX_LEN];
-
-	unsigned int n = rte_strlcpy(ring_name, qp->name, sizeof(ring_name));
-
-	if (n >= sizeof(ring_name))
-		return NULL;
+	const char *ring_name = qp->name;
 
 	r = rte_ring_lookup(ring_name);
 	if (r) {
-- 
2.39.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 09/25] crypto/dpaa_sec: replace snprintf with strlcpy
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
                   ` (7 preceding siblings ...)
  2023-06-01 15:00 ` [PATCH 08/25] crypto/ipsec_mb: remove unnecessary snprintf Stephen Hemminger
@ 2023-06-01 15:00 ` Stephen Hemminger
  2023-06-02  4:24   ` Hemant Agrawal
  2023-06-01 15:00 ` [PATCH 10/25] event/cnxk: " Stephen Hemminger
                   ` (16 subsequent siblings)
  25 siblings, 1 reply; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:00 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Gagandeep Singh, Hemant Agrawal

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

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/crypto/dpaa_sec/dpaa_sec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/crypto/dpaa_sec/dpaa_sec.c b/drivers/crypto/dpaa_sec/dpaa_sec.c
index db5268384786..0df3a9f1e9b9 100644
--- a/drivers/crypto/dpaa_sec/dpaa_sec.c
+++ b/drivers/crypto/dpaa_sec/dpaa_sec.c
@@ -3740,7 +3740,7 @@ cryptodev_dpaa_sec_probe(struct rte_dpaa_driver *dpaa_drv __rte_unused,
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
 		return 0;
 
-	snprintf(cryptodev_name, sizeof(cryptodev_name), "%s", dpaa_dev->name);
+	strlcpy(cryptodev_name, dpaa_dev->name, sizeof(cryptodev_name));
 
 	cryptodev = rte_cryptodev_pmd_allocate(cryptodev_name, rte_socket_id());
 	if (cryptodev == NULL)
-- 
2.39.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 10/25] event/cnxk: replace snprintf with strlcpy
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
                   ` (8 preceding siblings ...)
  2023-06-01 15:00 ` [PATCH 09/25] crypto/dpaa_sec: replace snprintf with strlcpy Stephen Hemminger
@ 2023-06-01 15:00 ` Stephen Hemminger
  2023-06-01 15:00 ` [PATCH 11/25] net/atlantic: " Stephen Hemminger
                   ` (15 subsequent siblings)
  25 siblings, 0 replies; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:00 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Pavan Nikhilesh, Shijith Thotton

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

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/event/cnxk/cnxk_eventdev_stats.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/event/cnxk/cnxk_eventdev_stats.c b/drivers/event/cnxk/cnxk_eventdev_stats.c
index a8a87a06e43e..e18d24815f81 100644
--- a/drivers/event/cnxk/cnxk_eventdev_stats.c
+++ b/drivers/event/cnxk/cnxk_eventdev_stats.c
@@ -246,15 +246,14 @@ cnxk_sso_xstats_get_names(const struct rte_eventdev *event_dev,
 	unsigned int i;
 
 	for (i = 0; i < CNXK_SSO_NUM_HWS_XSTATS; i++) {
-		snprintf(xstats_names_copy[i].name,
-			 sizeof(xstats_names_copy[i].name), "%s",
-			 sso_hws_xstats[i].name);
+		strlcpy(xstats_names_copy[i].name, sso_hws_xstats[i].name,
+			sizeof(xstats_names_copy[i].name));
 	}
 
 	for (; i < CNXK_SSO_NUM_XSTATS; i++) {
-		snprintf(xstats_names_copy[i].name,
-			 sizeof(xstats_names_copy[i].name), "%s",
-			 sso_hwgrp_xstats[i - CNXK_SSO_NUM_HWS_XSTATS].name);
+		strlcpy(xstats_names_copy[i].name,
+			sso_hwgrp_xstats[i - CNXK_SSO_NUM_HWS_XSTATS].name,
+			sizeof(xstats_names_copy[i].name));
 	}
 
 	switch (mode) {
-- 
2.39.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 11/25] net/atlantic: replace snprintf with strlcpy
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
                   ` (9 preceding siblings ...)
  2023-06-01 15:00 ` [PATCH 10/25] event/cnxk: " Stephen Hemminger
@ 2023-06-01 15:00 ` Stephen Hemminger
  2023-06-01 15:00 ` [PATCH 12/25] net/axgbe: " Stephen Hemminger
                   ` (14 subsequent siblings)
  25 siblings, 0 replies; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:00 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Igor Russkikh

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

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/atlantic/atl_ethdev.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/net/atlantic/atl_ethdev.c b/drivers/net/atlantic/atl_ethdev.c
index 3a028f429002..09a7d9c8c88f 100644
--- a/drivers/net/atlantic/atl_ethdev.c
+++ b/drivers/net/atlantic/atl_ethdev.c
@@ -1006,9 +1006,8 @@ atl_dev_xstats_get_names(struct rte_eth_dev *dev __rte_unused,
 
 	if (xstats_names) {
 		for (i = 0; i < size && i < count; i++) {
-			snprintf(xstats_names[i].name,
-				RTE_ETH_XSTATS_NAME_SIZE, "%s",
-				atl_xstats_tbl[i].name);
+			strlcpy(xstats_names[i].name, atl_xstats_tbl[i].name,
+				RTE_ETH_XSTATS_NAME_SIZE);
 		}
 	}
 
-- 
2.39.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 12/25] net/axgbe: replace snprintf with strlcpy
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
                   ` (10 preceding siblings ...)
  2023-06-01 15:00 ` [PATCH 11/25] net/atlantic: " Stephen Hemminger
@ 2023-06-01 15:00 ` Stephen Hemminger
  2023-06-01 15:00 ` [PATCH 13/25] net/bnxt: " Stephen Hemminger
                   ` (13 subsequent siblings)
  25 siblings, 0 replies; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:00 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Chandubabu Namburu

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

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/axgbe/axgbe_ethdev.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/axgbe/axgbe_ethdev.c b/drivers/net/axgbe/axgbe_ethdev.c
index 48714eebe699..f28d18ec9035 100644
--- a/drivers/net/axgbe/axgbe_ethdev.c
+++ b/drivers/net/axgbe/axgbe_ethdev.c
@@ -1025,9 +1025,9 @@ axgbe_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
 
 	if (n >= AXGBE_XSTATS_COUNT && xstats_names) {
 		for (i = 0; i < AXGBE_XSTATS_COUNT; ++i) {
-			snprintf(xstats_names[i].name,
-				 RTE_ETH_XSTATS_NAME_SIZE, "%s",
-				 axgbe_xstats_strings[i].name);
+			strlcpy(xstats_names[i].name,
+				axgbe_xstats_strings[i].name,
+				RTE_ETH_XSTATS_NAME_SIZE);
 		}
 	}
 
-- 
2.39.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 13/25] net/bnxt: replace snprintf with strlcpy
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
                   ` (11 preceding siblings ...)
  2023-06-01 15:00 ` [PATCH 12/25] net/axgbe: " Stephen Hemminger
@ 2023-06-01 15:00 ` Stephen Hemminger
  2023-06-01 15:00 ` [PATCH 14/25] net/cpfl: " Stephen Hemminger
                   ` (12 subsequent siblings)
  25 siblings, 0 replies; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:00 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Ajit Khaparde, Somnath Kotur

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

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/bnxt/bnxt_ethdev.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
index ef7b8859d997..d6aa84f6d3e4 100644
--- a/drivers/net/bnxt/bnxt_ethdev.c
+++ b/drivers/net/bnxt/bnxt_ethdev.c
@@ -2983,8 +2983,8 @@ bnxt_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
 
 	for (i = 0; i < RTE_DIM(bnxt_rx_burst_info); i++) {
 		if (pkt_burst == bnxt_rx_burst_info[i].pkt_burst) {
-			snprintf(mode->info, sizeof(mode->info), "%s",
-				 bnxt_rx_burst_info[i].info);
+			strlcpy(mode->info, bnxt_rx_burst_info[i].info,
+				sizeof(mode->info));
 			return 0;
 		}
 	}
@@ -3017,8 +3017,8 @@ bnxt_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
 
 	for (i = 0; i < RTE_DIM(bnxt_tx_burst_info); i++) {
 		if (pkt_burst == bnxt_tx_burst_info[i].pkt_burst) {
-			snprintf(mode->info, sizeof(mode->info), "%s",
-				 bnxt_tx_burst_info[i].info);
+			strlcpy(mode->info, bnxt_tx_burst_info[i].info,
+				sizeof(mode->info));
 			return 0;
 		}
 	}
-- 
2.39.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 14/25] net/cpfl: replace snprintf with strlcpy
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
                   ` (12 preceding siblings ...)
  2023-06-01 15:00 ` [PATCH 13/25] net/bnxt: " Stephen Hemminger
@ 2023-06-01 15:00 ` Stephen Hemminger
  2023-06-01 15:00 ` [PATCH 15/25] net/cxgbe: " Stephen Hemminger
                   ` (11 subsequent siblings)
  25 siblings, 0 replies; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:00 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Yuying Zhang, Beilei Xing

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

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/cpfl/cpfl_ethdev.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/cpfl/cpfl_ethdev.c b/drivers/net/cpfl/cpfl_ethdev.c
index ede730fd508b..7aed8c878ee6 100644
--- a/drivers/net/cpfl/cpfl_ethdev.c
+++ b/drivers/net/cpfl/cpfl_ethdev.c
@@ -380,9 +380,9 @@ static int cpfl_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
 
 	if (xstats_names) {
 		for (i = 0; i < CPFL_NB_XSTATS; i++) {
-			snprintf(xstats_names[i].name,
-				 sizeof(xstats_names[i].name),
-				 "%s", rte_cpfl_stats_strings[i].name);
+			strlcpy(xstats_names[i].name,
+				rte_cpfl_stats_strings[i].name,
+				sizeof(xstats_names[i].name));
 		}
 	}
 	return CPFL_NB_XSTATS;
-- 
2.39.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 15/25] net/cxgbe: replace snprintf with strlcpy
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
                   ` (13 preceding siblings ...)
  2023-06-01 15:00 ` [PATCH 14/25] net/cpfl: " Stephen Hemminger
@ 2023-06-01 15:00 ` Stephen Hemminger
  2023-06-01 15:00 ` [PATCH 16/25] net/dpaa*: " Stephen Hemminger
                   ` (10 subsequent siblings)
  25 siblings, 0 replies; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:00 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Rahul Lakkireddy

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

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/cxgbe/cxgbe_ethdev.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/net/cxgbe/cxgbe_ethdev.c b/drivers/net/cxgbe/cxgbe_ethdev.c
index 45bbeaef0ceb..a00fa6051344 100644
--- a/drivers/net/cxgbe/cxgbe_ethdev.c
+++ b/drivers/net/cxgbe/cxgbe_ethdev.c
@@ -928,9 +928,8 @@ static int cxgbe_dev_xstats(struct rte_eth_dev *dev,
 	count = 0;
 	for (i = 0; i < nstats; i++, count++) {
 		if (xstats_names != NULL)
-			snprintf(xstats_names[count].name,
-				 sizeof(xstats_names[count].name),
-				 "%s", xstats_str[i].name);
+			strlcpy(xstats_names[count].name, xstats_str[i].name,
+				sizeof(xstats_names[count].name));
 		if (xstats != NULL) {
 			stats_ptr = RTE_PTR_ADD(&ps,
 						xstats_str[i].offset);
@@ -1043,8 +1042,8 @@ int cxgbe_dev_xstats_get_names_by_id(struct rte_eth_dev *dev,
 			ret = -EINVAL;
 			goto out_err;
 		}
-		rte_strlcpy(xnames[i].name, xnames_copy[ids[i]].name,
-			    sizeof(xnames[i].name));
+		strlcpy(xnames[i].name, xnames_copy[ids[i]].name,
+			sizeof(xnames[i].name));
 	}
 
 	ret = n;
-- 
2.39.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 16/25] net/dpaa*: replace snprintf with strlcpy
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
                   ` (14 preceding siblings ...)
  2023-06-01 15:00 ` [PATCH 15/25] net/cxgbe: " Stephen Hemminger
@ 2023-06-01 15:00 ` Stephen Hemminger
  2023-06-02  4:24   ` Hemant Agrawal
  2023-06-01 15:00 ` [PATCH 17/25] net/hinic: replace snptintf " Stephen Hemminger
                   ` (9 subsequent siblings)
  25 siblings, 1 reply; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:00 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Hemant Agrawal, Sachin Saxena

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

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/dpaa/dpaa_ethdev.c   | 8 ++++----
 drivers/net/dpaa2/dpaa2_ethdev.c | 8 ++++----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/net/dpaa/dpaa_ethdev.c b/drivers/net/dpaa/dpaa_ethdev.c
index a6c86113d125..0076a531005b 100644
--- a/drivers/net/dpaa/dpaa_ethdev.c
+++ b/drivers/net/dpaa/dpaa_ethdev.c
@@ -620,8 +620,8 @@ dpaa_dev_rx_burst_mode_get(struct rte_eth_dev *dev,
 	/* Update Rx offload info */
 	for (i = 0; i < RTE_DIM(rx_offload_map); i++) {
 		if (eth_conf->rxmode.offloads & rx_offload_map[i].flags) {
-			snprintf(mode->info, sizeof(mode->info), "%s",
-				rx_offload_map[i].output);
+			strlcpy(mode->info, rx_offload_map[i].output,
+				sizeof(mode->info));
 			ret = 0;
 			break;
 		}
@@ -654,8 +654,8 @@ dpaa_dev_tx_burst_mode_get(struct rte_eth_dev *dev,
 	/* Update Tx offload info */
 	for (i = 0; i < RTE_DIM(tx_offload_map); i++) {
 		if (eth_conf->txmode.offloads & tx_offload_map[i].flags) {
-			snprintf(mode->info, sizeof(mode->info), "%s",
-				tx_offload_map[i].output);
+			strlcpy(mode->info, tx_offload_map[i].output,
+				sizeof(mode->info));
 			ret = 0;
 			break;
 		}
diff --git a/drivers/net/dpaa2/dpaa2_ethdev.c b/drivers/net/dpaa2/dpaa2_ethdev.c
index 679f33ae1a08..baa1c2d1ea0f 100644
--- a/drivers/net/dpaa2/dpaa2_ethdev.c
+++ b/drivers/net/dpaa2/dpaa2_ethdev.c
@@ -313,8 +313,8 @@ dpaa2_dev_rx_burst_mode_get(struct rte_eth_dev *dev,
 	/* Update Rx offload info */
 	for (i = 0; i < RTE_DIM(rx_offload_map); i++) {
 		if (eth_conf->rxmode.offloads & rx_offload_map[i].flags) {
-			snprintf(mode->info, sizeof(mode->info), "%s",
-				rx_offload_map[i].output);
+			strlcpy(mode->info, rx_offload_map[i].output,
+				sizeof(mode->info));
 			ret = 0;
 			break;
 		}
@@ -348,8 +348,8 @@ dpaa2_dev_tx_burst_mode_get(struct rte_eth_dev *dev,
 	/* Update Tx offload info */
 	for (i = 0; i < RTE_DIM(tx_offload_map); i++) {
 		if (eth_conf->txmode.offloads & tx_offload_map[i].flags) {
-			snprintf(mode->info, sizeof(mode->info), "%s",
-				tx_offload_map[i].output);
+			strlcpy(mode->info, tx_offload_map[i].output,
+				sizeof(mode->info));
 			ret = 0;
 			break;
 		}
-- 
2.39.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 17/25] net/hinic: replace snptintf with strlcpy
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
                   ` (15 preceding siblings ...)
  2023-06-01 15:00 ` [PATCH 16/25] net/dpaa*: " Stephen Hemminger
@ 2023-06-01 15:00 ` Stephen Hemminger
  2023-06-01 15:00 ` [PATCH 18/25] net/hns3: replace snprint " Stephen Hemminger
                   ` (8 subsequent siblings)
  25 siblings, 0 replies; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:00 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Ziyang Xuan, Xiaoyun Wang, Guoyang Zhou

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


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 18/25] net/hns3: replace snprint with strlcpy
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
                   ` (16 preceding siblings ...)
  2023-06-01 15:00 ` [PATCH 17/25] net/hinic: replace snptintf " Stephen Hemminger
@ 2023-06-01 15:00 ` Stephen Hemminger
  2023-06-01 15:01 ` [PATCH 19/25] net/intel: replace snprintf " Stephen Hemminger
                   ` (7 subsequent siblings)
  25 siblings, 0 replies; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:00 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Dongdong Liu, Yisen Zhuang

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(-)

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);
-- 
2.39.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 19/25] net/intel: replace snprintf with strlcpy
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
                   ` (17 preceding siblings ...)
  2023-06-01 15:00 ` [PATCH 18/25] net/hns3: replace snprint " Stephen Hemminger
@ 2023-06-01 15:01 ` Stephen Hemminger
  2023-06-01 15:01 ` [PATCH 20/25] net/ionic: " Stephen Hemminger
                   ` (6 subsequent siblings)
  25 siblings, 0 replies; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:01 UTC (permalink / raw)
  To: dev
  Cc: Stephen Hemminger, Qi Zhang, Xiao Wang, Yuying Zhang,
	Beilei Xing, Jingjing Wu, Qiming Yang

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

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/fm10k/fm10k_ethdev.c | 6 +++---
 drivers/net/i40e/i40e_rxtx.c     | 8 ++++----
 drivers/net/iavf/iavf_ethdev.c   | 6 +++---
 drivers/net/ice/ice_dcf_ethdev.c | 6 +++---
 drivers/net/ice/ice_rxtx.c       | 8 ++++----
 drivers/net/idpf/idpf_ethdev.c   | 6 +++---
 6 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/drivers/net/fm10k/fm10k_ethdev.c b/drivers/net/fm10k/fm10k_ethdev.c
index 4d3c4c10cfa4..cb8cf1a8a8ea 100644
--- a/drivers/net/fm10k/fm10k_ethdev.c
+++ b/drivers/net/fm10k/fm10k_ethdev.c
@@ -1244,9 +1244,9 @@ static int fm10k_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
 
 		/* Global stats */
 		for (i = 0; i < FM10K_NB_HW_XSTATS; i++) {
-			snprintf(xstats_names[count].name,
-				sizeof(xstats_names[count].name),
-				"%s", fm10k_hw_stats_strings[count].name);
+			strlcpy(xstats_names[count].name,
+				fm10k_hw_stats_strings[count].name,
+				sizeof(xstats_names[count].name));
 			count++;
 		}
 
diff --git a/drivers/net/i40e/i40e_rxtx.c b/drivers/net/i40e/i40e_rxtx.c
index 788ffb51c272..54fb9b9c15ec 100644
--- a/drivers/net/i40e/i40e_rxtx.c
+++ b/drivers/net/i40e/i40e_rxtx.c
@@ -3395,8 +3395,8 @@ i40e_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
 
 	for (i = 0; i < RTE_DIM(i40e_rx_burst_infos); ++i) {
 		if (pkt_burst == i40e_rx_burst_infos[i].pkt_burst) {
-			snprintf(mode->info, sizeof(mode->info), "%s",
-				 i40e_rx_burst_infos[i].info);
+			strlcpy(mode->info, i40e_rx_burst_infos[i].info,
+				sizeof(mode->info));
 			ret = 0;
 			break;
 		}
@@ -3526,8 +3526,8 @@ i40e_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
 
 	for (i = 0; i < RTE_DIM(i40e_tx_burst_infos); ++i) {
 		if (pkt_burst == i40e_tx_burst_infos[i].pkt_burst) {
-			snprintf(mode->info, sizeof(mode->info), "%s",
-				 i40e_tx_burst_infos[i].info);
+			strlcpy(mode->info, i40e_tx_burst_infos[i].info,
+				sizeof(mode->info));
 			ret = 0;
 			break;
 		}
diff --git a/drivers/net/iavf/iavf_ethdev.c b/drivers/net/iavf/iavf_ethdev.c
index f6d68403ce71..f3474f6faccb 100644
--- a/drivers/net/iavf/iavf_ethdev.c
+++ b/drivers/net/iavf/iavf_ethdev.c
@@ -1802,9 +1802,9 @@ static int iavf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
 
 	if (xstats_names != NULL)
 		for (i = 0; i < IAVF_NB_XSTATS; i++) {
-			snprintf(xstats_names[i].name,
-				sizeof(xstats_names[i].name),
-				"%s", rte_iavf_stats_strings[i].name);
+			strlcpy(xstats_names[i].name,
+				rte_iavf_stats_strings[i].name,
+				sizeof(xstats_names[i].name));
 		}
 	return IAVF_NB_XSTATS;
 }
diff --git a/drivers/net/ice/ice_dcf_ethdev.c b/drivers/net/ice/ice_dcf_ethdev.c
index dcbf2af5b039..ea5296b54246 100644
--- a/drivers/net/ice/ice_dcf_ethdev.c
+++ b/drivers/net/ice/ice_dcf_ethdev.c
@@ -1549,9 +1549,9 @@ static int ice_dcf_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
 
 	if (xstats_names != NULL)
 		for (i = 0; i < ICE_DCF_NB_XSTATS; i++) {
-			snprintf(xstats_names[i].name,
-				sizeof(xstats_names[i].name),
-				"%s", rte_ice_dcf_stats_strings[i].name);
+			strlcpy(xstats_names[i].name,
+				rte_ice_dcf_stats_strings[i].name,
+				sizeof(xstats_names[i].name));
 		}
 	return ICE_DCF_NB_XSTATS;
 }
diff --git a/drivers/net/ice/ice_rxtx.c b/drivers/net/ice/ice_rxtx.c
index 0ea0045836cc..bde52f7532fb 100644
--- a/drivers/net/ice/ice_rxtx.c
+++ b/drivers/net/ice/ice_rxtx.c
@@ -3605,8 +3605,8 @@ ice_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
 
 	for (i = 0; i < RTE_DIM(ice_rx_burst_infos); ++i) {
 		if (pkt_burst == ice_rx_burst_infos[i].pkt_burst) {
-			snprintf(mode->info, sizeof(mode->info), "%s",
-				 ice_rx_burst_infos[i].info);
+			strlcpy(mode->info, ice_rx_burst_infos[i].info,
+				sizeof(mode->info));
 			ret = 0;
 			break;
 		}
@@ -3846,8 +3846,8 @@ ice_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
 
 	for (i = 0; i < RTE_DIM(ice_tx_burst_infos); ++i) {
 		if (pkt_burst == ice_tx_burst_infos[i].pkt_burst) {
-			snprintf(mode->info, sizeof(mode->info), "%s",
-				 ice_tx_burst_infos[i].info);
+			strlcpy(mode->info, ice_tx_burst_infos[i].info,
+				sizeof(mode->info));
 			ret = 0;
 			break;
 		}
diff --git a/drivers/net/idpf/idpf_ethdev.c b/drivers/net/idpf/idpf_ethdev.c
index e02ec2ec5ace..39c9edbb3c19 100644
--- a/drivers/net/idpf/idpf_ethdev.c
+++ b/drivers/net/idpf/idpf_ethdev.c
@@ -384,9 +384,9 @@ static int idpf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
 
 	if (xstats_names)
 		for (i = 0; i < IDPF_NB_XSTATS; i++) {
-			snprintf(xstats_names[i].name,
-				 sizeof(xstats_names[i].name),
-				 "%s", rte_idpf_stats_strings[i].name);
+			strlcpy(xstats_names[i].name,
+				rte_idpf_stats_strings[i].name,
+				sizeof(xstats_names[i].name));
 		}
 	return IDPF_NB_XSTATS;
 }
-- 
2.39.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 20/25] net/ionic: replace snprintf with strlcpy
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
                   ` (18 preceding siblings ...)
  2023-06-01 15:01 ` [PATCH 19/25] net/intel: replace snprintf " Stephen Hemminger
@ 2023-06-01 15:01 ` Stephen Hemminger
  2023-06-02  6:05   ` Xu, Rosen
  2023-06-01 15:01 ` [PATCH 21/25] net/mlx5: " Stephen Hemminger
                   ` (5 subsequent siblings)
  25 siblings, 1 reply; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:01 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Andrew Boyer, Rosen Xu

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


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 21/25] net/mlx5: replace snprintf with strlcpy
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
                   ` (19 preceding siblings ...)
  2023-06-01 15:01 ` [PATCH 20/25] net/ionic: " Stephen Hemminger
@ 2023-06-01 15:01 ` Stephen Hemminger
  2023-06-01 15:01 ` [PATCH 22/25] net/nfp: " Stephen Hemminger
                   ` (4 subsequent siblings)
  25 siblings, 0 replies; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:01 UTC (permalink / raw)
  To: dev
  Cc: Stephen Hemminger, Matan Azrad, Viacheslav Ovsiienko, Ori Kam,
	Suanming Mou

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

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/mlx5/mlx5_rx.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_rx.c b/drivers/net/mlx5/mlx5_rx.c
index a2be523e9e36..5d0ec51f2a19 100644
--- a/drivers/net/mlx5/mlx5_rx.c
+++ b/drivers/net/mlx5/mlx5_rx.c
@@ -219,26 +219,26 @@ mlx5_rx_burst_mode_get(struct rte_eth_dev *dev,
 		return -rte_errno;
 	}
 	if (pkt_burst == mlx5_rx_burst) {
-		snprintf(mode->info, sizeof(mode->info), "%s", "Scalar");
+		strlcpy(mode->info, "Scalar", sizeof(mode->info));
 	} else if (pkt_burst == mlx5_rx_burst_mprq) {
-		snprintf(mode->info, sizeof(mode->info), "%s", "Multi-Packet RQ");
+		strlcpy(mode->info, "Multi-Packet RQ", sizeof(mode->info));
 	} else if (pkt_burst == mlx5_rx_burst_vec) {
 #if defined RTE_ARCH_X86_64
-		snprintf(mode->info, sizeof(mode->info), "%s", "Vector SSE");
+		strlcpy(mode->info, "Vector SSE", sizeof(mode->info));
 #elif defined RTE_ARCH_ARM64
-		snprintf(mode->info, sizeof(mode->info), "%s", "Vector Neon");
+		strlcpy(mode->info, "Vector Neon", sizeof(mode->info));
 #elif defined RTE_ARCH_PPC_64
-		snprintf(mode->info, sizeof(mode->info), "%s", "Vector AltiVec");
+		strlcpy(mode->info, "Vector AltiVec", sizeof(mode->info));
 #else
 		return -EINVAL;
 #endif
 	} else if (pkt_burst == mlx5_rx_burst_mprq_vec) {
 #if defined RTE_ARCH_X86_64
-		snprintf(mode->info, sizeof(mode->info), "%s", "MPRQ Vector SSE");
+		strlcpy(mode->info, "MPRQ Vector SSE", sizeof(mode->info));
 #elif defined RTE_ARCH_ARM64
-		snprintf(mode->info, sizeof(mode->info), "%s", "MPRQ Vector Neon");
+		strlcpy(mode->info, "MPRQ Vector Neon", sizeof(mode->info));
 #elif defined RTE_ARCH_PPC_64
-		snprintf(mode->info, sizeof(mode->info), "%s", "MPRQ Vector AltiVec");
+		strlcpy(mode->info, "MPRQ Vector AltiVec", sizeof(mode->info));
 #else
 		return -EINVAL;
 #endif
-- 
2.39.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 22/25] net/nfp: replace snprintf with strlcpy
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
                   ` (20 preceding siblings ...)
  2023-06-01 15:01 ` [PATCH 21/25] net/mlx5: " Stephen Hemminger
@ 2023-06-01 15:01 ` Stephen Hemminger
  2023-06-05 11:10   ` Niklas Söderlund
  2023-06-01 15:01 ` [PATCH 23/25] net/ngbe: " Stephen Hemminger
                   ` (3 subsequent siblings)
  25 siblings, 1 reply; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:01 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Chaoyong He, Niklas Söderlund

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

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/nfp/flower/nfp_flower_representor.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/nfp/flower/nfp_flower_representor.c b/drivers/net/nfp/flower/nfp_flower_representor.c
index 362c67f7b56d..09e0447d9268 100644
--- a/drivers/net/nfp/flower/nfp_flower_representor.c
+++ b/drivers/net/nfp/flower/nfp_flower_representor.c
@@ -600,7 +600,7 @@ nfp_flower_pf_repr_init(struct rte_eth_dev *eth_dev,
 	repr->repr_type        = init_repr_data->repr_type;
 	repr->app_fw_flower    = init_repr_data->app_fw_flower;
 
-	snprintf(repr->name, sizeof(repr->name), "%s", init_repr_data->name);
+	strlcpy(repr->name, init_repr_data->name, sizeof(repr->name));
 
 	eth_dev->dev_ops = &nfp_flower_pf_repr_dev_ops;
 	eth_dev->rx_pkt_burst = nfp_flower_pf_recv_pkts;
@@ -671,7 +671,7 @@ nfp_flower_repr_init(struct rte_eth_dev *eth_dev,
 	repr->repr_type        = init_repr_data->repr_type;
 	repr->app_fw_flower    = init_repr_data->app_fw_flower;
 
-	snprintf(repr->name, sizeof(repr->name), "%s", init_repr_data->name);
+	strlcpy(repr->name, init_repr_data->name, sizeof(repr->name));
 
 	eth_dev->dev_ops = &nfp_flower_repr_dev_ops;
 	eth_dev->rx_pkt_burst = nfp_flower_repr_rx_burst;
-- 
2.39.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 23/25] net/ngbe: replace snprintf with strlcpy
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
                   ` (21 preceding siblings ...)
  2023-06-01 15:01 ` [PATCH 22/25] net/nfp: " Stephen Hemminger
@ 2023-06-01 15:01 ` Stephen Hemminger
  2023-06-01 15:01 ` [PATCH 24/25] net/qede: " Stephen Hemminger
                   ` (2 subsequent siblings)
  25 siblings, 0 replies; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:01 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Jiawen Wu

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

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/ngbe/ngbe_rxtx.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/net/ngbe/ngbe_rxtx.c b/drivers/net/ngbe/ngbe_rxtx.c
index 0c678e155726..dc6043f3620a 100644
--- a/drivers/net/ngbe/ngbe_rxtx.c
+++ b/drivers/net/ngbe/ngbe_rxtx.c
@@ -1875,8 +1875,8 @@ ngbe_tx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
 
 	for (i = 0; i < RTE_DIM(ngbe_tx_burst_infos); ++i) {
 		if (pkt_burst == ngbe_tx_burst_infos[i].pkt_burst) {
-			snprintf(mode->info, sizeof(mode->info), "%s",
-				 ngbe_tx_burst_infos[i].info);
+			strlcpy(mode->info, ngbe_tx_burst_infos[i].info,
+				sizeof(mode->info));
 			ret = 0;
 			break;
 		}
@@ -2785,8 +2785,8 @@ ngbe_rx_burst_mode_get(struct rte_eth_dev *dev, __rte_unused uint16_t queue_id,
 
 	for (i = 0; i < RTE_DIM(ngbe_rx_burst_infos); ++i) {
 		if (pkt_burst == ngbe_rx_burst_infos[i].pkt_burst) {
-			snprintf(mode->info, sizeof(mode->info), "%s",
-				 ngbe_rx_burst_infos[i].info);
+			strlcpy(mode->info, ngbe_rx_burst_infos[i].info,
+				sizeof(mode->info));
 			ret = 0;
 			break;
 		}
-- 
2.39.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 24/25] net/qede: replace snprintf with strlcpy
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
                   ` (22 preceding siblings ...)
  2023-06-01 15:01 ` [PATCH 23/25] net/ngbe: " Stephen Hemminger
@ 2023-06-01 15:01 ` Stephen Hemminger
  2023-06-01 15:01 ` [PATCH 25/25] net/txgbe: " Stephen Hemminger
  2023-06-02 20:01 ` [PATCH 00/25] " Tyler Retzlaff
  25 siblings, 0 replies; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:01 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Devendra Singh Rawat, Alok Prasad

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

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/qede/qede_ethdev.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/drivers/net/qede/qede_ethdev.c b/drivers/net/qede/qede_ethdev.c
index a4923670d6ba..7429ec3e8773 100644
--- a/drivers/net/qede/qede_ethdev.c
+++ b/drivers/net/qede/qede_ethdev.c
@@ -238,8 +238,8 @@ qede_fw_version_get(struct rte_eth_dev *dev, char *fw_ver, size_t fw_size)
 	size_t size;
 
 	if (IS_PF(edev))
-		snprintf(ver_str, QEDE_PMD_DRV_VER_STR_SIZE, "%s",
-			 QEDE_PMD_FW_VERSION);
+		strlcpy(ver_str, QEDE_PMD_FW_VERSION,
+			QEDE_PMD_DRV_VER_STR_SIZE);
 	else
 		snprintf(ver_str, QEDE_PMD_DRV_VER_STR_SIZE, "%d.%d.%d.%d",
 			 info->fw_major, info->fw_minor,
@@ -374,11 +374,9 @@ static void qede_print_adapter_info(struct rte_eth_dev *dev)
 		  ECORE_IS_BB(edev) ? "BB" : "AH",
 		  'A' + edev->chip_rev,
 		  (int)edev->chip_metal);
-	snprintf(ver_str, QEDE_PMD_DRV_VER_STR_SIZE, "%s",
-		 QEDE_PMD_DRV_VERSION);
+	strlcpy(ver_str, QEDE_PMD_DRV_VERSION, QEDE_PMD_DRV_VER_STR_SIZE);
 	DP_INFO(edev, " %-20s: %s\n", "Driver version", ver_str);
-	snprintf(ver_str, QEDE_PMD_DRV_VER_STR_SIZE, "%s",
-		 QEDE_PMD_BASE_VERSION);
+	strlcpy(ver_str, QEDE_PMD_BASE_VERSION, QEDE_PMD_DRV_VER_STR_SIZE);
 	DP_INFO(edev, " %-20s: %s\n", "Base version", ver_str);
 	qede_fw_version_get(dev, ver_str, sizeof(ver_str));
 	DP_INFO(edev, " %-20s: %s\n", "Firmware version", ver_str);
-- 
2.39.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* [PATCH 25/25] net/txgbe: replace snprintf with strlcpy
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
                   ` (23 preceding siblings ...)
  2023-06-01 15:01 ` [PATCH 24/25] net/qede: " Stephen Hemminger
@ 2023-06-01 15:01 ` Stephen Hemminger
  2023-06-02 20:01 ` [PATCH 00/25] " Tyler Retzlaff
  25 siblings, 0 replies; 32+ messages in thread
From: Stephen Hemminger @ 2023-06-01 15:01 UTC (permalink / raw)
  To: dev; +Cc: Stephen Hemminger, Jiawen Wu, Jian Wang

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

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 drivers/net/txgbe/txgbe_ethdev_vf.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/txgbe/txgbe_ethdev_vf.c b/drivers/net/txgbe/txgbe_ethdev_vf.c
index 3b1f7c913b7b..376357a23648 100644
--- a/drivers/net/txgbe/txgbe_ethdev_vf.c
+++ b/drivers/net/txgbe/txgbe_ethdev_vf.c
@@ -357,9 +357,9 @@ static int txgbevf_dev_xstats_get_names(__rte_unused struct rte_eth_dev *dev,
 
 	if (xstats_names != NULL)
 		for (i = 0; i < TXGBEVF_NB_XSTATS; i++)
-			snprintf(xstats_names[i].name,
-				sizeof(xstats_names[i].name),
-				"%s", rte_txgbevf_stats_strings[i].name);
+			strlcpy(xstats_names[i].name,
+				rte_txgbevf_stats_strings[i].name,
+				sizeof(xstats_names[i].name));
 	return TXGBEVF_NB_XSTATS;
 }
 
-- 
2.39.2


^ permalink raw reply	[flat|nested] 32+ messages in thread

* RE: [PATCH 16/25] net/dpaa*: replace snprintf with strlcpy
  2023-06-01 15:00 ` [PATCH 16/25] net/dpaa*: " Stephen Hemminger
@ 2023-06-02  4:24   ` Hemant Agrawal
  0 siblings, 0 replies; 32+ messages in thread
From: Hemant Agrawal @ 2023-06-02  4:24 UTC (permalink / raw)
  To: Stephen Hemminger, dev; +Cc: Sachin Saxena

Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* RE: [PATCH 09/25] crypto/dpaa_sec: replace snprintf with strlcpy
  2023-06-01 15:00 ` [PATCH 09/25] crypto/dpaa_sec: replace snprintf with strlcpy Stephen Hemminger
@ 2023-06-02  4:24   ` Hemant Agrawal
  0 siblings, 0 replies; 32+ messages in thread
From: Hemant Agrawal @ 2023-06-02  4:24 UTC (permalink / raw)
  To: Stephen Hemminger, dev; +Cc: Gagandeep Singh

Acked-by: Hemant Agrawal <hemant.agrawal@nxp.com>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* RE: [PATCH 04/25] raw/ifpga: replace snprintf with strlcpy
  2023-06-01 15:00 ` [PATCH 04/25] raw/ifpga: replace snprintf with strlcpy Stephen Hemminger
@ 2023-06-02  6:04   ` Xu, Rosen
  0 siblings, 0 replies; 32+ messages in thread
From: Xu, Rosen @ 2023-06-02  6:04 UTC (permalink / raw)
  To: Stephen Hemminger, dev; +Cc: Zhang, Tianfei

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>; Xu, Rosen
> <rosen.xu@intel.com>; Zhang, Tianfei <tianfei.zhang@intel.com>
> Subject: [PATCH 04/25] raw/ifpga: replace snprintf with strlcpy
> 
> Suggested by devtools/cocci/strlcpy-with-header.cocci
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  drivers/raw/ifpga/afu_pmd_core.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/raw/ifpga/afu_pmd_core.c
> b/drivers/raw/ifpga/afu_pmd_core.c
> index 3ab1f47ac1a4..e969897dbe7d 100644
> --- a/drivers/raw/ifpga/afu_pmd_core.c
> +++ b/drivers/raw/ifpga/afu_pmd_core.c
> @@ -16,6 +16,7 @@
>  #include <rte_malloc.h>
>  #include <rte_memzone.h>
>  #include <rte_rawdev_pmd.h>
> +#include <rte_string_fns.h>
> 
>  #include "afu_pmd_core.h"
> 
> @@ -225,7 +226,7 @@ static int afu_shared_data_alloc(const char *name,
>  		return -EINVAL;
> 
>  	/* name format is afu_?|??:??.? which is unique */
> -	snprintf(mz_name, sizeof(mz_name), "%s", name);
> +	strlcpy(mz_name, name, sizeof(mz_name));
> 
>  	mz = rte_memzone_lookup(mz_name);
>  	if (!mz) {
> --
> 2.39.2

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

^ permalink raw reply	[flat|nested] 32+ messages in thread

* RE: [PATCH 20/25] net/ionic: replace snprintf with strlcpy
  2023-06-01 15:01 ` [PATCH 20/25] net/ionic: " Stephen Hemminger
@ 2023-06-02  6:05   ` Xu, Rosen
  0 siblings, 0 replies; 32+ messages in thread
From: Xu, Rosen @ 2023-06-02  6:05 UTC (permalink / raw)
  To: Stephen Hemminger, dev; +Cc: Andrew Boyer

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>

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 00/25] replace snprintf with strlcpy
  2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy Stephen Hemminger
                   ` (24 preceding siblings ...)
  2023-06-01 15:01 ` [PATCH 25/25] net/txgbe: " Stephen Hemminger
@ 2023-06-02 20:01 ` Tyler Retzlaff
  25 siblings, 0 replies; 32+ messages in thread
From: Tyler Retzlaff @ 2023-06-02 20:01 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev

On Thu, Jun 01, 2023 at 08:00:41AM -0700, Stephen Hemminger wrote:
> This patch series was generated by using the existing
> Coccinelle script to find where snprintf() is used but
> strlcpy() could be used instead.

i guess the motivation here is strlcpy is safer to use than the portable
snprintf? not objecting, just confirming.

> 
> Manually replaced fixed some trigraphs and paren's where
> needed. Also one instance the whole temporary string
> copy was not needed at all.
> 
> Stephen Hemminger (25):
>   app: use strlcpy in tests
>   examples: use strlcpy instead of snprintf
>   lib: use strlcpy instead of snprintf
>   raw/ifpga: replace snprintf with strlcpy
>   common/cnxk: replace snprint with strlcpy
>   common/mlx5: replace snprintf with strlcpy
>   drivers/gpu: replace snprintf with strlcpy
>   crypto/ipsec_mb: remove unnecessary snprintf
>   crypto/dpaa_sec: replace snprintf with strlcpy
>   event/cnxk: replace snprintf with strlcpy
>   net/atlantic: replace snprintf with strlcpy
>   net/axgbe: replace snprintf with strlcpy
>   net/bnxt: replace snprintf with strlcpy
>   net/cpfl: replace snprintf with strlcpy
>   net/cxgbe: replace snprintf with strlcpy
>   net/dpaa*: replace snprintf with strlcpy
>   net/hinic: replace snptintf with strlcpy
>   net/hns3: replace snprint with strlcpy
>   net/intel: replace snprintf with strlcpy
>   net/ionic: replace snprintf with strlcpy
>   net/mlx5: replace snprintf with strlcpy
>   net/nfp: replace snprintf with strlcpy
>   net/ngbe: replace snprintf with strlcpy
>   net/qede: replace snprintf with strlcpy
>   net/txgbe: replace snprintf with strlcpy
> 
>  app/test-bbdev/main.c                         |  5 ++--
>  app/test-pmd/cmdline_flow.c                   |  6 ++--
>  app/test/process.h                            |  2 +-
>  app/test/test_graph_perf.c                    | 29 ++++++++++---------
>  drivers/common/cnxk/roc_nix_stats.c           |  4 +--
>  drivers/common/mlx5/linux/mlx5_common_os.c    |  2 +-
>  drivers/common/mlx5/mlx5_common_utils.c       |  5 ++--
>  drivers/crypto/dpaa_sec/dpaa_sec.c            |  2 +-
>  drivers/crypto/ipsec_mb/ipsec_mb_ops.c        |  7 +----
>  drivers/event/cnxk/cnxk_eventdev_stats.c      | 11 ++++---
>  drivers/gpu/cuda/cuda.c                       |  2 +-
>  drivers/gpu/cuda/gdrcopy.c                    |  2 +-
>  drivers/net/atlantic/atl_ethdev.c             |  5 ++--
>  drivers/net/axgbe/axgbe_ethdev.c              |  6 ++--
>  drivers/net/bnxt/bnxt_ethdev.c                |  8 ++---
>  drivers/net/cpfl/cpfl_ethdev.c                |  6 ++--
>  drivers/net/cxgbe/cxgbe_ethdev.c              |  9 +++---
>  drivers/net/dpaa/dpaa_ethdev.c                |  8 ++---
>  drivers/net/dpaa2/dpaa2_ethdev.c              |  8 ++---
>  drivers/net/fm10k/fm10k_ethdev.c              |  6 ++--
>  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 ++++-----
>  drivers/net/hns3/hns3_fdir.c                  |  2 +-
>  drivers/net/hns3/hns3_rxtx.c                  |  8 ++---
>  drivers/net/hns3/hns3_stats.c                 | 22 +++++++-------
>  drivers/net/i40e/i40e_rxtx.c                  |  8 ++---
>  drivers/net/iavf/iavf_ethdev.c                |  6 ++--
>  drivers/net/ice/ice_dcf_ethdev.c              |  6 ++--
>  drivers/net/ice/ice_rxtx.c                    |  8 ++---
>  drivers/net/idpf/idpf_ethdev.c                |  6 ++--
>  drivers/net/ionic/ionic_ethdev.c              | 15 +++++-----
>  drivers/net/ipn3ke/ipn3ke_representor.c       | 17 +++++------
>  drivers/net/mlx5/mlx5_rx.c                    | 16 +++++-----
>  .../net/nfp/flower/nfp_flower_representor.c   |  4 +--
>  drivers/net/ngbe/ngbe_rxtx.c                  |  8 ++---
>  drivers/net/qede/qede_ethdev.c                | 10 +++----
>  drivers/net/txgbe/txgbe_ethdev_vf.c           |  6 ++--
>  drivers/raw/ifpga/afu_pmd_core.c              |  3 +-
>  examples/fips_validation/fips_validation.c    |  8 ++---
>  examples/l3fwd-graph/main.c                   |  2 +-
>  examples/pipeline/cli.c                       |  2 +-
>  examples/vhost_blk/vhost_blk.c                |  5 ++--
>  lib/bbdev/rte_bbdev.c                         |  2 +-
>  lib/ethdev/sff_8636.c                         | 11 ++++---
>  45 files changed, 157 insertions(+), 170 deletions(-)
> 
> -- 
> 2.39.2

^ permalink raw reply	[flat|nested] 32+ messages in thread

* Re: [PATCH 22/25] net/nfp: replace snprintf with strlcpy
  2023-06-01 15:01 ` [PATCH 22/25] net/nfp: " Stephen Hemminger
@ 2023-06-05 11:10   ` Niklas Söderlund
  0 siblings, 0 replies; 32+ messages in thread
From: Niklas Söderlund @ 2023-06-05 11:10 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: dev, Chaoyong He

Hi Stephen,

Thanks for your work.

On 2023-06-01 08:01:03 -0700, Stephen Hemminger wrote:
> Suggested by devtools/cocci/strlcpy-with-header.cocci
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>

Reviewed-by: Niklas Söderlund <niklas.soderlund@corigine.com>

> ---
>  drivers/net/nfp/flower/nfp_flower_representor.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/nfp/flower/nfp_flower_representor.c b/drivers/net/nfp/flower/nfp_flower_representor.c
> index 362c67f7b56d..09e0447d9268 100644
> --- a/drivers/net/nfp/flower/nfp_flower_representor.c
> +++ b/drivers/net/nfp/flower/nfp_flower_representor.c
> @@ -600,7 +600,7 @@ nfp_flower_pf_repr_init(struct rte_eth_dev *eth_dev,
>  	repr->repr_type        = init_repr_data->repr_type;
>  	repr->app_fw_flower    = init_repr_data->app_fw_flower;
>  
> -	snprintf(repr->name, sizeof(repr->name), "%s", init_repr_data->name);
> +	strlcpy(repr->name, init_repr_data->name, sizeof(repr->name));
>  
>  	eth_dev->dev_ops = &nfp_flower_pf_repr_dev_ops;
>  	eth_dev->rx_pkt_burst = nfp_flower_pf_recv_pkts;
> @@ -671,7 +671,7 @@ nfp_flower_repr_init(struct rte_eth_dev *eth_dev,
>  	repr->repr_type        = init_repr_data->repr_type;
>  	repr->app_fw_flower    = init_repr_data->app_fw_flower;
>  
> -	snprintf(repr->name, sizeof(repr->name), "%s", init_repr_data->name);
> +	strlcpy(repr->name, init_repr_data->name, sizeof(repr->name));
>  
>  	eth_dev->dev_ops = &nfp_flower_repr_dev_ops;
>  	eth_dev->rx_pkt_burst = nfp_flower_repr_rx_burst;
> -- 
> 2.39.2
> 

-- 
Kind Regards,
Niklas Söderlund

^ permalink raw reply	[flat|nested] 32+ messages in thread

end of thread, other threads:[~2023-06-05 11:11 UTC | newest]

Thread overview: 32+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-01 15:00 [PATCH 00/25] replace snprintf with strlcpy 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 ` [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

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).