netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2.1] davinci_emac: fix kernel oops when changing MAC address while interface is down
@ 2009-07-07  6:10 Pablo Bitton
  2009-07-08  2:14 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Pablo Bitton @ 2009-07-07  6:10 UTC (permalink / raw)
  To: davinci-linux-open-source; +Cc: netdev

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




^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2.1] davinci_emac: fix kernel oops when changing MAC address while interface is down
  2009-07-07  6:10 [PATCH v2.1] davinci_emac: fix kernel oops when changing MAC address while interface is down Pablo Bitton
@ 2009-07-08  2:14 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2009-07-08  2:14 UTC (permalink / raw)
  To: pablo.bitton; +Cc: davinci-linux-open-source, netdev

From: Pablo Bitton <pablo.bitton@gmail.com>
Date: Tue, 07 Jul 2009 09:10:26 +0300

> 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]

Applied to net-2.6, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-07-08  2:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-07  6:10 [PATCH v2.1] davinci_emac: fix kernel oops when changing MAC address while interface is down Pablo Bitton
2009-07-08  2:14 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).