From: Stephen Hemminger <stephen@networkplumber.org>
To: dev@dpdk.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>,
Junlong Wang <wang.junlong1@zte.com.cn>,
Lijie Shan <shan.lijie@zte.com.cn>
Subject: [PATCH] more replace memcpy with structure assignment
Date: Wed, 11 Jun 2025 20:08:51 -0700 [thread overview]
Message-ID: <20250612030952.611893-1-stephen@networkplumber.org> (raw)
In-Reply-To: <5311136.0WQXIW03uk@thomas>
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 <stephen@networkplumber.org>
---
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(-)
diff --git a/drivers/common/sfc_efx/base/efx_mae.c b/drivers/common/sfc_efx/base/efx_mae.c
index 1429e7dd0a..4533e5cae6 100644
--- a/drivers/common/sfc_efx/base/efx_mae.c
+++ b/drivers/common/sfc_efx/base/efx_mae.c
@@ -1353,7 +1353,7 @@ efx_mae_match_spec_clone(
goto fail1;
}
- memcpy(clone, orig, sizeof (efx_mae_match_spec_t));
+ *clone = *orig;
*clonep = clone;
diff --git a/drivers/net/zxdh/zxdh_ethdev_ops.c b/drivers/net/zxdh/zxdh_ethdev_ops.c
index f8e8d26c50..268f78900c 100644
--- a/drivers/net/zxdh/zxdh_ethdev_ops.c
+++ b/drivers/net/zxdh/zxdh_ethdev_ops.c
@@ -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) {
--
2.47.2
prev parent reply other threads:[~2025-06-12 3:10 UTC|newest]
Thread overview: 43+ 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-10 10:38 ` Hemant Agrawal
2025-02-08 20:21 ` [PATCH 05/32] dma/dpaa2: " Stephen Hemminger
2025-02-10 10:42 ` Hemant Agrawal
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-10 10:39 ` Hemant Agrawal
2025-02-08 20:22 ` [PATCH 08/32] event/dsw: replace memcpy with assignment Stephen Hemminger
2025-02-12 7:53 ` Mattias Rönnblom
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 ` [PATCH 12/32] pipeline: " Stephen Hemminger
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-10 2:56 ` Somnath Kotur
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-10 10:39 ` Hemant Agrawal
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-10 1:13 ` Chaoyong He
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-10 10:40 ` Hemant Agrawal
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
2025-06-11 23:38 ` [PATCH 00/32] Use structure assignment instead of memcpy Thomas Monjalon
2025-06-12 3:08 ` Stephen Hemminger [this message]
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=20250612030952.611893-1-stephen@networkplumber.org \
--to=stephen@networkplumber.org \
--cc=andrew.rybchenko@oktetlabs.ru \
--cc=dev@dpdk.org \
--cc=shan.lijie@zte.com.cn \
--cc=wang.junlong1@zte.com.cn \
/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).