[31/32] test: replace memcpy with structure assignment

Message ID 20250208203142.242284-32-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 struct-assign.cocci.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 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(-)
  

Patch

diff --git a/app/test/test_acl.c b/app/test/test_acl.c
index 503ff08894..43d13b5b0f 100644
--- a/app/test/test_acl.c
+++ b/app/test/test_acl.c
@@ -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;
diff --git a/app/test/test_compressdev.c b/app/test/test_compressdev.c
index 81b8e02006..c217ad6cda 100644
--- a/app/test/test_compressdev.c
+++ b/app/test/test_compressdev.c
@@ -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 = {
diff --git a/app/test/test_security_inline_proto.c b/app/test/test_security_inline_proto.c
index 480469f672..04ecfd02c6 100644
--- a/app/test/test_security_inline_proto.c
+++ b/app/test/test_security_inline_proto.c
@@ -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 */