]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: macb: avoid dealing with endianness in macb_set_hwaddr()
authorThéo Lebrun <theo.lebrun@bootlin.com>
Tue, 23 Sep 2025 16:00:27 +0000 (18:00 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 3 Dec 2025 11:45:14 +0000 (12:45 +0100)
[ Upstream commit 70a5ce8bc94545ba0fb47b2498bfb12de2132f4d ]

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>
drivers/net/ethernet/cadence/macb_main.c

index a635c9af26c3edf596d68e38f711cb92029c7b1e..873b0acecd1bfc494b5dc9a7a02870b6da240547 100644 (file)
@@ -277,9 +277,9 @@ static void macb_set_hwaddr(struct macb *bp)
        u32 bottom;
        u16 top;
 
-       bottom = cpu_to_le32(*((u32 *)bp->dev->dev_addr));
+       bottom = get_unaligned_le32(bp->dev->dev_addr);
        macb_or_gem_writel(bp, SA1B, bottom);
-       top = cpu_to_le16(*((u16 *)(bp->dev->dev_addr + 4)));
+       top = get_unaligned_le16(bp->dev->dev_addr + 4);
        macb_or_gem_writel(bp, SA1T, top);
 
        /* Clear unused address register sets */