linux-mips
[Top] [All Lists]

[PATCH 6/8] netdev: octeon_mgmt: Cleanup and modernize MAC address handl

To: linux-mips@linux-mips.org, ralf@linux-mips.org, "David S. Miller" <davem@davemloft.net>, netdev@vger.kernel.org
Subject: [PATCH 6/8] netdev: octeon_mgmt: Cleanup and modernize MAC address handling.
From: David Daney <ddaney.cavm@gmail.com>
Date: Tue, 21 Aug 2012 11:45:10 -0700
Cc: linux-kernel@vger.kernel.org, David Daney <david.daney@cavium.com>
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=PoqVl/kgxfAU4DU1EctKGGN/I7BISYjgH3cT+AGHez0=; b=dTCegMHup+r1S296f5mPggdhTw1RyQlLFb900tCalmdLVYYcWwO7I5W5sNnZ+WJB+W ILpOEiEx58M8mtgabpF7USOE5DOJ55QZc6F/ASO7LdodgIaEMG496qlpdn0KuWHqGMON vNRd73ND4+KNrLtViGMyCPQoULFKyBYW4DlJAM4pN5GA4YGLVjWNPngcTNUN0ltJhpQF ZjbUkO3HTDUYg17Q1B49Ht+EkgNXUTVe2/hLLv2oKnB9ZTspmkxRr/UdRDyP0JqjTBEL bMqIiAKEdha/0tZV1TDSHGn8AEaamzeJEcHhIyaWiULUWOSiNLFvR1Q/qZMePNHM7OzB Xu2Q==
In-reply-to: <1345574712-21444-1-git-send-email-ddaney.cavm@gmail.com>
List-archive: <http://www.linux-mips.org/archives/linux-mips/>
List-help: <mailto:ecartis@linux-mips.org?Subject=help>
List-id: linux-mips <linux-mips.eddie.linux-mips.org>
List-owner: <mailto:ralf@linux-mips.org>
List-post: <mailto:linux-mips@linux-mips.org>
List-software: Ecartis version 1.0.0
List-subscribe: <mailto:ecartis@linux-mips.org?subject=subscribe%20linux-mips>
List-unsubscribe: <mailto:ecartis@linux-mips.org?subject=unsubscribe%20linux-mips>
References: <1345574712-21444-1-git-send-email-ddaney.cavm@gmail.com>
Sender: linux-mips-bounce@linux-mips.org
From: David Daney <david.daney@cavium.com>

Use eth_mac_addr(), and generate a random address if none is otherwise
assigned.

Signed-off-by: David Daney <david.daney@cavium.com>
---
 drivers/net/ethernet/octeon/octeon_mgmt.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/octeon/octeon_mgmt.c 
b/drivers/net/ethernet/octeon/octeon_mgmt.c
index 3bae01f..9b526da 100644
--- a/drivers/net/ethernet/octeon/octeon_mgmt.c
+++ b/drivers/net/ethernet/octeon/octeon_mgmt.c
@@ -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);
 
-- 
1.7.11.4


<Prev in Thread] Current Thread [Next in Thread>