From patchwork Mon Feb 23 18:55:18 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Felipe Balbi X-Patchwork-Id: 8458 X-Patchwork-Delegate: me@felipebalbi.com Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n1NIuBJX028025 for ; Mon, 23 Feb 2009 18:56:12 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754793AbZBWSz6 (ORCPT ); Mon, 23 Feb 2009 13:55:58 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1754815AbZBWSz5 (ORCPT ); Mon, 23 Feb 2009 13:55:57 -0500 Received: from ns1.siteground211.com ([209.62.36.12]:42441 "EHLO serv01.siteground211.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754793AbZBWSz5 (ORCPT ); Mon, 23 Feb 2009 13:55:57 -0500 Received: from [91.154.126.168] (port=23095 helo=localhost.localdomain) by serv01.siteground211.com with esmtpa (Exim 4.69) (envelope-from ) id 1Lbfy5-0001at-6g; Mon, 23 Feb 2009 12:55:53 -0600 From: Felipe Balbi To: linux-omap@vger.kernel.org Cc: Steve Sakoman , Anand Gadiyar , Felipe Balbi Subject: [rft/rfc/patch-v2.6.29-rc5+ 06/23] usb: host: ehci: sanitize error path Date: Mon, 23 Feb 2009 20:55:18 +0200 Message-Id: <1235415335-17408-7-git-send-email-me@felipebalbi.com> X-Mailer: git-send-email 1.6.1.3 In-Reply-To: <1235415335-17408-6-git-send-email-me@felipebalbi.com> References: <1235415335-17408-1-git-send-email-me@felipebalbi.com> <1235415335-17408-2-git-send-email-me@felipebalbi.com> <1235415335-17408-3-git-send-email-me@felipebalbi.com> <1235415335-17408-4-git-send-email-me@felipebalbi.com> <1235415335-17408-5-git-send-email-me@felipebalbi.com> <1235415335-17408-6-git-send-email-me@felipebalbi.com> X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - serv01.siteground211.com X-AntiAbuse: Original Domain - vger.kernel.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - felipebalbi.com Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org This patch: - sanitizes error path in ehci_hcd_omap_drv_probe(); - removes two unnecessary debugging messages, we only need debugging in the failing case generally; - fix a memory leak when omap_start_ehc() fails: the recently created hcd was never put in that case; Signed-off-by: Felipe Balbi --- drivers/usb/host/ehci-omap.c | 53 +++++++++++++++++++++++++---------------- 1 files changed, 32 insertions(+), 21 deletions(-) diff --git a/drivers/usb/host/ehci-omap.c b/drivers/usb/host/ehci-omap.c index d994392..db4576d 100644 --- a/drivers/usb/host/ehci-omap.c +++ b/drivers/usb/host/ehci-omap.c @@ -418,21 +418,24 @@ static int ehci_hcd_omap_drv_probe(struct platform_device *pdev) struct usb_hcd *hcd; int irq = platform_get_irq(pdev, 0); - int retval = 0; - - dev_dbg(&pdev->dev, "ehci_hcd_omap_drv_probe()\n"); + int ret = -ENODEV; if (usb_disabled()) - return -ENODEV; + goto err_disabled; hcd = usb_create_hcd(&ehci_omap_hc_driver, &pdev->dev, dev_name(&pdev->dev)); - if (!hcd) - return -ENOMEM; + if (!hcd) { + dev_dbg(&pdev->dev, "failed to create hcd with err %d\n", ret); + ret = -ENOMEM; + goto err_create_hcd; + } - retval = omap_start_ehc(pdev, hcd); - if (retval) - return retval; + ret = omap_start_ehc(pdev, hcd); + if (ret) { + dev_dbg(&pdev->dev, "failed to start ehci\n"); + goto err_start; + } res = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -444,12 +447,12 @@ static int ehci_hcd_omap_drv_probe(struct platform_device *pdev) hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); if (!hcd->regs) { dev_err(&pdev->dev, "ioremap failed\n"); - return -ENOMEM; + ret = -ENOMEM; + goto err_ioremap; } ehci = hcd_to_ehci(hcd); ehci->caps = hcd->regs; - ehci->sbrn = 0x20; ehci->regs = hcd->regs + HC_LENGTH(readl(&ehci->caps->hc_capbase)); @@ -459,16 +462,26 @@ static int ehci_hcd_omap_drv_probe(struct platform_device *pdev) /* SET 1 micro-frame Interrupt interval */ writel(readl(&ehci->regs->command) | (1 << 16), &ehci->regs->command); - retval = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); - if (retval == 0) - return retval; + ret = usb_add_hcd(hcd, irq, IRQF_DISABLED | IRQF_SHARED); + if (ret) { + dev_dbg(&pdev->dev, "failed to add hcd with err %d\n", ret); + goto err_add_hcd; + } - dev_dbg(&pdev->dev, "ERR: add_hcd\n"); - omap_stop_ehc(pdev, hcd); + return 0; + +err_add_hcd: iounmap(hcd->regs); + +err_ioremap: + omap_stop_ehc(pdev, hcd); + +err_start: usb_put_hcd(hcd); - return retval; +err_create_hcd: +err_disabled: + return ret; } /*-------------------------------------------------------------------------*/ @@ -490,12 +503,10 @@ static int ehci_hcd_omap_drv_remove(struct platform_device *pdev) { struct usb_hcd *hcd = platform_get_drvdata(pdev); - dev_dbg(&pdev->dev, "ehci_hcd_omap_drv_remove()\n"); - - iounmap(hcd->regs); usb_remove_hcd(hcd); - usb_put_hcd(hcd); + iounmap(hcd->regs); omap_stop_ehc(pdev, hcd); + usb_put_hcd(hcd); return 0; }