[12/32] pipeline: replace memcpy with assignment

Message ID 20250208203142.242284-13-stephen@networkplumber.org (mailing list archive)
State New
Delegated to: Thomas Monjalon
Headers
Series Use structure assignment instead of memcpy |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger Feb. 8, 2025, 8:22 p.m. UTC
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(-)
  

Patch

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