[v4,03/30] ethdev: replace uses of rte_memcpy

Message ID 20240405165518.367503-4-stephen@networkplumber.org (mailing list archive)
State Superseded
Delegated to: Thomas Monjalon
Headers
Series replace use of rte_memcpy with fixed sizes |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger April 5, 2024, 4:53 p.m. UTC
  Replace use of rte_memcpy in ethdev. Most of these were
fixed size, and the others were not in the fast path.
Where possible replace memcpy() with structure assignment
which has same effect is type safe.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>

ethdev: struct assign
---
 lib/ethdev/rte_ethdev.c |  12 ++---
 lib/ethdev/rte_flow.c   | 101 +++++++++++++++++++---------------------
 2 files changed, 53 insertions(+), 60 deletions(-)
  

Patch

diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index f1c658f49e..27d2416466 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -15,7 +15,6 @@ 
 #include <rte_log.h>
 #include <rte_interrupts.h>
 #include <rte_kvargs.h>
-#include <rte_memcpy.h>
 #include <rte_common.h>
 #include <rte_mempool.h>
 #include <rte_malloc.h>
@@ -618,7 +617,7 @@  rte_eth_dev_owner_get(const uint16_t port_id, struct rte_eth_dev_owner *owner)
 	rte_spinlock_lock(rte_mcfg_ethdev_get_lock());
 
 	if (eth_dev_shared_data_prepare() != NULL) {
-		rte_memcpy(owner, &ethdev->data->owner, sizeof(*owner));
+		*owner = ethdev->data->owner;
 		ret = 0;
 	} else {
 		ret = -ENOMEM;
@@ -1316,15 +1315,14 @@  rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 	dev->data->dev_configured = 0;
 
 	 /* Store original config, as rollback required on failure */
-	memcpy(&orig_conf, &dev->data->dev_conf, sizeof(dev->data->dev_conf));
+	orig_conf = dev->data->dev_conf;
 
 	/*
 	 * Copy the dev_conf parameter into the dev structure.
 	 * rte_eth_dev_info_get() requires dev_conf, copy it before dev_info get
 	 */
 	if (dev_conf != &dev->data->dev_conf)
-		memcpy(&dev->data->dev_conf, dev_conf,
-		       sizeof(dev->data->dev_conf));
+		dev->data->dev_conf = *dev_conf;
 
 	/* Backup mtu for rollback */
 	old_mtu = dev->data->mtu;
@@ -1601,7 +1599,7 @@  rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
 	eth_dev_rx_queue_config(dev, 0);
 	eth_dev_tx_queue_config(dev, 0);
 rollback:
-	memcpy(&dev->data->dev_conf, &orig_conf, sizeof(dev->data->dev_conf));
+	dev->data->dev_conf = orig_conf;
 	if (old_mtu != dev->data->mtu)
 		dev->data->mtu = old_mtu;
 
@@ -3843,7 +3841,7 @@  rte_eth_dev_conf_get(uint16_t port_id, struct rte_eth_conf *dev_conf)
 		return -EINVAL;
 	}
 
-	memcpy(dev_conf, &dev->data->dev_conf, sizeof(struct rte_eth_conf));
+	*dev_conf = dev->data->dev_conf;
 
 	rte_ethdev_trace_conf_get(port_id, dev_conf);
 
diff --git a/lib/ethdev/rte_flow.c b/lib/ethdev/rte_flow.c
index 7ab1100ea0..776352b984 100644
--- a/lib/ethdev/rte_flow.c
+++ b/lib/ethdev/rte_flow.c
@@ -62,7 +62,8 @@  rte_flow_conv_copy(void *buf, const void *data, const size_t size,
 	size_t sz = rte_type ? desc[type].size : sizeof(void *);
 	if (buf == NULL || data == NULL)
 		return 0;
-	rte_memcpy(buf, data, (size > sz ? sz : size));
+
+	memcpy(buf, data, (size > sz ? sz : size));
 	if (rte_type && desc[type].desc_fn)
 		sz += desc[type].desc_fn(size > 0 ? buf : NULL, data);
 	return sz;
@@ -73,11 +74,10 @@  rte_flow_item_flex_conv(void *buf, const void *data)
 {
 	struct rte_flow_item_flex *dst = buf;
 	const struct rte_flow_item_flex *src = data;
-	if (buf) {
-		dst->pattern = rte_memcpy
-			((void *)((uintptr_t)(dst + 1)), src->pattern,
-			 src->length);
-	}
+
+	if (buf)
+		dst->pattern = memcpy((void *)((uintptr_t)(dst + 1)),
+				      src->pattern, src->length);
 	return src->length;
 }
 
@@ -643,16 +643,18 @@  rte_flow_conv_item_spec(void *buf, const size_t size,
 		mask.raw = item->mask ? item->mask : &rte_flow_item_raw_mask;
 		src.raw = data;
 		dst.raw = buf;
-		rte_memcpy(dst.raw,
-			   (&(struct rte_flow_item_raw){
-				.relative = src.raw->relative,
-				.search = src.raw->search,
-				.reserved = src.raw->reserved,
-				.offset = src.raw->offset,
-				.limit = src.raw->limit,
-				.length = src.raw->length,
-			   }),
-			   size > sizeof(*dst.raw) ? sizeof(*dst.raw) : size);
+
+		memcpy(dst.raw,
+		       (&(struct rte_flow_item_raw){
+			       .relative = src.raw->relative,
+			       .search = src.raw->search,
+			       .reserved = src.raw->reserved,
+			       .offset = src.raw->offset,
+			       .limit = src.raw->limit,
+			       .length = src.raw->length,
+		       }),
+		       size > sizeof(*dst.raw) ? sizeof(*dst.raw) : size);
+
 		off = sizeof(*dst.raw);
 		if (type == RTE_FLOW_CONV_ITEM_SPEC ||
 		    (type == RTE_FLOW_CONV_ITEM_MASK &&
@@ -664,9 +666,8 @@  rte_flow_conv_item_spec(void *buf, const size_t size,
 		if (tmp) {
 			off = RTE_ALIGN_CEIL(off, sizeof(*dst.raw->pattern));
 			if (size >= off + tmp)
-				dst.raw->pattern = rte_memcpy
-					((void *)((uintptr_t)dst.raw + off),
-					 src.raw->pattern, tmp);
+				dst.raw->pattern = memcpy((void *)((uintptr_t)dst.raw + off),
+							  src.raw->pattern, tmp);
 			off += tmp;
 		}
 		break;
@@ -716,32 +717,31 @@  rte_flow_conv_action_conf(void *buf, const size_t size,
 	case RTE_FLOW_ACTION_TYPE_RSS:
 		src.rss = action->conf;
 		dst.rss = buf;
-		rte_memcpy(dst.rss,
-			   (&(struct rte_flow_action_rss){
-				.func = src.rss->func,
-				.level = src.rss->level,
-				.types = src.rss->types,
-				.key_len = src.rss->key_len,
-				.queue_num = src.rss->queue_num,
-			   }),
-			   size > sizeof(*dst.rss) ? sizeof(*dst.rss) : size);
+		memcpy(dst.rss,
+		       (&(struct rte_flow_action_rss){
+			       .func = src.rss->func,
+			       .level = src.rss->level,
+			       .types = src.rss->types,
+			       .key_len = src.rss->key_len,
+			       .queue_num = src.rss->queue_num,
+		       }),
+		       size > sizeof(*dst.rss) ? sizeof(*dst.rss) : size);
+
 		off = sizeof(*dst.rss);
 		if (src.rss->key_len && src.rss->key) {
 			off = RTE_ALIGN_CEIL(off, sizeof(*dst.rss->key));
 			tmp = sizeof(*src.rss->key) * src.rss->key_len;
 			if (size >= (uint64_t)off + (uint64_t)tmp)
-				dst.rss->key = rte_memcpy
-					((void *)((uintptr_t)dst.rss + off),
-					 src.rss->key, tmp);
+				dst.rss->key = memcpy((void *)((uintptr_t)dst.rss + off),
+						      src.rss->key, tmp);
 			off += tmp;
 		}
 		if (src.rss->queue_num) {
 			off = RTE_ALIGN_CEIL(off, sizeof(*dst.rss->queue));
 			tmp = sizeof(*src.rss->queue) * src.rss->queue_num;
 			if (size >= (uint64_t)off + (uint64_t)tmp)
-				dst.rss->queue = rte_memcpy
-					((void *)((uintptr_t)dst.rss + off),
-					 src.rss->queue, tmp);
+				dst.rss->queue = memcpy((void *)((uintptr_t)dst.rss + off),
+							src.rss->queue, tmp);
 			off += tmp;
 		}
 		break;
@@ -983,20 +983,15 @@  rte_flow_conv_rule(struct rte_flow_conv_rule *dst,
 	size_t off;
 	int ret;
 
-	rte_memcpy(dst,
-		   (&(struct rte_flow_conv_rule){
-			.attr = NULL,
-			.pattern = NULL,
-			.actions = NULL,
-		   }),
-		   size > sizeof(*dst) ? sizeof(*dst) : size);
+	memcpy(dst, &(struct rte_flow_conv_rule) { },
+	       size > sizeof(*dst) ? sizeof(*dst) : size);
+
 	off = sizeof(*dst);
 	if (src->attr_ro) {
 		off = RTE_ALIGN_CEIL(off, sizeof(double));
 		if (size && size >= off + sizeof(*dst->attr))
-			dst->attr = rte_memcpy
-				((void *)((uintptr_t)dst + off),
-				 src->attr_ro, sizeof(*dst->attr));
+			dst->attr = memcpy((void *)((uintptr_t)dst + off),
+					   src->attr_ro, sizeof(*dst->attr));
 		off += sizeof(*dst->attr);
 	}
 	if (src->pattern_ro) {
@@ -1098,7 +1093,7 @@  rte_flow_conv(enum rte_flow_conv_op op,
 		attr = src;
 		if (size > sizeof(*attr))
 			size = sizeof(*attr);
-		rte_memcpy(dst, attr, size);
+		memcpy(dst, attr, size);
 		ret = sizeof(*attr);
 		break;
 	case RTE_FLOW_CONV_OP_ITEM:
@@ -1180,14 +1175,14 @@  rte_flow_copy(struct rte_flow_desc *desc, size_t len,
 	if (ret < 0)
 		return 0;
 	ret += sizeof(*desc) - sizeof(*dst);
-	rte_memcpy(desc,
-		   (&(struct rte_flow_desc){
-			.size = ret,
-			.attr = *attr,
-			.items = dst_size ? dst->pattern : NULL,
-			.actions = dst_size ? dst->actions : NULL,
-		   }),
-		   len > sizeof(*desc) ? sizeof(*desc) : len);
+	memcpy(desc,
+	       (&(struct rte_flow_desc){
+		       .size = ret,
+		       .attr = *attr,
+		       .items = dst_size ? dst->pattern : NULL,
+		       .actions = dst_size ? dst->actions : NULL,
+	       }),
+	       len > sizeof(*desc) ? sizeof(*desc) : len);
 
 	rte_flow_trace_copy(desc, len, attr, items, actions, ret);