git: 3aeeedc7e0dc - main - qlnxe: Avoid memcpy with same source and destination

From: Zhenlei Huang <zlei_at_FreeBSD.org>
Date: Fri, 06 Feb 2026 17:59:27 UTC
The branch main has been updated by zlei:

URL: https://cgit.FreeBSD.org/src/commit/?id=3aeeedc7e0dc231c16406ff64f4a08a716964c40

commit 3aeeedc7e0dc231c16406ff64f4a08a716964c40
Author:     Zhenlei Huang <zlei@FreeBSD.org>
AuthorDate: 2026-02-06 17:52:53 +0000
Commit:     Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2026-02-06 17:52:53 +0000

    qlnxe: Avoid memcpy with same source and destination
    
    In case the device is VF, qlnx_get_mac_addr() returns ha->primary_mac
    hence it ends up memcpy with same source and destination. Refactor
    slightly to avoid that.
    
    Reviewed by:    kbowling
    MFC after:      5 days
    Differential Revision:  https://reviews.freebsd.org/D54884
---
 sys/dev/qlnx/qlnxe/qlnx_def.h |  1 -
 sys/dev/qlnx/qlnxe/qlnx_os.c  | 13 +++++++------
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/sys/dev/qlnx/qlnxe/qlnx_def.h b/sys/dev/qlnx/qlnxe/qlnx_def.h
index 796845f3f8c6..ed3a0403bb6f 100644
--- a/sys/dev/qlnx/qlnxe/qlnx_def.h
+++ b/sys/dev/qlnx/qlnxe/qlnx_def.h
@@ -683,7 +683,6 @@ extern int qlnx_grc_dump(qlnx_host_t *ha, uint32_t *num_dumped_dwords,
 		int hwfn_index);
 extern int qlnx_idle_chk(qlnx_host_t *ha, uint32_t *num_dumped_dwords,
 		int hwfn_index);
-extern uint8_t *qlnx_get_mac_addr(qlnx_host_t *ha);
 extern void qlnx_fill_link(qlnx_host_t *ha, struct ecore_hwfn *hwfn,
                           struct qlnx_link_output *if_link);
 extern int qlnx_set_lldp_tlvx(qlnx_host_t *ha, qlnx_lldp_sys_tlvs_t *lldp_tlvs);
diff --git a/sys/dev/qlnx/qlnxe/qlnx_os.c b/sys/dev/qlnx/qlnxe/qlnx_os.c
index 9616d9f4d611..1c885133c3ec 100644
--- a/sys/dev/qlnx/qlnxe/qlnx_os.c
+++ b/sys/dev/qlnx/qlnxe/qlnx_os.c
@@ -101,6 +101,7 @@ static void qlnx_stop(qlnx_host_t *ha);
 static int qlnx_send(qlnx_host_t *ha, struct qlnx_fastpath *fp,
 		struct mbuf **m_headp);
 static int qlnx_get_ifq_snd_maxlen(qlnx_host_t *ha);
+static void qlnx_get_mac_addr(qlnx_host_t *ha);
 static uint32_t qlnx_get_optics(qlnx_host_t *ha,
 			struct qlnx_link_output *if_link);
 static int qlnx_transmit(if_t ifp, struct mbuf  *mp);
@@ -2322,7 +2323,7 @@ qlnx_init_ifnet(device_t dev, qlnx_host_t *ha)
 
         ha->max_frame_size = if_getmtu(ifp) + ETHER_HDR_LEN + ETHER_CRC_LEN;
 
-        memcpy(ha->primary_mac, qlnx_get_mac_addr(ha), ETH_ALEN);
+	qlnx_get_mac_addr(ha);
 
 	if (!ha->primary_mac[0] && !ha->primary_mac[1] &&
 		!ha->primary_mac[2] && !ha->primary_mac[3] &&
@@ -3772,7 +3773,7 @@ qlnx_get_ifq_snd_maxlen(qlnx_host_t *ha)
         return(TX_RING_SIZE - 1);
 }
 
-uint8_t *
+static void
 qlnx_get_mac_addr(qlnx_host_t *ha)
 {
 	struct ecore_hwfn	*p_hwfn;
@@ -3781,8 +3782,10 @@ qlnx_get_mac_addr(qlnx_host_t *ha)
 
 	p_hwfn = &ha->cdev.hwfns[0];
 
-	if (qlnx_vf_device(ha) != 0) 
-		return (p_hwfn->hw_info.hw_mac_addr);
+	if (qlnx_vf_device(ha) != 0) {
+		memcpy(ha->primary_mac, p_hwfn->hw_info.hw_mac_addr, ETH_ALEN);
+		return;
+	}
 
 	ecore_vf_read_bulletin(p_hwfn, &p_is_forced);
 	if (ecore_vf_bulletin_get_forced_mac(p_hwfn, mac, &p_is_forced) ==
@@ -3792,8 +3795,6 @@ qlnx_get_mac_addr(qlnx_host_t *ha)
 			p_is_forced, mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
         	memcpy(ha->primary_mac, mac, ETH_ALEN);
 	}
-
-	return (ha->primary_mac);
 }
 
 static uint32_t