netdev: octeon_mgmt: Cleanup and modernize MAC address handling.
authorDavid Daney <david.daney@cavium.com>
Tue, 21 Aug 2012 18:45:10 +0000 (11:45 -0700)
committerDavid Daney <david.daney@cavium.com>
Fri, 31 Aug 2012 18:49:54 +0000 (11:49 -0700)
Use eth_mac_addr(), and generate a random address if none is otherwise
assigned.

Signed-off-by: David Daney <david.daney@cavium.com>
Acked-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/octeon/octeon_mgmt.c

index 3bae01f4669b559cf018c223cd7637cc2876b8c1..9b526da79af73584aabc60951e87fda6e5d01eb2 100644 (file)
@@ -648,12 +648,10 @@ static void octeon_mgmt_set_rx_filtering(struct net_device *netdev)
 
 static int octeon_mgmt_set_mac_address(struct net_device *netdev, void *addr)
 {
-       struct sockaddr *sa = addr;
+       int r = eth_mac_addr(netdev, addr);
 
-       if (!is_valid_ether_addr(sa->sa_data))
-               return -EADDRNOTAVAIL;
-
-       memcpy(netdev->dev_addr, sa->sa_data, ETH_ALEN);
+       if (r)
+               return r;
 
        octeon_mgmt_set_rx_filtering(netdev);
 
@@ -1545,8 +1543,12 @@ static int __devinit octeon_mgmt_probe(struct platform_device *pdev)
 
        mac = of_get_mac_address(pdev->dev.of_node);
 
-       if (mac)
-               memcpy(netdev->dev_addr, mac, 6);
+       if (mac && is_valid_ether_addr(mac)) {
+               memcpy(netdev->dev_addr, mac, ETH_ALEN);
+               netdev->addr_assign_type &= ~NET_ADDR_RANDOM;
+       } else {
+               eth_hw_addr_random(netdev);
+       }
 
        p->phy_np = of_parse_phandle(pdev->dev.of_node, "phy-handle", 0);