Use structure assignment instead of memcpy
Subsystems (4)
cover Use structure assignment instead of memcpy
This patch series reduces use of memcpy and rte_memcpy in DPDK. It changes memcpy to a simple assignment operator which easier to read, generates the same code, and keeps type safety.
Historically memcpy was used in textbooks because there was no structure assignement in original K&R C.
Stephen Hemminger (32):
devtools/cocci: prefer structure assignment over memcpy app/testpmd: replace memcpy with assignment app/graph: replace memcpy with structure assignment crypto/dpaa_sec: replace memcpy with assignment dma/dpaa2: replace memcpy with assignment
eventdev: replace memcpy with assignment event/dpaa2: replace memcpy with structure assignment event/dsw: replace memcpy with assignment ml/cnxk: replace memcpy with assignment
examples: replace memcpy with assignment
node: replace memcpy with assignment
pipeline: replace memcpy with assignment
sched: replace memcpy with structure assignment
table: replace memcpy with structure assignment net/ntnic: replace memcpy with structure assignment net/bnxt: replace memcpy with structure assignment crypto/qat: replace memcpy with structure assignment mempool/cnxk: replace memcpy with structure assignment net/dpaa2: replace memcpy with assignment net/enic: replace memcpy with assignment net/intel/i40e: replace memcpy with structure assignment net/nfp: replace memcpy with assignment net/txgbe: replace memcpy with assignment net/bnx2x: replace memcpy with structure assignment net/dpaa2: replace memcpy with structure assignment net/bonding: replace memcpy with structure assignment net/cnxk: replace memcpy with structure assignment net/enic: replace memcpy with structure assignment net/iavf: replace memcpy with structure assignment net/ice: replace memcpy with structure assignment
test: replace memcpy with structure assignment test/cryptodev: replace memcpy with structure assignment
app/graph/ethdev.c | 2 +- app/test-pmd/cmdline_flow.c | 2 +- app/test/test_acl.c | 5 ++- app/test/test_compressdev.c | 36 +++++++------------ app/test/test_cryptodev.c | 3 +- app/test/test_security_inline_proto.c | 23 +++++------- devtools/cocci/struct-assign.cocci | 15 ++++++++ drivers/crypto/dpaa_sec/dpaa_sec.c | 2 +- drivers/crypto/qat/dev/qat_crypto_pmd_gen3.c | 3 +- drivers/crypto/qat/dev/qat_crypto_pmd_gen5.c | 3 +- drivers/dma/dpaa2/dpaa2_qdma.c | 4 +-- drivers/event/dpaa2/dpaa2_eventdev.c | 7 ++-- drivers/event/dsw/dsw_event.c | 3 +- drivers/mempool/cnxk/cnxk_mempool_ops.c | 2 +- drivers/ml/cnxk/cnxk_ml_ops.c | 2 +- drivers/net/bnx2x/bnx2x_stats.c | 2 +- drivers/net/bnxt/bnxt_hwrm.c | 3 +- drivers/net/bnxt/tf_core/tf_rm.c | 8 ++--- drivers/net/bnxt/tf_ulp/ulp_tun.c | 3 +- drivers/net/bonding/rte_eth_bond_pmd.c | 2 +- drivers/net/cnxk/cnxk_ethdev_cman.c | 2 +- drivers/net/dpaa2/dpaa2_ethdev.c | 5 ++- drivers/net/dpaa2/dpaa2_flow.c | 9 ++--- drivers/net/dpaa2/dpaa2_mux.c | 2 +- drivers/net/enic/enic_fm_flow.c | 2 +- drivers/net/enic/enic_main.c | 2 +- drivers/net/intel/i40e/i40e_ethdev.c | 6 ++-- drivers/net/intel/i40e/i40e_fdir.c | 3 +- drivers/net/intel/i40e/i40e_flow.c | 3 +- drivers/net/intel/i40e/rte_pmd_i40e.c | 3 +- drivers/net/intel/iavf/iavf_ipsec_crypto.c | 3 +- drivers/net/intel/ice/ice_hash.c | 6 ++-- drivers/net/intel/ixgbe/ixgbe_flow.c | 4 +-- .../net/nfp/flower/nfp_flower_representor.c | 2 +- .../net/ntnic/nthw/flow_api/flow_id_table.c | 4 +-- .../profile_inline/flow_api_profile_inline.c | 2 +- drivers/net/txgbe/txgbe_flow.c | 4 +-- examples/bbdev_app/main.c | 2 +- examples/ip_pipeline/parser.c | 2 +- examples/l2fwd-cat/cat.c | 3 +- examples/ptpclient/ptpclient.c | 4 +-- lib/eventdev/rte_event_dma_adapter.c | 2 +- lib/eventdev/rte_event_timer_adapter.c | 2 +- lib/node/ethdev_rx.c | 2 +- lib/node/ip4_reassembly.c | 2 +- lib/node/kernel_rx.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 +++++++------------ lib/sched/rte_sched.c | 2 +- lib/table/rte_swx_table_selector.c | 2 +- 52 files changed, 108 insertions(+), 155 deletions(-) create mode 100644 devtools/cocci/struct-assign.cocci
Signature · 1 line
2.47.2
PATCH 1/32 devtools/cocci: prefer structure assignment over memcpy
Prefer using simple structure assignment instead of memcpy. Using a structure assignment preserves type information and compiler checks types already.
--- devtools/cocci/struct-assign.cocci | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 devtools/cocci/struct-assign.cocci
devtools/cocci/struct-assign.cocci new file +15 -0
@@ -0,0 +1,15 @@ +// +// prefer structure assignment over memcpy +// +@@ +type T; +T *SRCP; +T *DSTP; +@@ +( +- rte_memcpy(DSTP, SRCP, sizeof(T)) ++ *DSTP = *SRCP +| +- memcpy(DSTP, SRCP, sizeof(T)) ++ *DSTP = *SRCP +)
Signature · 1 line
2.47.2
PATCH 2/32 app/testpmd: replace memcpy with assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by cocci/struct_assign.cocci
--- app/test-pmd/cmdline_flow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
app/test-pmd/cmdline_flow.c +1 -1
@@ -13934,7 +13934,7 @@ cmd_set_raw_parsed_sample(const struct buffer *in)fprintf (stderr,"Error - Not supported action\n" );return ; } -rte_memcpy (data, action,sizeof (struct rte_flow_action )); + *data = *action; data++; } }
Signature · 1 line
2.47.2
PATCH 3/32 app/graph: replace memcpy with structure assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by struct-assign.cocci.
--- app/graph/ethdev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
app/graph/ethdev.c +1 -1
@@ -422,7 +422,7 @@ ethdev_process(const char *name, struct ethdev_config *params) }/* Port */ -memcpy (&port_conf, &port_conf_default,sizeof (struct rte_eth_conf )); + port_conf = port_conf_default;if (rss) {uint64_t rss_hf =RTE_ETH_RSS_IP |RTE_ETH_RSS_TCP |RTE_ETH_RSS_UDP ;
Signature · 1 line
2.47.2
PATCH 4/32 crypto/dpaa_sec: replace memcpy with assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by cocci/struct_assign.cocci
--- drivers/crypto/dpaa_sec/dpaa_sec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/crypto/dpaa_sec/dpaa_sec.c +1 -1
@@ -680,7 +680,7 @@ dpaa_sec_dump(struct dpaa_sec_op_ctx *ctx, struct dpaa_sec_qp *qp, FILE *f) } cdb = &sess->cdb; -rte_memcpy (&c_cdb, cdb,sizeof (struct sec_cdb )); + c_cdb = *cdb;#ifdef RTE_LIB_SECURITY fprintf (f,"\nsession protocol type = %d\n" , sess->proto_alg);#endif
Signature · 1 line
2.47.2
Re: [PATCH 04/32] crypto/dpaa_sec: replace memcpy with assignment
Quoted 13 lines · Stephen Hemminger
Prefer structure assignment over memcpy.
Found bycocci/struct_assign.cocciSigned-off-by Stephen Hemminger <[email protected]>--- drivers/crypto/dpaa_sec/dpaa_sec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/crypto/dpaa_sec/dpaa_sec.c +0
-0
drivers/crypto/dpaa_sec/dpaa_sec.c dpaa_sec_dump(struct dpaa_sec_op_ctx *ctx, struct dpaa_sec_qp *qp, FILE *f) · line 686
Quoted 8 lines
drivers/crypto/dpaa_sec/dpaa_sec.c +1
-1@@ -680,7 +680,7 @@ dpaa_sec_dump(struct dpaa_sec_op_ctx *ctx, struct dpaa_sec_qp *qp, FILE *f) } cdb = &sess->cdb; -rte_memcpy (&c_cdb, cdb,sizeof (struct sec_cdb )); + c_cdb = *cdb;#ifdef RTE_LIB_SECURITY fprintf (f,"\nsession protocol type = %d\n" , sess->proto_alg);#endif
PATCH 5/32 dma/dpaa2: replace memcpy with assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by cocci/struct_assign.cocci
--- drivers/dma/dpaa2/dpaa2_qdma.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/dma/dpaa2/dpaa2_qdma.c +1 -3
@@ -171,9 +171,7 @@ dpaa2_qdma_multi_eq(struct qdma_virt_queue *qdma_vq)if (unlikely (num_tx != qdma_vq->fd_idx)) { dst_idx =0 ;for (idx = num_tx; idx < qdma_vq->fd_idx; idx++) { -rte_memcpy (&qdma_vq->fd[dst_idx], - &qdma_vq->fd[idx], -sizeof (struct qbman_fd )); + qdma_vq->fd[dst_idx] = qdma_vq->fd[idx]; dst_idx++; } }
Signature · 1 line
2.47.2
RE: [PATCH 05/32] dma/dpaa2: replace memcpy with assignment
PATCH 6/32 eventdev: replace memcpy with assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by cocci/struct_assign.cocci
--- lib/eventdev/rte_event_dma_adapter.c | 2 +- lib/eventdev/rte_event_timer_adapter.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
lib/eventdev/rte_event_dma_adapter.c +1 -1
@@ -449,7 +449,7 @@ rte_event_dma_adapter_create(uint8_t id, uint8_t evdev_id, struct rte_event_portif (pc ==NULL )return -ENOMEM ; -rte_memcpy (pc, port_config,sizeof (struct rte_event_port_conf )); + *pc = *port_config; ret =rte_event_dma_adapter_create_ext (id, evdev_id, edma_default_config_cb, mode, pc);if (ret !=0 )rte_free (pc);
lib/eventdev/rte_event_timer_adapter.c +1 -1
@@ -549,7 +549,7 @@ event_buffer_add(struct event_buffer *bufp, struct rte_event *eventp)/* Instead of modulus, bitwise AND with mask to get head_idx. */ head_idx = bufp->head &EVENT_BUFFER_MASK ; buf_eventp = &bufp->events[head_idx]; -rte_memcpy (buf_eventp, eventp,sizeof (struct rte_event )); + *buf_eventp = *eventp;/* Wrap automatically when overflow occurs. */ bufp->head++;
Signature · 1 line
2.47.2
PATCH 7/32 event/dpaa2: replace memcpy with structure assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by struct-assign.cocci.
--- drivers/event/dpaa2/dpaa2_eventdev.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
drivers/event/dpaa2/dpaa2_eventdev.c +3 -4
@@ -224,7 +224,7 @@ static void dpaa2_eventdev_process_parallel(struct qbman_swp *swp,RTE_SET_USED (rxq); -rte_memcpy (ev, ev_temp,sizeof (struct rte_event )); + *ev = *ev_temp;rte_free (ev_temp);qbman_swp_dqrr_consume (swp, dq);
@@ -243,7 +243,7 @@ static void dpaa2_eventdev_process_atomic(struct qbman_swp *swp,RTE_SET_USED (swp);RTE_SET_USED (rxq); -rte_memcpy (ev, ev_temp,sizeof (struct rte_event )); + *ev = *ev_temp;rte_free (ev_temp); *dpaa2_seqn (ev->mbuf) = dqrr_index +1 ;DPAA2_PER_LCORE_DQRR_SIZE ++;
@@ -588,8 +588,7 @@ dpaa2_eventdev_port_link(struct rte_eventdev *dev, void *port,for (i =0 ; i < nb_links; i++) { evq_info = &priv->evq_info[queues[i]]; -memcpy (&dpaa2_portal->evq_info[queues[i]], evq_info, -sizeof (struct dpaa2_eventq )); + dpaa2_portal->evq_info[queues[i]] = *evq_info; dpaa2_portal->evq_info[queues[i]].event_port = port; dpaa2_portal->num_linked_evq++; }
Signature · 1 line
2.47.2
Re: [PATCH 07/32] event/dpaa2: replace memcpy with structure assignment
Quoted 40 lines · Stephen Hemminger
Prefer structure assignment over memcpy.
Found bystruct-assign.cocci.Signed-off-by Stephen Hemminger <[email protected]>--- drivers/event/dpaa2/dpaa2_eventdev.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)drivers/event/dpaa2/dpaa2_eventdev.c +3
-4@@ -224,7 +224,7 @@ static void dpaa2_eventdev_process_parallel(struct qbman_swp *swp,RTE_SET_USED (rxq); -rte_memcpy (ev, ev_temp,sizeof (struct rte_event )); + *ev = *ev_temp;rte_free (ev_temp);qbman_swp_dqrr_consume (swp, dq);@@ -243,7 +243,7 @@ static void dpaa2_eventdev_process_atomic(struct qbman_swp *swp,RTE_SET_USED (swp);RTE_SET_USED (rxq); -rte_memcpy (ev, ev_temp,sizeof (struct rte_event )); + *ev = *ev_temp;rte_free (ev_temp); *dpaa2_seqn (ev->mbuf) = dqrr_index +1 ;DPAA2_PER_LCORE_DQRR_SIZE ++;@@ -588,8 +588,7 @@ dpaa2_eventdev_port_link(struct rte_eventdev *dev, void *port,for (i =0 ; i < nb_links; i++) { evq_info = &priv->evq_info[queues[i]]; -memcpy (&dpaa2_portal->evq_info[queues[i]], evq_info, -sizeof (struct dpaa2_eventq )); + dpaa2_portal->evq_info[queues[i]] = *evq_info; dpaa2_portal->evq_info[queues[i]].event_port = port; dpaa2_portal->num_linked_evq++; }
PATCH 8/32 event/dsw: replace memcpy with assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by cocci/struct_assign.cocci
--- drivers/event/dsw/dsw_event.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/event/dsw/dsw_event.c +1 -2
@@ -1078,8 +1078,7 @@ dsw_port_stash_any_migrating_events(struct dsw_port *port, offset++; }else if (offset >0 ) {struct rte_event *out_event = &events[i - offset]; -rte_memcpy (out_event, in_event, -sizeof (struct rte_event )); + *out_event = *in_event; } }
Signature · 1 line
2.47.2
Re: [PATCH 08/32] event/dsw: replace memcpy with assignment
Quoted 13 lines · Stephen Hemminger
Prefer structure assignment over memcpy.
Found bycocci/struct_assign.cocciSigned-off-by Stephen Hemminger <[email protected]>--- drivers/event/dsw/dsw_event.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)drivers/event/dsw/dsw_event.c +0
-0
drivers/event/dsw/dsw_event.c dsw_port_stash_any_migrating_events(struct dsw_port *port, · line 1084
Quoted 9 lines
drivers/event/dsw/dsw_event.c +1
-2@@ -1078,8 +1078,7 @@ dsw_port_stash_any_migrating_events(struct dsw_port *port, offset++; }else if (offset >0 ) {struct rte_event *out_event = &events[i - offset]; -rte_memcpy (out_event, in_event, -sizeof (struct rte_event )); + *out_event = *in_event; } }
PATCH 9/32 ml/cnxk: replace memcpy with assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by cocci/struct_assign.cocci
--- drivers/ml/cnxk/cnxk_ml_ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/ml/cnxk/cnxk_ml_ops.c +1 -1
@@ -1398,7 +1398,7 @@ cnxk_ml_model_info_get(struct rte_ml_dev *dev, uint16_t model_id, } info = (struct rte_ml_model_info *)model->info; -rte_memcpy (model_info, info,sizeof (struct rte_ml_model_info )); + *model_info = *info; model_info->input_info = info->input_info; model_info->output_info = info->output_info;
Signature · 1 line
2.47.2
PATCH 10/32 examples: replace memcpy with assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by cocci/struct_assign.cocci
--- examples/bbdev_app/main.c | 2 +- examples/l2fwd-cat/cat.c | 3 +-- examples/ptpclient/ptpclient.c | 4 +--- 3 files changed, 3 insertions(+), 6 deletions(-)
examples/bbdev_app/main.c +1 -1
@@ -360,7 +360,7 @@ add_ether_hdr(struct rte_mbuf *pkt_src, struct rte_mbuf *pkt_dst) eth_to = rte_pktmbuf_mtod(pkt_dst, struct rte_ether_hdr *);/* copy header */ -rte_memcpy (eth_to, eth_from,sizeof (struct rte_ether_hdr )); + *eth_to = *eth_from; } static inline void
examples/l2fwd-cat/cat.c +1 -2
@@ -314,8 +314,7 @@ parse_l3ca(const char *l3ca)if (cmask !=0 &&is_contiguous (cmask) ==0 ) goto err; -rte_memcpy (&m_config[idx].cpumask, - &cpuset,sizeof (rte_cpuset_t)); + m_config[idx].cpumask = cpuset;if (cmask !=0 ) { m_config[idx].cdp =1 ;
examples/ptpclient/ptpclient.c +1 -3
@@ -470,9 +470,7 @@ parse_fup(struct ptpv2_time_receiver_ordinary *ptp_data) client_clkid->id[6 ] = eth_hdr->src_addr.addr_bytes[4 ]; client_clkid->id[7 ] = eth_hdr->src_addr.addr_bytes[5 ]; -rte_memcpy (&ptp_data->client_clock_id, - client_clkid, -sizeof (struct clock_id )); + ptp_data->client_clock_id = *client_clkid;/* Enable flag for hardware timestamping. */ created_pkt->ol_flags |=RTE_MBUF_F_TX_IEEE1588_TMST ;
Signature · 1 line
2.47.2
PATCH 11/32 node: replace memcpy with assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by cocci/rte_memcpy.cocci.
--- lib/node/ethdev_rx.c | 2 +- lib/node/ip4_reassembly.c | 2 +- lib/node/kernel_rx.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
lib/node/ethdev_rx.c +1 -1
@@ -186,7 +186,7 @@ ethdev_rx_node_init(const struct rte_graph *graph, struct rte_node *node)while (elem) {if (elem->nid == node->id) {/* Update node specific context */ -memcpy (ctx, &elem->ctx,sizeof (ethdev_rx_node_ctx_t)); + *ctx = elem->ctx;break ; } elem = elem->next;
lib/node/ip4_reassembly.c +1 -1
@@ -157,7 +157,7 @@ ip4_reassembly_node_init(const struct rte_graph *graph, struct rte_node *node)while (elem) {if (elem->node_id == node->id) {/* Update node specific context */ -memcpy (ctx, &elem->ctx,sizeof (ip4_reassembly_ctx_t)); + *ctx = elem->ctx;break ; } elem = elem->next;
lib/node/kernel_rx.c +1 -1
@@ -198,7 +198,7 @@ kernel_rx_node_init(const struct rte_graph *graph, struct rte_node *node)while (elem) {if (elem->nid == node->id) {/* Update node specific context */ -memcpy (ctx, &elem->ctx,sizeof (kernel_rx_node_ctx_t)); + *ctx = elem->ctx;break ; } elem = elem->next;
Signature · 1 line
2.47.2
PATCH 12/32 pipeline: replace memcpy with assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by cocci/struct_assign.cocci
--- 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(-)
examples/ip_pipeline/parser.c +1 -1
@@ -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 ; }
lib/pipeline/rte_pipeline.c +3 -3
@@ -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;
lib/pipeline/rte_swx_ctl.c +1 -1
@@ -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); }
lib/pipeline/rte_swx_ipsec.c +1 -1
@@ -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, ¶ms->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 ;
lib/pipeline/rte_swx_pipeline_spec.c +12 -24
@@ -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], - ®array_spec, -sizeof (struct regarray_spec )); + s->regarrays[s->n_regarrays] = regarray_spec; s->n_regarrays++;memset (®array_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 ));
Signature · 1 line
2.47.2
PATCH 13/32 sched: replace memcpy with structure assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by struct-assign.cocci.
--- lib/sched/rte_sched.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/sched/rte_sched.c +1 -1
@@ -1775,7 +1775,7 @@ rte_sched_queue_read_stats(struct rte_sched_port *port, qe = s->queue_extra + subport_qindex;/* Copy queue stats and clear */ -memcpy (stats, &qe->stats,sizeof (struct rte_sched_queue_stats )); + *stats = qe->stats;memset (&qe->stats,0 ,sizeof (struct rte_sched_queue_stats ));/* Queue length */
Signature · 1 line
2.47.2
PATCH 14/32 table: replace memcpy with structure assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by struct-assign.cocci.
--- lib/table/rte_swx_table_selector.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/table/rte_swx_table_selector.c +1 -1
@@ -225,7 +225,7 @@ table_params_copy(struct table *t, struct rte_swx_table_selector_params *params)if (selector_size <8 ) selector_size =8 ; -memcpy (&t->params, params,sizeof (struct rte_swx_table_selector_params )); + t->params = *params; t->params.selector_size = selector_size; t->params.selector_mask =NULL ; t->params.n_groups_max =rte_align32pow2 (params->n_groups_max);
Signature · 1 line
2.47.2
PATCH 15/32 net/ntnic: replace memcpy with structure assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by struct-assign.cocci.
--- drivers/net/ntnic/nthw/flow_api/flow_id_table.c | 4 ++-- .../nthw/flow_api/profile_inline/flow_api_profile_inline.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/ntnic/nthw/flow_api/flow_id_table.c +2 -2
@@ -99,7 +99,7 @@ uint32_t ntnic_id_table_get_id(void *id_table, union flm_handles flm_h, uint8_tstruct ntnic_id_table_element *element =ntnic_id_table_array_find_element (handle, new_id); element->caller_id = caller_id; element->type = type; -memcpy (&element->handle, &flm_h,sizeof (union flm_handles )); + element->handle = flm_h;rte_spinlock_unlock (&handle->mtx);
@@ -139,7 +139,7 @@ void ntnic_id_table_find(void *id_table, uint32_t id, union flm_handles *flm_h, *caller_id = element->caller_id; *type = element->type; -memcpy (flm_h, &element->handle,sizeof (union flm_handles )); + *flm_h = element->handle;rte_spinlock_unlock (&handle->mtx); }
drivers/net/ntnic/nthw/flow_api/profile_inline/flow_api_profile_inline.c +1 -1
@@ -3099,7 +3099,7 @@ static int convert_fh_to_fh_flm(struct flow_handle *fh, const uint32_t *packet_dif (fh->type !=FLOW_HANDLE_TYPE_FLOW )return -1 ; -memcpy (&fh_copy, fh,sizeof (struct flow_handle )); + fh_copy = *fh;memset (fh,0x0 ,sizeof (struct flow_handle )); fd = fh_copy.fd;
Signature · 1 line
2.47.2
PATCH 16/32 net/bnxt: replace memcpy with structure assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by struct-assign.cocci.
--- drivers/net/bnxt/bnxt_hwrm.c | 3 +-- drivers/net/bnxt/tf_core/tf_rm.c | 8 ++------ drivers/net/bnxt/tf_ulp/ulp_tun.c | 3 +-- 3 files changed, 4 insertions(+), 10 deletions(-)
drivers/net/bnxt/bnxt_hwrm.c +1 -2
@@ -3266,8 +3266,7 @@ int bnxt_hwrm_func_qstats(struct bnxt *bp, uint16_t fid,HWRM_CHECK_RESULT ();if (func_qstats) -memcpy (func_qstats, resp, -sizeof (struct hwrm_func_qstats_output )); + *func_qstats = *resp;if (!stats) goto exit;
drivers/net/bnxt/tf_core/tf_rm.c +2 -6
@@ -1265,9 +1265,7 @@ tf_rm_get_info(struct tf_rm_get_alloc_info_parms *parms)if (cfg_type ==TF_RM_ELEM_CFG_NULL )return -ENOTSUP ; -memcpy (parms->info, - &rm_db->db[parms->subtype].alloc, -sizeof (struct tf_rm_alloc_info )); + *parms->info = rm_db->db[parms->subtype].alloc;return 0 ; }
@@ -1299,9 +1297,7 @@ tf_rm_get_all_info(struct tf_rm_get_alloc_info_parms *parms, int size)continue ; } -memcpy (info, - &rm_db->db[i].alloc, -sizeof (struct tf_rm_alloc_info )); + *info = rm_db->db[i].alloc; info++; }
drivers/net/bnxt/tf_ulp/ulp_tun.c +1 -2
@@ -40,8 +40,7 @@ ulp_app_tun_search_entry(struct bnxt_ulp_context *ulp_ctx, }if (free_entry >=0 ) { *tun_entry = &tun_ent_list[free_entry]; -memcpy (&tun_ent_list[free_entry].app_tunnel, app_tunnel, -sizeof (struct rte_flow_tunnel )); + tun_ent_list[free_entry].app_tunnel = *app_tunnel; tun_ent_list[free_entry].ref_cnt =1 ; rc =1 ; }else {
Signature · 1 line
2.47.2
Re: [PATCH 16/32] net/bnxt: replace memcpy with structure assignment
Quoted 66 lines · Stephen Hemminger
Prefer structure assignment over memcpy.
Found bystruct-assign.cocci.Signed-off-by Stephen Hemminger <[email protected]>--- drivers/net/bnxt/bnxt_hwrm.c | 3 +-- drivers/net/bnxt/tf_core/tf_rm.c | 8 ++------ drivers/net/bnxt/tf_ulp/ulp_tun.c | 3 +-- 3 files changed, 4 insertions(+), 10 deletions(-)drivers/net/bnxt/bnxt_hwrm.c +1
-2@@ -3266,8 +3266,7 @@ int bnxt_hwrm_func_qstats(struct bnxt *bp, uint16_t fid,HWRM_CHECK_RESULT ();if (func_qstats) -memcpy (func_qstats, resp, -sizeof (struct hwrm_func_qstats_output )); + *func_qstats = *resp;if (!stats) goto exit;drivers/net/bnxt/tf_core/tf_rm.c +2
-6@@ -1265,9 +1265,7 @@ tf_rm_get_info(struct tf_rm_get_alloc_info_parms *parms)if (cfg_type ==TF_RM_ELEM_CFG_NULL )return -ENOTSUP ; -memcpy (parms->info, - &rm_db->db[parms->subtype].alloc, -sizeof (struct tf_rm_alloc_info )); + *parms->info = rm_db->db[parms->subtype].alloc;return 0 ; }@@ -1299,9 +1297,7 @@ tf_rm_get_all_info(struct tf_rm_get_alloc_info_parms *parms, int size)continue ; } -memcpy (info, - &rm_db->db[i].alloc, -sizeof (struct tf_rm_alloc_info )); + *info = rm_db->db[i].alloc; info++; }drivers/net/bnxt/tf_ulp/ulp_tun.c +1
-3@@ -40,8 +40,7 @@ ulp_app_tun_search_entry(struct bnxt_ulp_context *ulp_ctx, }if (free_entry >=0 ) { *tun_entry = &tun_ent_list[free_entry]; -memcpy (&tun_ent_list[free_entry].app_tunnel, app_tunnel, -sizeof (struct rte_flow_tunnel )); + tun_ent_list[free_entry].app_tunnel = *app_tunnel; tun_ent_list[free_entry].ref_cnt =1 ; rc =1 ; }else { --
Quoted 2 lines
2.47.2
PATCH 17/32 crypto/qat: replace memcpy with structure assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by struct-assign.cocci.
--- drivers/crypto/qat/dev/qat_crypto_pmd_gen3.c | 3 +-- drivers/crypto/qat/dev/qat_crypto_pmd_gen5.c | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-)
drivers/crypto/qat/dev/qat_crypto_pmd_gen3.c +1 -2
@@ -277,8 +277,7 @@ qat_sym_crypto_cap_get_gen3(struct qat_cryptodev_private *internals, RTE_CRYPTO_CIPHER_DES_DOCSISBPI)))continue ; -memcpy (addr + curr_capa, capabilities + iter, -sizeof (struct rte_cryptodev_capabilities )); + *(addr + curr_capa) = *(capabilities + iter); if (internals->qat_dev->options.has_wireless_slice && ( check_auth_capa(&capabilities[iter],
drivers/crypto/qat/dev/qat_crypto_pmd_gen5.c +1 -2
@@ -203,8 +203,7 @@ qat_sym_crypto_cap_get_gen5(struct qat_cryptodev_private *internals,continue ; } -memcpy (addr + curr_capa, capabilities + iter, -sizeof (struct rte_cryptodev_capabilities )); + *(addr + curr_capa) = *(capabilities + iter); curr_capa++; } internals->qat_dev_capabilities = internals->capa_mz->addr;
Signature · 1 line
2.47.2
PATCH 18/32 mempool/cnxk: replace memcpy with structure assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by struct-assign.cocci.
--- drivers/mempool/cnxk/cnxk_mempool_ops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mempool/cnxk/cnxk_mempool_ops.c +1 -1
@@ -103,7 +103,7 @@ cnxk_mempool_alloc(struct rte_mempool *mp)struct npa_aura_s *paura; paura =CNXK_MEMPOOL_CONFIG (mp); -memcpy (&aura, paura,sizeof (struct npa_aura_s )); + aura = *paura; } rc = roc_npa_pool_create(&aura_handle, block_size, block_count, &aura,
Signature · 1 line
2.47.2
PATCH 19/32 net/dpaa2: replace memcpy with assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by cocci/struct_assign.cocci
--- drivers/net/dpaa2/dpaa2_mux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/dpaa2/dpaa2_mux.c +1 -1
@@ -293,7 +293,7 @@ rte_pmd_dpaa2_mux_flow_create(uint32_t dpdmux_id, ret); goto creation_error; } -rte_memcpy (&s_kg_cfg, &kg_cfg,sizeof (struct dpkg_profile_cfg )); + s_kg_cfg = kg_cfg; }else {if (memcmp (&s_kg_cfg, &kg_cfg,sizeof (struct dpkg_profile_cfg ))) {
Signature · 1 line
2.47.2
Re: [PATCH 19/32] net/dpaa2: replace memcpy with assignment
Quoted 21 lines · Stephen Hemminger
Prefer structure assignment over memcpy.
Found bycocci/struct_assign.cocciSigned-off-by Stephen Hemminger <[email protected]>--- drivers/net/dpaa2/dpaa2_mux.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/dpaa2/dpaa2_mux.c +1
-1@@ -293,7 +293,7 @@ rte_pmd_dpaa2_mux_flow_create(uint32_t dpdmux_id, ret); goto creation_error; } -rte_memcpy (&s_kg_cfg, &kg_cfg,sizeof (struct dpkg_profile_cfg )); + s_kg_cfg = kg_cfg; }else {if (memcmp (&s_kg_cfg, &kg_cfg,sizeof (struct dpkg_profile_cfg ))) {
PATCH 20/32 net/enic: replace memcpy with assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by cocci/struct_assign.cocci
--- drivers/net/enic/enic_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/enic/enic_main.c +1 -1
@@ -1238,7 +1238,7 @@ int enic_set_rss_reta(struct enic *enic, union vnic_rss_cpu *rss_cpu)if (!rss_cpu_buf_va)return -ENOMEM ; -rte_memcpy (rss_cpu_buf_va, rss_cpu,sizeof (union vnic_rss_cpu )); + *rss_cpu_buf_va = *rss_cpu; err = enic_set_rss_cpu(enic, rss_cpu_buf_pa,
Signature · 1 line
2.47.2
PATCH 21/32 net/intel/i40e: replace memcpy with structure assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by struct-assign.cocci.
--- drivers/net/intel/i40e/i40e_ethdev.c | 6 ++---- drivers/net/intel/i40e/i40e_fdir.c | 3 +-- drivers/net/intel/i40e/i40e_flow.c | 3 +-- drivers/net/intel/i40e/rte_pmd_i40e.c | 3 +-- drivers/net/intel/ixgbe/ixgbe_flow.c | 4 +--- 5 files changed, 6 insertions(+), 13 deletions(-)
drivers/net/intel/i40e/i40e_ethdev.c +2 -4
@@ -5987,8 +5987,7 @@ i40e_vsi_setup(struct i40e_pf *pf,PMD_DRV_LOG (ERR ,"Failed to get VSI params" ); goto fail_msix_alloc; } -rte_memcpy (&vsi->info, &ctxt.info, -sizeof (struct i40e_aqc_vsi_properties_data )); + vsi->info = ctxt.info; vsi->vsi_id = ctxt.vsi_number; vsi->info.valid_sections =0 ;
@@ -6005,8 +6004,7 @@ i40e_vsi_setup(struct i40e_pf *pf,rte_cpu_to_le_16 (I40E_AQ_VSI_PROP_VLAN_VALID ); vsi->info.port_vlan_flags =I40E_AQ_VSI_PVLAN_MODE_ALL |I40E_AQ_VSI_PVLAN_EMOD_STR_BOTH ; -rte_memcpy (&ctxt.info, &vsi->info, -sizeof (struct i40e_aqc_vsi_properties_data )); + ctxt.info = vsi->info; ret =i40e_vsi_config_tc_queue_mapping (vsi, &ctxt.info,I40E_DEFAULT_TCMAP );if (ret !=I40E_SUCCESS ) {
drivers/net/intel/i40e/i40e_fdir.c +1 -2
@@ -1252,8 +1252,7 @@ i40e_flow_store_flex_mask(struct i40e_pf *pf, sizeof(struct i40e_fdir_flex_mask))))return 1 ; -memcpy (&pf->fdir.flex_mask[pctype], &flex_mask, -sizeof (struct i40e_fdir_flex_mask )); + pf->fdir.flex_mask[pctype] = flex_mask;return 0 ; }
drivers/net/intel/i40e/i40e_flow.c +1 -2
@@ -2364,8 +2364,7 @@ i40e_flow_parse_fdir_pattern(struct rte_eth_dev *dev, next_dst_off += raw_spec->length; raw_id++; -memcpy (&filter->input.flow_ext.flex_pit[field_idx], - &flex_pit,sizeof (struct i40e_fdir_flex_pit )); + filter->input.flow_ext.flex_pit[field_idx] = flex_pit; filter->input.flow_ext.layer_idx = layer_idx; filter->input.flow_ext.raw_id = raw_id; filter->input.flow_ext.is_flex_flow = true;
drivers/net/intel/i40e/rte_pmd_i40e.c +1 -2
@@ -2961,8 +2961,7 @@ i40e_queue_region_get_all_info(struct i40e_pf *pf, {struct i40e_queue_regions *info = &pf->queue_region; -rte_memcpy (regions_ptr, info, -sizeof (struct i40e_queue_regions )); + *regions_ptr = *info;return 0 ; }
drivers/net/intel/ixgbe/ixgbe_flow.c +1 -3
@@ -3142,9 +3142,7 @@ ixgbe_flow_create(struct rte_eth_dev *dev,if (fdir_rule.b_mask) {if (!fdir_info->mask_added) {/* It's the first time the mask is set. */ -rte_memcpy (&fdir_info->mask, - &fdir_rule.mask, -sizeof (struct ixgbe_hw_fdir_mask )); + *&fdir_info->mask = *&fdir_rule.mask;if (fdir_rule.mask.flex_bytes_mask) { ret = ixgbe_fdir_set_flexbytes_offset(dev,
Signature · 1 line
2.47.2
PATCH 22/32 net/nfp: replace memcpy with assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by cocci/struct_assign.cocci
--- drivers/net/nfp/flower/nfp_flower_representor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/nfp/flower/nfp_flower_representor.c +1 -1
@@ -318,7 +318,7 @@ nfp_flower_repr_stats_get(struct rte_eth_dev *ethdev,struct nfp_flower_representor *repr; repr = ethdev->data->dev_private; -rte_memcpy (stats, &repr->repr_stats,sizeof (struct rte_eth_stats )); + *stats = repr->repr_stats;return 0 ; }
Signature · 1 line
2.47.2
RE: [PATCH 22/32] net/nfp: replace memcpy with assignment
Thanks.
Quoted 33 lines
-----Original Message-----
From: Stephen Hemminger <[email protected]>
Sent: Sunday, February 9, 2025 4:22 AM
To: [email protected]
Cc: Stephen Hemminger <[email protected]>; Chaoyong He <[email protected]>
Subject: [PATCH 22/32] net/nfp: replace memcpy with assignmentPrefer structure assignment over memcpy.
Found bycocci/struct_assign.cocciSigned-off-by Stephen Hemminger <[email protected]>--- drivers/net/nfp/flower/nfp_flower_representor.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)drivers/net/nfp/flower/nfp_flower_representor.c +1
-1@@ -318,7 +318,7 @@ nfp_flower_repr_stats_get(struct rte_eth_dev *ethdev, struct nfp_flower_representor *repr; repr = ethdev->data->dev_private; -rte_memcpy (stats, &repr->repr_stats,sizeof (struct rte_eth_stats )); + *stats = repr->repr_stats;return 0 ;}
--
2.47.2
PATCH 23/32 net/txgbe: replace memcpy with assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by cocci/struct_assign.cocci
--- drivers/net/txgbe/txgbe_flow.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/txgbe/txgbe_flow.c +1 -3
@@ -2827,9 +2827,7 @@ txgbe_flow_create(struct rte_eth_dev *dev,if (fdir_rule.b_mask) {if (!fdir_info->mask_added) {/* It's the first time the mask is set. */ -rte_memcpy (&fdir_info->mask, - &fdir_rule.mask, -sizeof (struct txgbe_hw_fdir_mask )); + fdir_info->mask = fdir_rule.mask; fdir_info->flex_bytes_offset = fdir_rule.flex_bytes_offset;
Signature · 1 line
2.47.2
PATCH 24/32 net/bnx2x: replace memcpy with structure assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by struct-assign.cocci.
--- drivers/net/bnx2x/bnx2x_stats.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/bnx2x/bnx2x_stats.c +1 -1
@@ -805,7 +805,7 @@ bnx2x_hw_stats_update(struct bnx2x_softc *sc) etherstatspktsover1522octets); } -memcpy (old, new,sizeof (struct nig_stats )); + *old = *new;memcpy (RTE_PTR_ADD (estats, offsetof(struct bnx2x_eth_stats , rx_stat_ifhcinbadoctets_hi)), &pstats->mac_stx[1 ],sizeof (struct mac_stx ));
Signature · 1 line
2.47.2
PATCH 25/32 net/dpaa2: replace memcpy with structure assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by struct-assign.cocci.
--- drivers/net/dpaa2/dpaa2_ethdev.c | 5 ++--- drivers/net/dpaa2/dpaa2_flow.c | 9 +++------ 2 files changed, 5 insertions(+), 9 deletions(-)
drivers/net/dpaa2/dpaa2_ethdev.c +2 -3
@@ -2539,8 +2539,7 @@ populate_mac_addr(struct fsl_mc_io *dpni_dev, ret); goto cleanup; } -memcpy (&prime_mac, &phy_mac, -sizeof (struct rte_ether_addr )); + prime_mac = phy_mac; } }else if (rte_is_zero_ether_addr (&prime_mac)) {/* In case phys and prime, both are zero, create random MAC */
@@ -2555,7 +2554,7 @@ populate_mac_addr(struct fsl_mc_io *dpni_dev, }/* prime_mac the final MAC address */ -memcpy (mac_entry, &prime_mac,sizeof (struct rte_ether_addr )); + *mac_entry = prime_mac;return 0 ; cleanup:
drivers/net/dpaa2/dpaa2_flow.c +3 -6
@@ -1008,8 +1008,7 @@ dpaa2_flow_faf_add_hdr(int faf_byte,if (pos != dpkg->num_extracts) {/* Not the last pos, must have IP address extract.*/ for (i = dpkg->num_extracts -1 ; i >= pos; i--) { -memcpy (&extracts[i +1 ], - &extracts[i],sizeof (struct dpkg_extract )); + extracts[i +1 ] = extracts[i]; } }
@@ -1063,8 +1062,7 @@ dpaa2_flow_pr_add_hdr(uint32_t pr_offset,if (pos != dpkg->num_extracts) {/* Not the last pos, must have IP address extract.*/ for (i = dpkg->num_extracts -1 ; i >= pos; i--) { -memcpy (&extracts[i +1 ], - &extracts[i],sizeof (struct dpkg_extract )); + extracts[i +1 ] = extracts[i]; } }
@@ -1118,8 +1116,7 @@ dpaa2_flow_extract_add_hdr(enum net_prot prot,if (pos != dpkg->num_extracts) {/* Not the last pos, must have IP address extract.*/ for (i = dpkg->num_extracts -1 ; i >= pos; i--) { -memcpy (&extracts[i +1 ], - &extracts[i],sizeof (struct dpkg_extract )); + extracts[i +1 ] = extracts[i]; } }
Signature · 1 line
2.47.2
Re: [PATCH 25/32] net/dpaa2: replace memcpy with structure assignment
Quoted 66 lines · Stephen Hemminger
Prefer structure assignment over memcpy.
Found bystruct-assign.cocci.Signed-off-by Stephen Hemminger <[email protected]>--- drivers/net/dpaa2/dpaa2_ethdev.c | 5 ++--- drivers/net/dpaa2/dpaa2_flow.c | 9 +++------ 2 files changed, 5 insertions(+), 9 deletions(-)drivers/net/dpaa2/dpaa2_ethdev.c +2
-3@@ -2539,8 +2539,7 @@ populate_mac_addr(struct fsl_mc_io *dpni_dev, ret); goto cleanup; } -memcpy (&prime_mac, &phy_mac, -sizeof (struct rte_ether_addr )); + prime_mac = phy_mac; } }else if (rte_is_zero_ether_addr (&prime_mac)) {/* In case phys and prime, both are zero, create random MAC */ @@ -2555,7 +2554,7 @@ populate_mac_addr(struct fsl_mc_io *dpni_dev, }/* prime_mac the final MAC address */ -memcpy (mac_entry, &prime_mac,sizeof (struct rte_ether_addr )); + *mac_entry = prime_mac;return 0 ; cleanup:drivers/net/dpaa2/dpaa2_flow.c +3
-6@@ -1008,8 +1008,7 @@ dpaa2_flow_faf_add_hdr(int faf_byte,if (pos != dpkg->num_extracts) {/* Not the last pos, must have IP address extract.*/ for (i = dpkg->num_extracts -1 ; i >= pos; i--) { -memcpy (&extracts[i +1 ], - &extracts[i],sizeof (struct dpkg_extract )); + extracts[i +1 ] = extracts[i]; } }@@ -1063,8 +1062,7 @@ dpaa2_flow_pr_add_hdr(uint32_t pr_offset,if (pos != dpkg->num_extracts) {/* Not the last pos, must have IP address extract.*/ for (i = dpkg->num_extracts -1 ; i >= pos; i--) { -memcpy (&extracts[i +1 ], - &extracts[i],sizeof (struct dpkg_extract )); + extracts[i +1 ] = extracts[i]; } }@@ -1118,8 +1116,7 @@ dpaa2_flow_extract_add_hdr(enum net_prot prot,if (pos != dpkg->num_extracts) {/* Not the last pos, must have IP address extract.*/ for (i = dpkg->num_extracts -1 ; i >= pos; i--) { -memcpy (&extracts[i +1 ], - &extracts[i],sizeof (struct dpkg_extract )); + extracts[i +1 ] = extracts[i]; } }
PATCH 26/32 net/bonding: replace memcpy with structure assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by struct-assign.cocci.
--- drivers/net/bonding/rte_eth_bond_pmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/bonding/rte_eth_bond_pmd.c +1 -1
@@ -3222,7 +3222,7 @@ bond_ethdev_rss_hash_update(struct rte_eth_dev *dev,struct bond_dev_private *internals = dev->data->dev_private;struct rte_eth_rss_conf bond_rss_conf; -memcpy (&bond_rss_conf, rss_conf,sizeof (struct rte_eth_rss_conf )); + bond_rss_conf = *rss_conf; bond_rss_conf.rss_hf &= internals->flow_type_rss_offloads;
Signature · 1 line
2.47.2
PATCH 27/32 net/cnxk: replace memcpy with structure assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by struct-assign.cocci.
--- drivers/net/cnxk/cnxk_ethdev_cman.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/cnxk/cnxk_ethdev_cman.c +1 -1
@@ -140,6 +140,6 @@ cnxk_nix_cman_config_get(struct rte_eth_dev *eth_dev, struct rte_eth_cman_config {struct cnxk_eth_dev *dev =cnxk_eth_pmd_priv (eth_dev); -memcpy (config, &dev->cman_cfg,sizeof (struct rte_eth_cman_config )); + *config = dev->cman_cfg;return 0 ; }
Signature · 1 line
2.47.2
PATCH 28/32 net/enic: replace memcpy with structure assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by struct-assign.cocci.
--- drivers/net/enic/enic_fm_flow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/enic/enic_fm_flow.c +1 -1
@@ -2590,7 +2590,7 @@ enic_action_handle_get(struct enic_flowman *fm, struct fm_action *action_in,return rte_flow_error_set (error,ENOMEM ,RTE_FLOW_ERROR_TYPE_HANDLE ,NULL ,"enic: calloc(fm-action)" ); -memcpy (&ah->key, action_in,sizeof (struct fm_action )); + ah->key = *action_in; args[0 ] =FM_ACTION_ALLOC ; args[1 ] = fm->cmd.pa; ret =flowman_cmd (fm, args,2 );
Signature · 1 line
2.47.2
PATCH 29/32 net/iavf: replace memcpy with structure assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by struct-assign.cocci.
--- drivers/net/intel/iavf/iavf_ipsec_crypto.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/net/intel/iavf/iavf_ipsec_crypto.c +1 -2
@@ -1139,8 +1139,7 @@ iavf_ipsec_crypto_pkt_metadata_set(void *device, struct iavf_ipsec_crypto_pkt_metadata *);/* Set immutable metadata values from session template */ -memcpy (md, &iavf_sess->pkt_metadata_template, -sizeof (struct iavf_ipsec_crypto_pkt_metadata )); + *md = iavf_sess->pkt_metadata_template; esp_tail =iavf_ipsec_crypto_get_esp_trailer (m, iavf_sess, &esp_trailer_length);
Signature · 1 line
2.47.2
PATCH 30/32 net/ice: replace memcpy with structure assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by struct-assign.cocci.
--- drivers/net/intel/ice/ice_hash.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/intel/ice/ice_hash.c +2 -4
@@ -1309,8 +1309,7 @@ ice_hash_create(struct ice_adapter *ad, goto out; }else {if (rss_meta->raw.raw_ena) { -memcpy (&filter_ptr->rss_cfg.raw, &rss_meta->raw, -sizeof (struct ice_rss_raw_cfg )); + filter_ptr->rss_cfg.raw = rss_meta->raw; ret =ice_hash_add_raw_cfg (ad, &rss_meta->raw, pf->main_vsi->idx);if (ret) {
@@ -1321,8 +1320,7 @@ ice_hash_create(struct ice_adapter *ad, goto error; } }else { -memcpy (&filter_ptr->rss_cfg.hash, &rss_meta->cfg, -sizeof (struct ice_rss_hash_cfg )); + filter_ptr->rss_cfg.hash = rss_meta->cfg; ret =ice_add_rss_cfg_wrap (pf, vsi->idx, &filter_ptr->rss_cfg.hash);if (ret) {
Signature · 1 line
2.47.2
PATCH 31/32 test: replace memcpy with structure assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by struct-assign.cocci.
--- app/test/test_acl.c | 5 ++-- app/test/test_compressdev.c | 36 +++++++++------------------ app/test/test_security_inline_proto.c | 23 +++++++---------- 3 files changed, 23 insertions(+), 41 deletions(-)
app/test/test_acl.c +2 -3
@@ -1223,8 +1223,7 @@ test_create_find_add(void)/* create dummy acl */ for (i =0 ; i <LEN ; i++) { -memcpy (&rules[i], &acl_rule, -sizeof (struct rte_acl_ipv4vlan_rule )); + rules[i] = acl_rule;/* skip zero */ rules[i].data.userdata = i +1 ;/* one rule per category */
@@ -1286,7 +1285,7 @@ test_invalid_rules(void)* such rules. */ /* create dummy acl */ -memcpy (&rule, &acl_rule,sizeof (struct rte_acl_ipv4vlan_rule )); + rule = acl_rule; rule.data.userdata =1 ; rule.dst_port_low =0xfff0 ; rule.dst_port_high =0x0010 ;
app/test/test_compressdev.c +12 -24
@@ -346,8 +346,7 @@ test_compressdev_invalid_configuration(void)RTE_LOG (INFO ,USER1 ,"This is a negative test, errors are expected\n" );/* Invalid configuration with 0 queue pairs */ -memcpy (&invalid_config, &valid_config, -sizeof (struct rte_compressdev_config )); + invalid_config = valid_config; invalid_config.nb_queue_pairs =0 ; TEST_ASSERT_FAIL(rte_compressdev_configure(0, &invalid_config),
@@ -360,8 +359,7 @@ test_compressdev_invalid_configuration(void)*/ rte_compressdev_info_get (0 , &dev_info);if (dev_info.max_nb_queue_pairs !=0 ) { -memcpy (&invalid_config, &valid_config, -sizeof (struct rte_compressdev_config )); + invalid_config = valid_config; invalid_config.nb_queue_pairs = dev_info.max_nb_queue_pairs +1 ; TEST_ASSERT_FAIL(rte_compressdev_configure(0, &invalid_config),
@@ -2188,8 +2186,7 @@ test_compressdev_deflate_stateless_fixed(void) goto exit; } -memcpy (compress_xform, ts_params->def_comp_xform, -sizeof (struct rte_comp_xform )); + *compress_xform = *ts_params->def_comp_xform; compress_xform->compress.deflate.huffman =RTE_COMP_HUFFMAN_FIXED ;struct interim_data_params int_data = {
@@ -2260,8 +2257,7 @@ test_compressdev_deflate_stateless_dynamic(void) goto exit; } -memcpy (compress_xform, ts_params->def_comp_xform, -sizeof (struct rte_comp_xform )); + *compress_xform = *ts_params->def_comp_xform; compress_xform->compress.deflate.huffman =RTE_COMP_HUFFMAN_DYNAMIC ;struct interim_data_params int_data = {
@@ -2372,8 +2368,7 @@ test_compressdev_deflate_stateless_multi_level(void) goto exit; } -memcpy (compress_xform, ts_params->def_comp_xform, -sizeof (struct rte_comp_xform )); + *compress_xform = *ts_params->def_comp_xform;struct interim_data_params int_data = {NULL ,
@@ -2442,8 +2437,7 @@ test_compressdev_deflate_stateless_multi_xform(void) goto exit; } -memcpy (compress_xforms[i], ts_params->def_comp_xform, -sizeof (struct rte_comp_xform )); + *compress_xforms[i] = *ts_params->def_comp_xform; compress_xforms[i]->compress.level = level; level++;
@@ -2456,8 +2450,7 @@ test_compressdev_deflate_stateless_multi_xform(void) goto exit; } -memcpy (decompress_xforms[i], ts_params->def_decomp_xform, -sizeof (struct rte_comp_xform )); + *decompress_xforms[i] = *ts_params->def_decomp_xform; }for (i =0 ; i <NUM_XFORMS ; i++) {
@@ -2614,8 +2607,7 @@ test_compressdev_deflate_stateless_checksum(void)return TEST_FAILED ; } -memcpy (compress_xform, ts_params->def_comp_xform, -sizeof (struct rte_comp_xform )); + *compress_xform = *ts_params->def_comp_xform;struct rte_comp_xform *decompress_xform =rte_malloc (NULL ,sizeof (struct rte_comp_xform ),0 );
@@ -2625,8 +2617,7 @@ test_compressdev_deflate_stateless_checksum(void)return TEST_FAILED ; } -memcpy (decompress_xform, ts_params->def_decomp_xform, -sizeof (struct rte_comp_xform )); + *decompress_xform = *ts_params->def_decomp_xform;struct interim_data_params int_data = {NULL ,
@@ -2960,8 +2951,7 @@ test_compressdev_deflate_stateful_decomp_checksum(void)return TEST_FAILED ; } -memcpy (compress_xform, ts_params->def_comp_xform, -sizeof (struct rte_comp_xform )); + *compress_xform = *ts_params->def_comp_xform;struct rte_comp_xform *decompress_xform =rte_malloc (NULL ,sizeof (struct rte_comp_xform ),0 );
@@ -2971,8 +2961,7 @@ test_compressdev_deflate_stateful_decomp_checksum(void)return TEST_FAILED ; } -memcpy (decompress_xform, ts_params->def_decomp_xform, -sizeof (struct rte_comp_xform )); + *decompress_xform = *ts_params->def_decomp_xform;struct interim_data_params int_data = { &compress_test_bufs[0 ],
@@ -3186,8 +3175,7 @@ test_compressdev_deflate_stateless_fixed_oos_recoverable(void) goto exit; } -memcpy (compress_xform, ts_params->def_comp_xform, -sizeof (struct rte_comp_xform )); + *compress_xform = *ts_params->def_comp_xform; compress_xform->compress.deflate.huffman =RTE_COMP_HUFFMAN_FIXED ;struct interim_data_params int_data = {
app/test/test_security_inline_proto.c +9 -14
@@ -858,7 +858,7 @@ test_ipsec_with_rx_inject(struct ip_pkt_vector *vector, const struct ipsec_test_ burst_sz = vector->burst ?ENCAP_DECAP_BURST_SZ :1 ; nb_tx = burst_sz; -memcpy (&sa_data, vector->sa_data,sizeof (struct ipsec_test_data )); + sa_data = *vector->sa_data; sa_data.ipsec_xform.direction =RTE_SECURITY_IPSEC_SA_DIR_EGRESS ; outer_ipv4 =is_outer_ipv4 (&sa_data);
@@ -873,7 +873,7 @@ test_ipsec_with_rx_inject(struct ip_pkt_vector *vector, const struct ipsec_test_ }for (i =0 ; i < burst_sz; i++) { -memcpy (&sa_data, vector->sa_data,sizeof (struct ipsec_test_data )); + sa_data = *vector->sa_data;/* Update SPI for every new SA */ sa_data.ipsec_xform.spi += i; sa_data.ipsec_xform.direction =RTE_SECURITY_IPSEC_SA_DIR_EGRESS ;
@@ -901,7 +901,7 @@ test_ipsec_with_rx_inject(struct ip_pkt_vector *vector, const struct ipsec_test_ }for (i =0 ; i < burst_sz; i++) { -memcpy (&sa_data, vector->sa_data,sizeof (struct ipsec_test_data )); + sa_data = *vector->sa_data;/* Update SPI for every new SA */ sa_data.ipsec_xform.spi += i; sa_data.ipsec_xform.direction =RTE_SECURITY_IPSEC_SA_DIR_INGRESS ;
@@ -1078,7 +1078,7 @@ test_ipsec_with_reassembly(struct reassembly_vector *vector,memset (tx_pkts_burst,0 ,sizeof (tx_pkts_burst[0 ]) * nb_tx);memset (rx_pkts_burst,0 ,sizeof (rx_pkts_burst[0 ]) * nb_tx); -memcpy (&sa_data, vector->sa_data,sizeof (struct ipsec_test_data )); + sa_data = *vector->sa_data; sa_data.ipsec_xform.direction =RTE_SECURITY_IPSEC_SA_DIR_EGRESS ; outer_ipv4 =is_outer_ipv4 (&sa_data);
@@ -1096,8 +1096,7 @@ test_ipsec_with_reassembly(struct reassembly_vector *vector, }for (i =0 ; i < burst_sz; i++) { -memcpy (&sa_data, vector->sa_data, -sizeof (struct ipsec_test_data )); + sa_data = *vector->sa_data;/* Update SPI for every new SA */ sa_data.ipsec_xform.spi += i; sa_data.ipsec_xform.direction =
@@ -1132,8 +1131,7 @@ test_ipsec_with_reassembly(struct reassembly_vector *vector, }for (i =0 ; i < burst_sz; i++) { -memcpy (&sa_data, vector->sa_data, -sizeof (struct ipsec_test_data )); + sa_data = *vector->sa_data;/* Update SPI for every new SA */ sa_data.ipsec_xform.spi += i; sa_data.ipsec_xform.direction =
@@ -2371,13 +2369,11 @@ test_inline_ip_reassembly(const void *testdata) reassembly_td.nb_frags = td->nb_frags; reassembly_td.burst = td->burst; -memcpy (&full_pkt, td->full_pkt, -sizeof (struct ip_reassembly_test_packet )); + full_pkt = *td->full_pkt; reassembly_td.full_pkt = &full_pkt;for (; i < reassembly_td.nb_frags; i++) { -memcpy (&frags[i], td->frags[i], -sizeof (struct ip_reassembly_test_packet )); + frags[i] = *td->frags[i]; reassembly_td.frags[i] = &frags[i];/* Add extra data for multi-seg test on all fragments except last one */
@@ -2466,8 +2462,7 @@ test_ipsec_inline_proto_rx_inj_inb(const void *test_data) out_td.sa_data = td->sa_data; out_td.burst = td->burst; -memcpy (&full_pkt, td->full_pkt, -sizeof (struct ip_reassembly_test_packet )); + full_pkt = *td->full_pkt; out_td.full_pkt = &full_pkt;/* Add extra data for multi-seg test */
Signature · 1 line
2.47.2
PATCH 32/32 test/cryptodev: replace memcpy with structure assignment
In reply to Stephen HemmingerPrefer structure assignment over memcpy.
Found by cocci/struct_assign.cocci
--- app/test/test_cryptodev.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
app/test/test_cryptodev.c +1 -2
@@ -14837,8 +14837,7 @@ test_multi_session_random_usage(void)for (i =0 ; i <MB_SESSION_NUMBER ; i++) { -rte_memcpy (&ut_paramz[i].ut_params, &unittest_params, -sizeof (struct crypto_unittest_params )); + ut_paramz[i].ut_params = unittest_params; test_AES_CBC_HMAC_SHA512_decrypt_create_session_params( &ut_paramz[i].ut_params,
Signature · 1 line
2.47.2
08/02/2025 21:21, Stephen Hemminger:
Quoted 33 lines
This patch series reduces use of memcpy and
rte_memcpyin DPDK. It changes memcpy to a simple assignment operator which easier to read, generates the same code, and keeps type safety.Historically memcpy was used in textbooks because there was no structure assignement in original K&R C.
Stephen Hemminger (32):
devtools/cocci: prefer structure assignment over memcpy app/testpmd: replace memcpy with assignment app/graph: replace memcpy with structure assignmentcrypto/dpaa_sec: replace memcpy with assignment dma/dpaa2: replace memcpy with assignment
eventdev: replace memcpy with assignment event/dpaa2: replace memcpy with structure assignment event/dsw: replace memcpy with assignment ml/cnxk: replace memcpy with assignment
examples: replace memcpy with assignment
node: replace memcpy with assignment
pipeline: replace memcpy with assignment
sched: replace memcpy with structure assignment
table: replace memcpy with structure assignment net/ntnic: replace memcpy with structure assignment net/bnxt: replace memcpy with structure assignmentcrypto/qat: replace memcpy with structure assignment mempool/cnxk: replace memcpy with structure assignment net/dpaa2: replace memcpy with assignment net/enic: replace memcpy with assignmentnet/intel/i40e: replace memcpy with structure assignment net/nfp: replace memcpy with assignment net/txgbe: replace memcpy with assignment net/bnx2x: replace memcpy with structure assignment
Quoted 8 lines
net/dpaa2: replace memcpy with structure assignment net/bonding: replace memcpy with structure assignment net/cnxk: replace memcpy with structure assignment net/enic: replace memcpy with structure assignment net/iavf: replace memcpy with structure assignment net/ice: replace memcpy with structure assignment
test: replace memcpy with structure assignment test/cryptodev: replace memcpy with structure assignment
Applied and squashed, thanks.
I tried to run the cocci script on my laptop but it took forever, so I hope there is no more occurrences remaining.
PATCH 1/1 more replace memcpy with structure assignment
Prefer using simple structure assignment instead of memcpy. Using a structure assignment preserves type information and compiler checks types already.
---
Reran cocci script against -rc1 and did minor replacement of "*&"
drivers/common/sfc_efx/base/efx_mae.c | 2 +- drivers/net/zxdh/zxdh_ethdev_ops.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-)
drivers/common/sfc_efx/base/efx_mae.c +1 -1
@@ -1353,7 +1353,7 @@ efx_mae_match_spec_clone( goto fail1; } -memcpy (clone, orig,sizeof (efx_mae_match_spec_t)); + *clone = *orig; *clonep = clone;
drivers/net/zxdh/zxdh_ethdev_ops.c +4 -4
@@ -444,7 +444,7 @@ zxdh_dev_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *addr) }else {struct zxdh_mac_filter *mac_filter = &msg_info.data.mac_filter_msg; mac_filter->filter_flag =ZXDH_MAC_UNFILTER ; -memcpy (&mac_filter->mac, addr,sizeof (struct rte_ether_addr )); + mac_filter->mac = *addr;zxdh_msg_head_build (hw,ZXDH_MAC_ADD , &msg_info); ret =zxdh_vf_send_msg_to_pf (dev, &msg_info,sizeof (msg_info),NULL ,0 );if (ret) {
@@ -460,7 +460,7 @@ zxdh_dev_mac_addr_set(struct rte_eth_dev *dev, struct rte_ether_addr *addr) mac_filter->filter_flag =ZXDH_MAC_UNFILTER ; mac_filter->mac_flag = true; -memcpy (&mac_filter->mac, old_addr,sizeof (struct rte_ether_addr )); + mac_filter->mac = *old_addr;zxdh_msg_head_build (hw,ZXDH_MAC_DEL , &msg_info); ret =zxdh_vf_send_msg_to_pf (dev, &msg_info,sizeof (msg_info),NULL ,0 );if (ret) {
@@ -532,7 +532,7 @@ zxdh_dev_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,struct zxdh_mac_filter *mac_filter = &msg_info.data.mac_filter_msg; mac_filter->filter_flag =ZXDH_MAC_FILTER ; -memcpy (&mac_filter->mac, mac_addr,sizeof (struct rte_ether_addr )); + mac_filter->mac = *mac_addr;zxdh_msg_head_build (hw,ZXDH_MAC_ADD , &msg_info);if (rte_is_unicast_ether_addr (mac_addr)) {if (hw->uc_num <ZXDH_MAX_UC_MAC_ADDRS ) {
@@ -614,7 +614,7 @@ void zxdh_dev_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)struct zxdh_mac_filter *mac_filter = &msg_info.data.mac_filter_msg; mac_filter->filter_flag =ZXDH_MAC_FILTER ; -memcpy (&mac_filter->mac, mac_addr,sizeof (struct rte_ether_addr )); + mac_filter->mac = *mac_addr;zxdh_msg_head_build (hw,ZXDH_MAC_DEL , &msg_info);if (rte_is_unicast_ether_addr (mac_addr)) {if (hw->uc_num <=ZXDH_MAX_UC_MAC_ADDRS ) {
Signature · 1 line
2.47.2
Thomas Monjalon
AppliedRe: [PATCH] more replace memcpy with structure assignment
12/06/2025 05:08, Stephen Hemminger:
Quoted 5 lines
Prefer using simple structure assignment instead of memcpy. Using a structure assignment preserves type information and compiler checks types already.
Signed-off-by Stephen Hemminger <[email protected]>
Applied, thanks.