From patchwork Mon Jul 6 10:50:46 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pablo Bitton X-Patchwork-Id: 34224 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 n66AiYGe012906 for ; Mon, 6 Jul 2009 10:44:35 GMT Received: from dlep36.itg.ti.com ([157.170.170.91]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id n66Ah2IZ007692; Mon, 6 Jul 2009 05:43:08 -0500 Received: from linux.omap.com (localhost [127.0.0.1]) by dlep36.itg.ti.com (8.13.8/8.13.8) with ESMTP id n66Ah2tY008742; Mon, 6 Jul 2009 05:43:02 -0500 (CDT) Received: from linux.omap.com (localhost [127.0.0.1]) by linux.omap.com (Postfix) with ESMTP id 2717C80627; Mon, 6 Jul 2009 05:43:02 -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 0A48780626 for ; Mon, 6 Jul 2009 05:43:00 -0500 (CDT) Received: from red.ext.ti.com (localhost [127.0.0.1]) by dflp53.itg.ti.com (8.13.8/8.13.8) with ESMTP id n66AgxX3004532 for ; Mon, 6 Jul 2009 05:42:59 -0500 (CDT) Received: from mail113-tx2-R.bigfish.com (mail-tx2.bigfish.com [65.55.88.113]) by red.ext.ti.com (8.13.7/8.13.7) with ESMTP id n66AgsfR020723 for ; Mon, 6 Jul 2009 05:42:59 -0500 Received: from mail113-tx2 (localhost.localdomain [127.0.0.1]) by mail113-tx2-R.bigfish.com (Postfix) with ESMTP id 6C22229024F for ; Mon, 6 Jul 2009 10:42:54 +0000 (UTC) X-SpamScore: 3 X-BigFish: vps3(zzzz1202h10adjzz5a6ciz2fh6bh5fh5eh62h) X-Spam-TCS-SCL: 1:0 X-FB-SS: 5, X-MS-Exchange-Organization-Antispam-Report: OrigIP: 209.85.218.210; Service: EHS Received: by mail113-tx2 (MessageSwitch) id 124687697378257_5811; Mon, 6 Jul 2009 10:42:53 +0000 (UCT) Received: from mail-bw0-f210.google.com (mail-bw0-f210.google.com [209.85.218.210]) by mail113-tx2.bigfish.com (Postfix) with ESMTP id BBE4E18A004D for ; Mon, 6 Jul 2009 10:42:52 +0000 (UTC) Received: by bwz6 with SMTP id 6so705619bwz.40 for ; Mon, 06 Jul 2009 03:42:51 -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=TaTz/LH8jjnjkDhLh4lWh5O4GTALsxlMzsuEbUjJhPRTNQvSTStxRMVrlTAtUHC7PU oHtIhIwYWtPZ5z7OTmTKBb+bCPAZbwOXAsr6+IwabVvCaKXUcj+lnF1r7fq/fMFrwyWd Joga+VRCQF+hEM0W+nlFKzaQrntGsd91Up9xo= 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=YSPw/EB/IQlZEvRdHUpQrEgS6WqCiqJcTLkDWjq4Apyhs2yeOe2RejvX9125BBNAm+ +IBt+sUHSi+RXzIESe3mVutnjeprdGdHxc+5pSSeA129QMu7pOtCGeo4oCBBijtlyfpQ 9g2fEeNuoCxBv/4r23CAA7L+T0mEAvBcXEBms= Received: by 10.103.177.1 with SMTP id e1mr2510420mup.111.1246876971520; Mon, 06 Jul 2009 03:42:51 -0700 (PDT) Received: from ?33.10.0.2? ([77.125.86.252]) by mx.google.com with ESMTPS id u26sm30625648mug.52.2009.07.06.03.42.50 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 06 Jul 2009 03:42:50 -0700 (PDT) From: Pablo Bitton To: davinci-linux-open-source@linux.davincidsp.com Date: Mon, 06 Jul 2009 13:50:46 +0300 Message-Id: <1246877446.8072.3.camel@desktop-002> Mime-Version: 1.0 X-Mailer: Evolution 2.22.3.1 Cc: netdev@vger.kernel.org Subject: [PATCH v2] 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",