diff options
author | Danny Kukawka <danny.kukawka@bisect.de> | 2012-02-17 05:43:29 +0000 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2012-02-17 15:58:06 -0500 |
commit | 939d2254fc259fd5ca0872f96b56f6966d804e24 (patch) | |
tree | 4dd4cb731ce4470f52a5d1a4581e5c1133ee1dbe | |
parent | 28009a6cab764f04d4e7c409c180c77b2ef36ba1 (diff) | |
download | op-kernel-dev-939d2254fc259fd5ca0872f96b56f6966d804e24.zip op-kernel-dev-939d2254fc259fd5ca0872f96b56f6966d804e24.tar.gz |
ethoc: set addr_assign_type if random_ether_addr() used
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>
-rw-r--r-- | 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 0b723ff..a381678 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)); @@ -1049,10 +1056,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; + } + + ret = ethoc_set_mac_address(netdev, netdev->dev_addr); + if (ret) { + dev_err(&netdev->dev, "failed to set MAC address\n"); + goto error; + } - ethoc_set_mac_address(netdev, netdev->dev_addr); + if (random_mac) + netdev->addr_assign_type |= NET_ADDR_RANDOM; /* register MII bus */ priv->mdio = mdiobus_alloc(); |