mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Danny Kukawka <danny.kukawka@bisect.de>
To: "David S. Miller" <davem@davemloft.net>
Cc: Danny Kukawka <dkukawka@suse.de>,
	Alexey Dobriyan <adobriyan@gmail.com>,
	Paul Gortmaker <paul.gortmaker@windriver.com>,
	Richard Cochran <richard.cochran@omicron.at>,
	Jiri Kosina <jkosina@suse.cz>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 08/10] ethoc: set addr_assign_type if random_ether_addr() used
Date: Fri, 17 Feb 2012 16:43:29 +0100	[thread overview]
Message-ID: <1329493411-25750-9-git-send-email-danny.kukawka@bisect.de> (raw)
In-Reply-To: <1329493411-25750-1-git-send-email-danny.kukawka@bisect.de>

Set addr_assign_type correctly to NET_ADDR_RANDOM in case
a random MAC address was generated and assigned to the netdevice.

Fixed ethoc_set_mac_address() to check if the given mac
address is valid and set also dev_addr of the net_device.
Check also the return value of ethoc_set_mac_address() in
ethoc_probe().

Reset the state to NET_ADDR_PERM as soon as the MAC get
changed via .ndo_set_mac_address.

v2: set net_device->dev_addr in ethoc_set_mac_address(),
    check if given address is valid

Signed-off-by: Danny Kukawka <danny.kukawka@bisect.de>
---
 drivers/net/ethernet/ethoc.c |   20 ++++++++++++++++++--
 1 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/ethoc.c b/drivers/net/ethernet/ethoc.c
index 60f0e78..cfc0ce0 100644
--- a/drivers/net/ethernet/ethoc.c
+++ b/drivers/net/ethernet/ethoc.c
@@ -776,10 +776,16 @@ static int ethoc_set_mac_address(struct net_device *dev, void *addr)
 	struct ethoc *priv = netdev_priv(dev);
 	u8 *mac = (u8 *)addr;
 
+	if(!is_valid_ether_addr(mac))
+		return -EADDRNOTAVAIL;
+        
 	ethoc_write(priv, MAC_ADDR0, (mac[2] << 24) | (mac[3] << 16) |
 				     (mac[4] <<  8) | (mac[5] <<  0));
 	ethoc_write(priv, MAC_ADDR1, (mac[0] <<  8) | (mac[1] <<  0));
 
+	memcpy(dev->dev_addr, mac, ETH_ALEN);
+	dev->addr_assign_type &= ~NET_ADDR_RANDOM;
+
 	return 0;
 }
 
@@ -909,6 +915,7 @@ static int __devinit ethoc_probe(struct platform_device *pdev)
 	unsigned int phy;
 	int num_bd;
 	int ret = 0;
+	bool random_mac = false;
 
 	/* allocate networking device */
 	netdev = alloc_etherdev(sizeof(struct ethoc));
@@ -1050,10 +1057,19 @@ static int __devinit ethoc_probe(struct platform_device *pdev)
 
 	/* Check the MAC again for validity, if it still isn't choose and
 	 * program a random one. */
-	if (!is_valid_ether_addr(netdev->dev_addr))
+	if (!is_valid_ether_addr(netdev->dev_addr)) {
 		random_ether_addr(netdev->dev_addr);
+		random_mac = true;
+	}
 
-	ethoc_set_mac_address(netdev, netdev->dev_addr);
+	ret = ethoc_set_mac_address(netdev, netdev->dev_addr);
+	if (ret) {
+		dev_err(&netdev->dev, "failed to set MAC address\n");
+		goto error;
+	}
+	
+	if (random_mac)
+		netdev->addr_assign_type |= NET_ADDR_RANDOM;
 
 	/* register MII bus */
 	priv->mdio = mdiobus_alloc();
-- 
1.7.8.3


  parent reply	other threads:[~2012-02-17 15:43 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-17 15:43 [PATCH v2 00/10] Part 4: handle addr_assign_type for random addresses Danny Kukawka
2012-02-17 15:43 ` [PATCH v2 01/10] au1000_eth: use eth_hw_addr_random() instead of random_ether_addr() Danny Kukawka
2012-02-17 20:59   ` David Miller
2012-02-17 15:43 ` [PATCH 02/10] lantiq_etop: set addr_assign_type if random_ether_addr() used Danny Kukawka
2012-02-17 21:00   ` David Miller
2012-02-17 21:24     ` Danny Kukawka
2012-02-17 15:43 ` [PATCH v2 03/10] davinci_emac: use eth_hw_addr_random() instead of random_ether_addr() Danny Kukawka
2012-02-17 21:00   ` David Miller
2012-02-17 15:43 ` [PATCH v2 04/10] xilinx ll_temac: " Danny Kukawka
2012-02-17 21:00   ` David Miller
2012-02-17 15:43 ` [PATCH v2 05/10] igbvf: reset netdevice addr_assign_type if changed Danny Kukawka
2012-02-17 21:01   ` David Miller
2012-02-17 15:43 ` [PATCH v2 06/10] batman-adv: use eth_hw_addr_random() instead of random_ether_addr() Danny Kukawka
2012-02-17 21:01   ` David Miller
2012-02-17 15:43 ` [PATCH v2 07/10] cisco/enic: " Danny Kukawka
2012-02-17 21:01   ` David Miller
2012-02-17 21:35     ` Danny Kukawka
2012-02-17 15:43 ` Danny Kukawka [this message]
2012-02-17 21:02   ` [PATCH v2 08/10] ethoc: set addr_assign_type if random_ether_addr() used David Miller
2012-02-17 15:43 ` [PATCH v2 09/10] atheros eth: " Danny Kukawka
2012-02-17 21:02   ` David Miller
2012-02-17 15:43 ` [PATCH 10/10] UML net: " Danny Kukawka
2012-02-17 15:55   ` Richard Weinberger
2012-02-17 20:17     ` David Miller
2012-02-17 21:05   ` David Miller

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=1329493411-25750-9-git-send-email-danny.kukawka@bisect.de \
    --to=danny.kukawka@bisect.de \
    --cc=adobriyan@gmail.com \
    --cc=davem@davemloft.net \
    --cc=dkukawka@suse.de \
    --cc=jkosina@suse.cz \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=paul.gortmaker@windriver.com \
    --cc=richard.cochran@omicron.at \
    /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

all inboxes | Powered by JetHome®