more replace memcpy with structure assignment

Message ID 20250612030952.611893-1-stephen@networkplumber.org (mailing list archive)
State Accepted
Delegated to: Thomas Monjalon
Headers
Series more replace memcpy with structure assignment |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-compile-amd64-testing warning Testing issues
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/aws-unit-testing success Unit Testing PASS
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-unit-amd64-testing fail Testing issues
ci/iol-sample-apps-testing success Testing PASS

Commit Message

Stephen Hemminger June 12, 2025, 3:08 a.m. UTC
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(-)
  

Comments

Thomas Monjalon June 29, 2025, 8:13 p.m. UTC | #1
12/06/2025 05:08, Stephen Hemminger:
> 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>

Applied, thanks.
  

Patch

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