Commit 64c8165b authored by Pablo Bitton's avatar Pablo Bitton Committed by David S. Miller

davinci_emac: fix kernel oops when changing MAC address while interface is down

Check that network interface is running before changing its MAC address.
Otherwise, rxch is accessed when it's NULL - causing a kernel oops.
Moreover, check that the new MAC address is valid.
Signed-off-by: default avatarPablo Bitton <pablo.bitton@gmail.com>
Signed-off-by: default avatarChaithrika U S <chaithrika@ti.com>
Tested-by: default avatarChaithrika U S <chaithrika@ti.com>
[tested on DM6467 EVM]
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 19e588e7
...@@ -1820,11 +1820,19 @@ static int emac_dev_setmac_addr(struct net_device *ndev, void *addr) ...@@ -1820,11 +1820,19 @@ static int emac_dev_setmac_addr(struct net_device *ndev, void *addr)
struct device *emac_dev = &priv->ndev->dev; struct device *emac_dev = &priv->ndev->dev;
struct sockaddr *sa = addr; struct sockaddr *sa = addr;
if (!is_valid_ether_addr(sa->sa_data))
return -EINVAL;
/* Store mac addr in priv and rx channel and set it in EMAC hw */ /* Store mac addr in priv and rx channel and set it in EMAC hw */
memcpy(priv->mac_addr, sa->sa_data, ndev->addr_len); memcpy(priv->mac_addr, sa->sa_data, ndev->addr_len);
memcpy(rxch->mac_addr, sa->sa_data, ndev->addr_len);
memcpy(ndev->dev_addr, sa->sa_data, ndev->addr_len); memcpy(ndev->dev_addr, sa->sa_data, ndev->addr_len);
emac_setmac(priv, EMAC_DEF_RX_CH, rxch->mac_addr);
/* If the interface is down - rxch is NULL. */
/* MAC address is configured only after the interface is enabled. */
if (netif_running(ndev)) {
memcpy(rxch->mac_addr, sa->sa_data, ndev->addr_len);
emac_setmac(priv, EMAC_DEF_RX_CH, rxch->mac_addr);
}
if (netif_msg_drv(priv)) if (netif_msg_drv(priv))
dev_notice(emac_dev, "DaVinci EMAC: emac_dev_setmac_addr %pM\n", dev_notice(emac_dev, "DaVinci EMAC: emac_dev_setmac_addr %pM\n",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment