netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Daney <ddaney.cavm@gmail.com>
To: linux-mips@linux-mips.org, ralf@linux-mips.org,
	"David S. Miller" <davem@davemloft.net>,
	netdev@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, David Daney <david.daney@cavium.com>
Subject: [PATCH 6/8] netdev: octeon_mgmt: Cleanup and modernize MAC address handling.
Date: Tue, 21 Aug 2012 11:45:10 -0700	[thread overview]
Message-ID: <1345574712-21444-7-git-send-email-ddaney.cavm@gmail.com> (raw)
In-Reply-To: <1345574712-21444-1-git-send-email-ddaney.cavm@gmail.com>

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

  parent reply	other threads:[~2012-08-21 18:45 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-21 18:45 [PATCH 0/8] netdev/MIPS: Improvements to octeon_mgmt Ethernet driver David Daney
2012-08-21 18:45 ` [PATCH 1/8] MIPS: Octeon: Add octeon_io_clk_delay() function David Daney
2012-08-21 18:45 ` [PATCH 2/8] netdev: octeon_mgmt: Add support for 1Gig ports David Daney
2012-08-21 18:45 ` [PATCH 3/8] netdev: octeon_mgmt: Add hardware timestamp support David Daney
2012-08-21 18:45 ` [PATCH 4/8] netdev: octeon_mgmt: Improve ethtool_ops David Daney
2012-08-21 18:45 ` [PATCH 5/8] netdev: octeon_mgmt: Set the parent device David Daney
2012-08-21 18:45 ` David Daney [this message]
2012-08-21 18:45 ` [PATCH 7/8] netdev: octeon_mgmt: Remove some useless 'inline' David Daney
2012-08-21 18:45 ` [PATCH 8/8] netdev: octeon_mgmt: Make multi-line comment style consistent David Daney
2012-08-23  2:16 ` [PATCH 0/8] netdev/MIPS: Improvements to octeon_mgmt Ethernet driver David Miller
2012-08-23  6:35   ` John Crispin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1345574712-21444-7-git-send-email-ddaney.cavm@gmail.com \
    --to=ddaney.cavm@gmail.com \
    --cc=davem@davemloft.net \
    --cc=david.daney@cavium.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@linux-mips.org \
    --cc=netdev@vger.kernel.org \
    --cc=ralf@linux-mips.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).