[PATCH 25/32] net/dpaa2: replace memcpy with structure assignment

Hemant Agrawal hemant.agrawal at oss.nxp.com
Mon Feb 10 11:40:04 CET 2025


Acked-by: Hemant Agrawal <hemant.agrawal at nxp.com>

On 09-02-2025 01:52, Stephen Hemminger wrote:
> Prefer structure assignment over memcpy.
> Found by struct-assign.cocci.
>
> Signed-off-by: Stephen Hemminger <stephen at networkplumber.org>
> ---
>   drivers/net/dpaa2/dpaa2_ethdev.c | 5 ++---
>   drivers/net/dpaa2/dpaa2_flow.c   | 9 +++------
>   2 files changed, 5 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/net/dpaa2/dpaa2_ethdev.c b/drivers/net/dpaa2/dpaa2_ethdev.c
> index a9bce854c3..452d58ae28 100644
> --- a/drivers/net/dpaa2/dpaa2_ethdev.c
> +++ b/drivers/net/dpaa2/dpaa2_ethdev.c
> @@ -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:
> diff --git a/drivers/net/dpaa2/dpaa2_flow.c b/drivers/net/dpaa2/dpaa2_flow.c
> index c94eb51ba5..299c50dcdf 100644
> --- a/drivers/net/dpaa2/dpaa2_flow.c
> +++ b/drivers/net/dpaa2/dpaa2_flow.c
> @@ -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];
>   		}
>   	}
>   


More information about the dev mailing list