From patchwork Tue Jul 7 06:10:26 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pablo Bitton X-Patchwork-Id: 34386 Received: from comal.ext.ti.com (comal.ext.ti.com [198.47.26.152]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n6764Fvt017275 for ; Tue, 7 Jul 2009 06:04:16 GMT Received: from dlep33.itg.ti.com ([157.170.170.112]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id n6762YdL016775; Tue, 7 Jul 2009 01:02:39 -0500 Received: from linux.omap.com (localhost [127.0.0.1]) by dlep33.itg.ti.com (8.13.7/8.13.7) with ESMTP id n6762XeT029237; Tue, 7 Jul 2009 01:02:34 -0500 (CDT) Received: from linux.omap.com (localhost [127.0.0.1]) by linux.omap.com (Postfix) with ESMTP id CC97680627; Tue, 7 Jul 2009 01:02:33 -0500 (CDT) X-Original-To: davinci-linux-open-source@linux.davincidsp.com Delivered-To: davinci-linux-open-source@linux.davincidsp.com Received: from dflp53.itg.ti.com (dflp53.itg.ti.com [128.247.5.6]) by linux.omap.com (Postfix) with ESMTP id 236A080626 for ; Tue, 7 Jul 2009 01:02:33 -0500 (CDT) Received: from medina.ext.ti.com (localhost [127.0.0.1]) by dflp53.itg.ti.com (8.13.8/8.13.8) with ESMTP id n6762WPM003373 for ; Tue, 7 Jul 2009 01:02:32 -0500 (CDT) Received: from mail132-tx2-R.bigfish.com (mail-tx2.bigfish.com [65.55.88.113]) by medina.ext.ti.com (8.13.7/8.13.7) with ESMTP id n6762RKJ026913 for ; Tue, 7 Jul 2009 01:02:32 -0500 Received: from mail132-tx2 (localhost.localdomain [127.0.0.1]) by mail132-tx2-R.bigfish.com (Postfix) with ESMTP id 9E6041B580FE for ; Tue, 7 Jul 2009 06:02:27 +0000 (UTC) X-SpamScore: 3 X-BigFish: vps3(zzzz1202h10adjzz5a6ciz2fh5fh5eh6bh63h) X-Spam-TCS-SCL: 2:0 X-FB-SS: 5,7, X-MS-Exchange-Organization-Antispam-Report: OrigIP: 209.85.220.228; Service: EHS Received: by mail132-tx2 (MessageSwitch) id 1246946546288073_7824; Tue, 7 Jul 2009 06:02:26 +0000 (UCT) Received: from mail-fx0-f228.google.com (mail-fx0-f228.google.com [209.85.220.228]) by mail132-tx2.bigfish.com (Postfix) with ESMTP id E8F071020014 for ; Tue, 7 Jul 2009 06:02:25 +0000 (UTC) Received: by fxm28 with SMTP id 28so997378fxm.40 for ; Mon, 06 Jul 2009 23:02:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:subject:from:to:cc :content-type:date:message-id:mime-version:x-mailer :content-transfer-encoding; bh=hX3VFp16VYslZsYjtJolLPlnSOg/wZyt8ipPFu3YFH4=; b=rzL/C2+dgYxACXqVWWc9Az4uMc6vJe2JXv035oKkDjcV8FfOwhZjtsIPl3DuUy4yhk VRYDNHhK7CX+r0vywMgmCwPc7tLcNfwrq2E0/ubz6ZSnrZf7LC3JeqbbKq5xj4+yotcV LBCsdZaoPUm+t3+osg8dPBIHMoNMu1B0XFhYE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=subject:from:to:cc:content-type:date:message-id:mime-version :x-mailer:content-transfer-encoding; b=oLz6w80CfMyVYwyVXYHT2pnLf52kUFY72ao1l2B1ys3PN98gfTbsy0UbKHpfrJBZLi pIPsOjPl24nO5HbAHPWFwQTy7rx0XqW9HOULXBcmUJnNsIoYICyFdOTHPa7S32zqKsd+ W+kDpfzlnBU4PNR+cf+mqsIBzdIyQrt5QEJm0= Received: by 10.103.181.20 with SMTP id i20mr3067637mup.62.1246946545007; Mon, 06 Jul 2009 23:02:25 -0700 (PDT) Received: from ?33.10.0.2? ([77.125.86.252]) by mx.google.com with ESMTPS id s10sm29549191mue.38.2009.07.06.23.02.24 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 06 Jul 2009 23:02:24 -0700 (PDT) From: Pablo Bitton To: davinci-linux-open-source@linux.davincidsp.com Date: Tue, 07 Jul 2009 09:10:26 +0300 Message-Id: <1246947026.3714.9.camel@desktop-002> Mime-Version: 1.0 X-Mailer: Evolution 2.22.3.1 Cc: netdev@vger.kernel.org Subject: [PATCH v2.1] davinci_emac: fix kernel oops when changing MAC address while interface is down X-BeenThere: davinci-linux-open-source@linux.davincidsp.com X-Mailman-Version: 2.1.4 Precedence: list List-Id: davinci-linux-open-source.linux.davincidsp.com List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: davinci-linux-open-source-bounces@linux.davincidsp.com Errors-To: davinci-linux-open-source-bounces@linux.davincidsp.com 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 Signed-off-by: Chaithrika U S Tested-by: Chaithrika U S [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",