Skip to content

Commit 0d2fad7

Browse files
tlebgregkh
authored andcommitted
net: macb: avoid dealing with endianness in macb_set_hwaddr()
[ Upstream commit 70a5ce8 ] bp->dev->dev_addr is of type `unsigned char *`. Casting it to a u32 pointer and dereferencing implies dealing manually with endianness, which is error-prone. Replace by calls to get_unaligned_le32|le16() helpers. This was found using sparse: ⟩ make C=2 drivers/net/ethernet/cadence/macb_main.o warning: incorrect type in assignment (different base types) expected unsigned int [usertype] bottom got restricted __le32 [usertype] warning: incorrect type in assignment (different base types) expected unsigned short [usertype] top got restricted __le16 [usertype] ... Reviewed-by: Sean Anderson <sean.anderson@linux.dev> Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com> Reviewed-by: Simon Horman <horms@kernel.org> Link: https://patch.msgid.link/20250923-macb-fixes-v6-5-772d655cdeb6@bootlin.com Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent c691d6a commit 0d2fad7

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

drivers/net/ethernet/cadence/macb_main.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,9 @@ static void macb_set_hwaddr(struct macb *bp)
281281
u32 bottom;
282282
u16 top;
283283

284-
bottom = cpu_to_le32(*((u32 *)bp->dev->dev_addr));
284+
bottom = get_unaligned_le32(bp->dev->dev_addr);
285285
macb_or_gem_writel(bp, SA1B, bottom);
286-
top = cpu_to_le16(*((u16 *)(bp->dev->dev_addr + 4)));
286+
top = get_unaligned_le16(bp->dev->dev_addr + 4);
287287
macb_or_gem_writel(bp, SA1T, top);
288288

289289
if (gem_has_ptp(bp)) {

0 commit comments

Comments
 (0)