gianfar: Make MAC addr setup endian safe, cleanup
authorClaudiu Manoil <claudiu.manoil@freescale.com>
Tue, 7 Oct 2014 07:44:33 +0000 (10:44 +0300)
committerDavid S. Miller <davem@davemloft.net>
Thu, 9 Oct 2014 05:40:37 +0000 (01:40 -0400)
Fix the 32-bit memory access that is not endian safe,
i.e. not giving the desired byte layout for a LE CPU:
tempval = *((u32 *) (tmpbuf + 4)), where 'char tmpbuf[]'.

Get rid of rendundant local vars (tmpbuf[] and idx) and
forced casts.  Cleanup comments.

Signed-off-by: Claudiu Manoil <claudiu.manoil@freescale.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/freescale/gianfar.c

index 37e060478630bc3f54852e7457bdfeffeb4ec678..961198a2bfa83126e83be6c2f76abb6799a47507 100644 (file)
@@ -3248,22 +3248,21 @@ static void gfar_set_mac_for_addr(struct net_device *dev, int num,
 {
        struct gfar_private *priv = netdev_priv(dev);
        struct gfar __iomem *regs = priv->gfargrp[0].regs;
-       int idx;
-       char tmpbuf[ETH_ALEN];
        u32 tempval;
        u32 __iomem *macptr = &regs->macstnaddr1;
 
        macptr += num*2;
 
-       /* Now copy it into the mac registers backwards, cuz
-        * little endian is silly
+       /* For a station address of 0x12345678ABCD in transmission
+        * order (BE), MACnADDR1 is set to 0xCDAB7856 and
+        * MACnADDR2 is set to 0x34120000.
         */
-       for (idx = 0; idx < ETH_ALEN; idx++)
-               tmpbuf[ETH_ALEN - 1 - idx] = addr[idx];
+       tempval = (addr[5] << 24) | (addr[4] << 16) |
+                 (addr[3] << 8)  |  addr[2];
 
-       gfar_write(macptr, *((u32 *) (tmpbuf)));
+       gfar_write(macptr, tempval);
 
-       tempval = *((u32 *) (tmpbuf + 4));
+       tempval = (addr[1] << 24) | (addr[0] << 16);
 
        gfar_write(macptr+1, tempval);
 }
This page took 0.030916 seconds and 5 git commands to generate.