Message ID | 1246947026.3714.9.camel@desktop-002 (mailing list archive) |
---|---|
State | Awaiting Upstream |
Headers | show |
Hi, I've resubmitted this patch since my email client has corrupted the v2 patch, turning TAB characters into spaces. Hopefully, this won't happen again. On Tue, Jul 7, 2009 at 9:10 AM, Pablo Bitton<pablo.bitton@gmail.com> wrote: > 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: Pablo Bitton <pablo.bitton@gmail.com> > Signed-off-by: Chaithrika U S <chaithrika@ti.com> > Tested-by: Chaithrika U S <chaithrika@ti.com> > [tested on DM6467 EVM] > > --- > Â drivers/net/davinci_emac.c | Â 12 ++++++++++-- > Â 1 files changed, 10 insertions(+), 2 deletions(-) > > diff --git a/drivers/net/davinci_emac.c b/drivers/net/davinci_emac.c > index cf689a0..dddb2b9 100644 > --- a/drivers/net/davinci_emac.c > +++ b/drivers/net/davinci_emac.c > @@ -1821,11 +1821,19 @@ static int emac_dev_setmac_addr(struct net_device *ndev, void *addr) > Â Â Â Â struct sockaddr *sa = addr; > Â Â Â Â DECLARE_MAC_BUF(mac); > > + Â Â Â if (!is_valid_ether_addr(sa->sa_data)) > + Â Â Â Â Â Â Â return -EINVAL; > + > Â Â Â Â /* 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(rxch->mac_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)) > Â Â Â Â Â Â Â Â dev_notice(emac_dev, "DaVinci EMAC: emac_dev_setmac_addr %s\n", > -- > 1.5.4.3 > > > >
diff --git a/drivers/net/davinci_emac.c b/drivers/net/davinci_emac.c index cf689a0..dddb2b9 100644 --- a/drivers/net/davinci_emac.c +++ b/drivers/net/davinci_emac.c @@ -1821,11 +1821,19 @@ static int emac_dev_setmac_addr(struct net_device *ndev, void *addr) struct sockaddr *sa = addr; DECLARE_MAC_BUF(mac); + if (!is_valid_ether_addr(sa->sa_data)) + return -EINVAL; + /* 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(rxch->mac_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)) dev_notice(emac_dev, "DaVinci EMAC: emac_dev_setmac_addr %s\n",