aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net
diff options
context:
space:
mode:
authorDanny Kukawka <danny.kukawka@bisect.de>2012-02-17 00:43:29 -0500
committerDavid S. Miller <davem@davemloft.net>2012-02-17 15:58:06 -0500
commit939d2254fc259fd5ca0872f96b56f6966d804e24 (patch)
tree4dd4cb731ce4470f52a5d1a4581e5c1133ee1dbe /drivers/net
parent28009a6cab764f04d4e7c409c180c77b2ef36ba1 (diff)
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>
Diffstat (limited to 'drivers/net')
-rw-r--r--drivers/net/ethernet/ethoc.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/drivers/net/ethernet/ethoc.c b/drivers/net/ethernet/ethoc.c
index 0b723ff2294b..a38167810546 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)
776 struct ethoc *priv = netdev_priv(dev); 776 struct ethoc *priv = netdev_priv(dev);
777 u8 *mac = (u8 *)addr; 777 u8 *mac = (u8 *)addr;
778 778
779 if (!is_valid_ether_addr(mac))
780 return -EADDRNOTAVAIL;
781
779 ethoc_write(priv, MAC_ADDR0, (mac[2] << 24) | (mac[3] << 16) | 782 ethoc_write(priv, MAC_ADDR0, (mac[2] << 24) | (mac[3] << 16) |
780 (mac[4] << 8) | (mac[5] << 0)); 783 (mac[4] << 8) | (mac[5] << 0));
781 ethoc_write(priv, MAC_ADDR1, (mac[0] << 8) | (mac[1] << 0)); 784 ethoc_write(priv, MAC_ADDR1, (mac[0] << 8) | (mac[1] << 0));
782 785
786 memcpy(dev->dev_addr, mac, ETH_ALEN);
787 dev->addr_assign_type &= ~NET_ADDR_RANDOM;
788
783 return 0; 789 return 0;
784} 790}
785 791
@@ -909,6 +915,7 @@ static int __devinit ethoc_probe(struct platform_device *pdev)
909 unsigned int phy; 915 unsigned int phy;
910 int num_bd; 916 int num_bd;
911 int ret = 0; 917 int ret = 0;
918 bool random_mac = false;
912 919
913 /* allocate networking device */ 920 /* allocate networking device */
914 netdev = alloc_etherdev(sizeof(struct ethoc)); 921 netdev = alloc_etherdev(sizeof(struct ethoc));
@@ -1049,10 +1056,19 @@ static int __devinit ethoc_probe(struct platform_device *pdev)
1049 1056
1050 /* Check the MAC again for validity, if it still isn't choose and 1057 /* Check the MAC again for validity, if it still isn't choose and
1051 * program a random one. */ 1058 * program a random one. */
1052 if (!is_valid_ether_addr(netdev->dev_addr)) 1059 if (!is_valid_ether_addr(netdev->dev_addr)) {
1053 random_ether_addr(netdev->dev_addr); 1060 random_ether_addr(netdev->dev_addr);
1061 random_mac = true;
1062 }
1063
1064 ret = ethoc_set_mac_address(netdev, netdev->dev_addr);
1065 if (ret) {
1066 dev_err(&netdev->dev, "failed to set MAC address\n");
1067 goto error;
1068 }
1054 1069
1055 ethoc_set_mac_address(netdev, netdev->dev_addr); 1070 if (random_mac)
1071 netdev->addr_assign_type |= NET_ADDR_RANDOM;
1056 1072
1057 /* register MII bus */ 1073 /* register MII bus */
1058 priv->mdio = mdiobus_alloc(); 1074 priv->mdio = mdiobus_alloc();