net: fec: add fallback to random MAC address
authorLucas Stach <l.stach@pengutronix.de>
Mon, 3 Jun 2013 00:38:39 +0000 (00:38 +0000)
committerDavid S. Miller <davem@davemloft.net>
Wed, 5 Jun 2013 00:00:32 +0000 (17:00 -0700)
If no valid MAC address could be obtained from the hardware,
fall back to a randomly generated one.

Signed-off-by: Pavel Machek <pavel@denx.de>
Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/freescale/fec_main.c

index 85a0603..a667015 100644 (file)
@@ -1038,6 +1038,18 @@ static void fec_get_mac(struct net_device *ndev)
                iap = &tmpaddr[0];
        }
 
+       /*
+        * 5) random mac address
+        */
+       if (!is_valid_ether_addr(iap)) {
+               /* Report it and use a random ethernet address instead */
+               netdev_err(ndev, "Invalid MAC address: %pM\n", iap);
+               eth_hw_addr_random(ndev);
+               netdev_info(ndev, "Using random MAC address: %pM\n",
+                           ndev->dev_addr);
+               return;
+       }
+
        memcpy(ndev->dev_addr, iap, ETH_ALEN);
 
        /* Adjust MAC if using macaddr */