[PATCH] net: 8139too: use unaligned helpers when setting MAC address
From: Lucas Poupeau
Date: Mon Aug 24 2026 - 06:39:54 EST
From: Lucas <lucasp.linux@xxxxxxxxx>
rtl8139_set_mac_address() accesses dev->dev_addr by casting it to u32
pointers. Besides potentially performing unaligned accesses, the second
read starts at offset 4 and reads 32 bits even though only two bytes
remain in the Ethernet address.
Use get_unaligned_le32() and get_unaligned_le16() to read the address
with the appropriate width and endianness. This also fixes the Sparse
type warnings caused by passing __le32 values to iowrite32().
Signed-off-by: Lucas Poupeau <lucasp.linux@xxxxxxxxx>
---
drivers/net/ethernet/realtek/8139too.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/net/ethernet/realtek/8139too.c b/drivers/net/ethernet/realtek/8139too.c
index 8241bcf76664..1736599d7244 100644
--- a/drivers/net/ethernet/realtek/8139too.c
+++ b/drivers/net/ethernet/realtek/8139too.c
@@ -112,6 +112,7 @@
#include <linux/gfp.h>
#include <linux/if_vlan.h>
#include <asm/irq.h>
+#include <linux/unaligned.h>
/* Default Message level */
#define RTL8139_DEF_MSG_ENABLE (NETIF_MSG_DRV | \
@@ -2230,8 +2231,8 @@ static int rtl8139_set_mac_address(struct net_device *dev, void *p)
spin_lock_irq(&tp->lock);
RTL_W8_F(Cfg9346, Cfg9346_Unlock);
- RTL_W32_F(MAC0 + 0, cpu_to_le32 (*(u32 *) (dev->dev_addr + 0)));
- RTL_W32_F(MAC0 + 4, cpu_to_le32 (*(u32 *) (dev->dev_addr + 4)));
+ RTL_W32_F(MAC0 + 0, get_unaligned_le32(dev->dev_addr));
+ RTL_W32_F(MAC0 + 4, get_unaligned_le16(dev->dev_addr + 4));
RTL_W8_F(Cfg9346, Cfg9346_Lock);
spin_unlock_irq(&tp->lock);
--
2.55.0