From patchwork Tue Dec 21 07:34:56 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 76266 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 1F9A2B70D6 for ; Tue, 21 Dec 2010 18:35:21 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753580Ab0LUHfO (ORCPT ); Tue, 21 Dec 2010 02:35:14 -0500 Received: from mail-ww0-f42.google.com ([74.125.82.42]:52879 "EHLO mail-ww0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753163Ab0LUHfM (ORCPT ); Tue, 21 Dec 2010 02:35:12 -0500 Received: by wwi17 with SMTP id 17so3657187wwi.1 for ; Mon, 20 Dec 2010 23:35:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:cc:subject :message-id:mime-version:content-type:content-disposition:user-agent; bh=tFUACrDELeaZGnU+zBaEkicYgu0T8BJd8f6FyByEBug=; b=uVoG9oOc4kXNlHZ7stCmjyhQigzOuiPz4DdaDX+67yrIMCC7ymzkrzQnbaeY5MI+o6 bipV8BESV2DJzt3MDPEW8RSFGr6+He5KWojl4wDj2OmRf1QTaALilwgdvo9EdF9gw+lO /5CGw5Zcvz4gv/XtPD6UCYJ25FZ9XBNwdfp+c= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:cc:subject:message-id:mime-version:content-type :content-disposition:user-agent; b=Ibe1U6T2/TF4aMw9KYZQDZhIYB68njhHxqxbLlhr6PVS8GKMW2gWujx1WcbDSOPRhp xoz32wCWCmU9NPXpFL3L84BTagPusTbDIgF8wYFdh4wmjHh8hG/QQNSXHIyxAWdid0hd Phj8GpPLxI2qebUAziOeYNMSPLKU7P4WFXSGc= Received: by 10.216.70.83 with SMTP id o61mr5584115wed.92.1292916910863; Mon, 20 Dec 2010 23:35:10 -0800 (PST) Received: from bicker ([41.202.225.145]) by mx.google.com with ESMTPS id r6sm2308454weq.20.2010.12.20.23.35.07 (version=TLSv1/SSLv3 cipher=RC4-MD5); Mon, 20 Dec 2010 23:35:10 -0800 (PST) Date: Tue, 21 Dec 2010 10:34:56 +0300 From: Dan Carpenter To: Giuseppe Cavallaro Cc: netdev@vger.kernel.org, kernel-janitors@vger.kernel.org Subject: [patch -next] stmmac: unwind properly in stmmac_dvr_probe() Message-ID: <20101221073456.GG1936@bicker> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The original code had a several problems: *) It had potential null dereferences of "priv" and "res". *) It released the memory region before it was aquired. *) It didn't free "ndev" after it was allocated. *) It didn't call unregister_netdev() after calling stmmac_probe(). Signed-off-by: Dan Carpenter --- To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/net/stmmac/stmmac_main.c b/drivers/net/stmmac/stmmac_main.c index 20f803d..34a0af3 100644 --- a/drivers/net/stmmac/stmmac_main.c +++ b/drivers/net/stmmac/stmmac_main.c @@ -1647,10 +1647,8 @@ static int stmmac_dvr_probe(struct platform_device *pdev) pr_info("STMMAC driver:\n\tplatform registration... "); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) { - ret = -ENODEV; - goto out; - } + if (!res) + return -ENODEV; pr_info("\tdone!\n"); if (!request_mem_region(res->start, resource_size(res), @@ -1658,22 +1656,21 @@ static int stmmac_dvr_probe(struct platform_device *pdev) pr_err("%s: ERROR: memory allocation failed" "cannot get the I/O addr 0x%x\n", __func__, (unsigned int)res->start); - ret = -EBUSY; - goto out; + return -EBUSY; } addr = ioremap(res->start, resource_size(res)); if (!addr) { pr_err("%s: ERROR: memory mapping failed\n", __func__); ret = -ENOMEM; - goto out; + goto out_release_region; } ndev = alloc_etherdev(sizeof(struct stmmac_priv)); if (!ndev) { pr_err("%s: ERROR: allocating the device\n", __func__); ret = -ENOMEM; - goto out; + goto out_unmap; } SET_NETDEV_DEV(ndev, &pdev->dev); @@ -1683,8 +1680,8 @@ static int stmmac_dvr_probe(struct platform_device *pdev) if (ndev->irq == -ENXIO) { pr_err("%s: ERROR: MAC IRQ configuration " "information not found\n", __func__); - ret = -ENODEV; - goto out; + ret = -ENXIO; + goto out_free_ndev; } priv = netdev_priv(ndev); @@ -1711,18 +1708,18 @@ static int stmmac_dvr_probe(struct platform_device *pdev) if (priv->plat->init) { ret = priv->plat->init(pdev); if (unlikely(ret)) - goto out; + goto out_free_ndev; } /* MAC HW revice detection */ ret = stmmac_mac_device_setup(ndev); if (ret < 0) - goto out; + goto out_plat_exit; /* Network Device Registration */ ret = stmmac_probe(ndev); if (ret < 0) - goto out; + goto out_plat_exit; /* associate a PHY - it is provided by another platform bus */ if (!driver_for_each_device @@ -1730,7 +1727,7 @@ static int stmmac_dvr_probe(struct platform_device *pdev) stmmac_associate_phy)) { pr_err("No PHY device is associated with this MAC!\n"); ret = -ENODEV; - goto out; + goto out_unregister; } pr_info("\t%s - (dev. name: %s - id: %d, IRQ #%d\n" @@ -1741,19 +1738,22 @@ static int stmmac_dvr_probe(struct platform_device *pdev) pr_debug("\tMDIO bus (id: %d)...", priv->plat->bus_id); ret = stmmac_mdio_register(ndev); if (ret < 0) - goto out; + goto out_unregister; pr_debug("registered!\n"); + return 0; -out: - if (ret < 0) { - if (priv->plat->exit) - priv->plat->exit(pdev); - - platform_set_drvdata(pdev, NULL); - release_mem_region(res->start, resource_size(res)); - if (addr != NULL) - iounmap(addr); - } +out_unregister: + unregister_netdev(ndev); +out_plat_exit: + if (priv->plat->exit) + priv->plat->exit(pdev); +out_free_ndev: + free_netdev(ndev); + platform_set_drvdata(pdev, NULL); +out_unmap: + iounmap(addr); +out_release_region: + release_mem_region(res->start, resource_size(res)); return ret; }