Skip to content

Commit 3784bcd

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 <[email protected]> Signed-off-by: Théo Lebrun <[email protected]> Reviewed-by: Simon Horman <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent 43ad338 commit 3784bcd

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/net/ethernet/cadence/macb_main.c

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

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

291291
if (gem_has_ptp(bp)) {

0 commit comments

Comments
 (0)