DPDK patches and discussions
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Subject: [PATCH 12/32] pipeline: replace memcpy with assignment
Date: Sat,  8 Feb 2025 12:22:04 -0800	[thread overview]
Message-ID: <20250208203142.242284-13-stephen@networkplumber.org> (raw)
In-Reply-To: <20250208203142.242284-1-stephen@networkplumber.org>

Prefer structure assignment over memcpy.
Found by cocci/struct_assign.cocci

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 examples/ip_pipeline/parser.c        |  2 +-
 lib/pipeline/rte_pipeline.c          |  6 ++---
 lib/pipeline/rte_swx_ctl.c           |  2 +-
 lib/pipeline/rte_swx_ipsec.c         |  2 +-
 lib/pipeline/rte_swx_pipeline_spec.c | 36 ++++++++++------------------
 5 files changed, 18 insertions(+), 30 deletions(-)

diff --git a/examples/ip_pipeline/parser.c b/examples/ip_pipeline/parser.c
index dfca026be5..8baa70e1f4 100644
--- a/examples/ip_pipeline/parser.c
+++ b/examples/ip_pipeline/parser.c
@@ -407,7 +407,7 @@ parse_mac_addr(const char *token, struct rte_ether_addr *addr)
 	if (tmp == NULL)
 		return -1;
 
-	memcpy(addr, tmp, sizeof(struct rte_ether_addr));
+	*addr = *tmp;
 	return 0;
 }
 
diff --git a/lib/pipeline/rte_pipeline.c b/lib/pipeline/rte_pipeline.c
index a09a89f746..bad85341c9 100644
--- a/lib/pipeline/rte_pipeline.c
+++ b/lib/pipeline/rte_pipeline.c
@@ -368,7 +368,7 @@ rte_pipeline_table_create(struct rte_pipeline *p,
 	*table_id = id;
 
 	/* Save input parameters */
-	memcpy(&table->ops, params->ops, sizeof(struct rte_table_ops));
+	table->ops = *params->ops;
 	table->f_action_hit = params->f_action_hit;
 	table->f_action_miss = params->f_action_miss;
 	table->arg_ah = params->arg_ah;
@@ -831,7 +831,7 @@ rte_pipeline_port_in_create(struct rte_pipeline *p,
 	*port_id = id;
 
 	/* Save input parameters */
-	memcpy(&port->ops, params->ops, sizeof(struct rte_port_in_ops));
+	port->ops = *params->ops;
 	port->f_action = params->f_action;
 	port->arg_ah = params->arg_ah;
 	port->burst_size = params->burst_size;
@@ -881,7 +881,7 @@ rte_pipeline_port_out_create(struct rte_pipeline *p,
 	*port_id = id;
 
 	/* Save input parameters */
-	memcpy(&port->ops, params->ops, sizeof(struct rte_port_out_ops));
+	port->ops = *params->ops;
 	port->f_action = params->f_action;
 	port->arg_ah = params->arg_ah;
 
diff --git a/lib/pipeline/rte_swx_ctl.c b/lib/pipeline/rte_swx_ctl.c
index 857770d297..db83c31c7c 100644
--- a/lib/pipeline/rte_swx_ctl.c
+++ b/lib/pipeline/rte_swx_ctl.c
@@ -832,7 +832,7 @@ selector_group_duplicate_to_pending(struct selector *s, uint32_t group_id)
 		if (!mp)
 			goto error;
 
-		memcpy(mp, m, sizeof(struct rte_swx_table_selector_member));
+		*mp = *m;
 
 		TAILQ_INSERT_TAIL(&gp->members, mp, node);
 	}
diff --git a/lib/pipeline/rte_swx_ipsec.c b/lib/pipeline/rte_swx_ipsec.c
index 17a9d2b98b..e710ba2f9d 100644
--- a/lib/pipeline/rte_swx_ipsec.c
+++ b/lib/pipeline/rte_swx_ipsec.c
@@ -366,7 +366,7 @@ rte_swx_ipsec_create(struct rte_swx_ipsec **ipsec_out,
 	ipsec->ring_out = ring_out;
 	ipsec->dev_id = (uint8_t)dev_id;
 	ipsec->qp_id = params->crypto_dev_queue_pair_id;
-	memcpy(&ipsec->bsz, &params->bsz, sizeof(struct rte_swx_ipsec_burst_size));
+	ipsec->bsz = params->bsz;
 	ipsec->n_sa_max = n_sa_max;
 
 	ipsec->crypto_wr_threshold = params->bsz.crypto_wr * 3 / 4;
diff --git a/lib/pipeline/rte_swx_pipeline_spec.c b/lib/pipeline/rte_swx_pipeline_spec.c
index 17419e7b85..986bbe5fd4 100644
--- a/lib/pipeline/rte_swx_pipeline_spec.c
+++ b/lib/pipeline/rte_swx_pipeline_spec.c
@@ -2985,7 +2985,7 @@ pipeline_spec_parse(FILE *spec,
 			}
 
 			s->structs = new_structs;
-			memcpy(&s->structs[s->n_structs], &struct_spec, sizeof(struct struct_spec));
+			s->structs[s->n_structs] = struct_spec;
 			s->n_structs++;
 			memset(&struct_spec, 0, sizeof(struct struct_spec));
 
@@ -3022,7 +3022,7 @@ pipeline_spec_parse(FILE *spec,
 			}
 
 			s->actions = new_actions;
-			memcpy(&s->actions[s->n_actions], &action_spec, sizeof(struct action_spec));
+			s->actions[s->n_actions] = action_spec;
 			s->n_actions++;
 			memset(&action_spec, 0, sizeof(struct action_spec));
 
@@ -3059,7 +3059,7 @@ pipeline_spec_parse(FILE *spec,
 			}
 
 			s->tables = new_tables;
-			memcpy(&s->tables[s->n_tables], &table_spec, sizeof(struct table_spec));
+			s->tables[s->n_tables] = table_spec;
 			s->n_tables++;
 			memset(&table_spec, 0, sizeof(struct table_spec));
 
@@ -3096,9 +3096,7 @@ pipeline_spec_parse(FILE *spec,
 			}
 
 			s->selectors = new_selectors;
-			memcpy(&s->selectors[s->n_selectors],
-			       &selector_spec,
-			       sizeof(struct selector_spec));
+			s->selectors[s->n_selectors] = selector_spec;
 			s->n_selectors++;
 			memset(&selector_spec, 0, sizeof(struct selector_spec));
 
@@ -3135,9 +3133,7 @@ pipeline_spec_parse(FILE *spec,
 			}
 
 			s->learners = new_learners;
-			memcpy(&s->learners[s->n_learners],
-			       &learner_spec,
-			       sizeof(struct learner_spec));
+			s->learners[s->n_learners] = learner_spec;
 			s->n_learners++;
 			memset(&learner_spec, 0, sizeof(struct learner_spec));
 
@@ -3173,7 +3169,7 @@ pipeline_spec_parse(FILE *spec,
 			}
 
 			s->apply = new_apply;
-			memcpy(&s->apply[s->n_apply], &apply_spec, sizeof(struct apply_spec));
+			s->apply[s->n_apply] = apply_spec;
 			s->n_apply++;
 			memset(&apply_spec, 0, sizeof(struct apply_spec));
 
@@ -3205,7 +3201,7 @@ pipeline_spec_parse(FILE *spec,
 			}
 
 			s->extobjs = new_extobjs;
-			memcpy(&s->extobjs[s->n_extobjs], &extobj_spec, sizeof(struct extobj_spec));
+			s->extobjs[s->n_extobjs] = extobj_spec;
 			s->n_extobjs++;
 			memset(&extobj_spec, 0, sizeof(struct extobj_spec));
 
@@ -3252,7 +3248,7 @@ pipeline_spec_parse(FILE *spec,
 			}
 
 			s->headers = new_headers;
-			memcpy(&s->headers[s->n_headers], &header_spec, sizeof(struct header_spec));
+			s->headers[s->n_headers] = header_spec;
 			s->n_headers++;
 			memset(&header_spec, 0, sizeof(struct header_spec));
 
@@ -3284,9 +3280,7 @@ pipeline_spec_parse(FILE *spec,
 			}
 
 			s->metadata = new_metadata;
-			memcpy(&s->metadata[s->n_metadata],
-			       &metadata_spec,
-			       sizeof(struct metadata_spec));
+			s->metadata[s->n_metadata] = metadata_spec;
 			s->n_metadata++;
 			memset(&metadata_spec, 0, sizeof(struct metadata_spec));
 
@@ -3378,9 +3372,7 @@ pipeline_spec_parse(FILE *spec,
 			}
 
 			s->regarrays = new_regarrays;
-			memcpy(&s->regarrays[s->n_regarrays],
-			       &regarray_spec,
-			       sizeof(struct regarray_spec));
+			s->regarrays[s->n_regarrays] = regarray_spec;
 			s->n_regarrays++;
 			memset(&regarray_spec, 0, sizeof(struct regarray_spec));
 
@@ -3412,9 +3404,7 @@ pipeline_spec_parse(FILE *spec,
 			}
 
 			s->metarrays = new_metarrays;
-			memcpy(&s->metarrays[s->n_metarrays],
-			       &metarray_spec,
-			       sizeof(struct metarray_spec));
+			s->metarrays[s->n_metarrays] = metarray_spec;
 			s->n_metarrays++;
 			memset(&metarray_spec, 0, sizeof(struct metarray_spec));
 
@@ -3446,9 +3436,7 @@ pipeline_spec_parse(FILE *spec,
 			}
 
 			s->rss = new_rss;
-			memcpy(&s->rss[s->n_rss],
-			       &rss_spec,
-			       sizeof(struct rss_spec));
+			s->rss[s->n_rss] = rss_spec;
 			s->n_rss++;
 			memset(&rss_spec, 0, sizeof(struct rss_spec));
 
-- 
2.47.2


  parent reply	other threads:[~2025-02-08 20:33 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-08 20:21 [PATCH 00/32] Use structure assignment instead of memcpy Stephen Hemminger
2025-02-08 20:21 ` [PATCH 01/32] devtools/cocci: prefer structure assignment over memcpy Stephen Hemminger
2025-02-08 20:21 ` [PATCH 02/32] app/testpmd: replace memcpy with assignment Stephen Hemminger
2025-02-08 20:21 ` [PATCH 03/32] app/graph: replace memcpy with structure assignment Stephen Hemminger
2025-02-08 20:21 ` [PATCH 04/32] crypto/dpaa_sec: replace memcpy with assignment Stephen Hemminger
2025-02-08 20:21 ` [PATCH 05/32] dma/dpaa2: " Stephen Hemminger
2025-02-08 20:21 ` [PATCH 06/32] eventdev: " Stephen Hemminger
2025-02-08 20:21 ` [PATCH 07/32] event/dpaa2: replace memcpy with structure assignment Stephen Hemminger
2025-02-08 20:22 ` [PATCH 08/32] event/dsw: replace memcpy with assignment Stephen Hemminger
2025-02-08 20:22 ` [PATCH 09/32] ml/cnxk: " Stephen Hemminger
2025-02-08 20:22 ` [PATCH 10/32] examples: " Stephen Hemminger
2025-02-08 20:22 ` [PATCH 11/32] node: " Stephen Hemminger
2025-02-08 20:22 ` Stephen Hemminger [this message]
2025-02-08 20:22 ` [PATCH 13/32] sched: replace memcpy with structure assignment Stephen Hemminger
2025-02-08 20:22 ` [PATCH 14/32] table: " Stephen Hemminger
2025-02-08 20:22 ` [PATCH 15/32] net/ntnic: " Stephen Hemminger
2025-02-08 20:22 ` [PATCH 16/32] net/bnxt: " Stephen Hemminger
2025-02-08 20:22 ` [PATCH 17/32] crypto/qat: " Stephen Hemminger
2025-02-08 20:22 ` [PATCH 18/32] mempool/cnxk: " Stephen Hemminger
2025-02-08 20:22 ` [PATCH 19/32] net/dpaa2: replace memcpy with assignment Stephen Hemminger
2025-02-08 20:22 ` [PATCH 20/32] net/enic: " Stephen Hemminger
2025-02-08 20:22 ` [PATCH 21/32] net/intel/i40e: replace memcpy with structure assignment Stephen Hemminger
2025-02-08 20:22 ` [PATCH 22/32] net/nfp: replace memcpy with assignment Stephen Hemminger
2025-02-08 20:22 ` [PATCH 23/32] net/txgbe: " Stephen Hemminger
2025-02-08 20:22 ` [PATCH 24/32] net/bnx2x: replace memcpy with structure assignment Stephen Hemminger
2025-02-08 20:22 ` [PATCH 25/32] net/dpaa2: " Stephen Hemminger
2025-02-08 20:22 ` [PATCH 26/32] net/bonding: " Stephen Hemminger
2025-02-08 20:22 ` [PATCH 27/32] net/cnxk: " Stephen Hemminger
2025-02-08 20:22 ` [PATCH 28/32] net/enic: " Stephen Hemminger
2025-02-08 20:22 ` [PATCH 29/32] net/iavf: " Stephen Hemminger
2025-02-08 20:22 ` [PATCH 30/32] net/ice: " Stephen Hemminger
2025-02-08 20:22 ` [PATCH 31/32] test: " Stephen Hemminger
2025-02-08 20:22 ` [PATCH 32/32] test/cryptodev: " Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250208203142.242284-13-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=cristian.dumitrescu@intel.com \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).