From patchwork Thu Oct 30 07:46:33 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pramod Gurav X-Patchwork-Id: 39811 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E20EE202FE for ; Thu, 30 Oct 2014 07:43:09 +0000 (UTC) Received: by mail-lb0-f200.google.com with SMTP id f15sf2600478lbj.3 for ; Thu, 30 Oct 2014 00:43:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=hXj/wk+lvMkAHOQ9ZlIrrhxSg34aIpXQWpCoR5lJOPs=; b=Gl089L6bVv8yLjdf+ZWClOLUF7cJpmpKH9SeuPjzBkHOz37e8+zFKkGF7uikVn/bar /Tm1M9ighTRkWhFTMpu/yysDmxz3ZeZmsNPR1oxDRierv0OhxvadABpIL9Vb8Gstcmof 78MA4hCxIkaUspLRDka5oa+L0I7FQWVnXbGS7YlpD8PWUPiEURxaMvmpIe4dGbFdZnVi I+ZaSt7Iminx2kO9nDJZ00/+4Nc1sR7ldhaMPr681jBC/HwYZlWLUOqH1a0ut8ndcEbb wkWYExyBLgV3uQXhtFKgdVgiD6nVm9wRzQrIwQ7S8oH76yB9oZEsRmAsW7uIFJ2Sc/4A 2FnA== X-Gm-Message-State: ALoCoQlNyQWbaF4R+zenJ0gjodLP8o5ckIowLlFyF6p93iKk49JNPRtfQujkLqmmN41AIlmAc10a X-Received: by 10.180.73.73 with SMTP id j9mr5806469wiv.3.1414654988639; Thu, 30 Oct 2014 00:43:08 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.153.7.70 with SMTP id da6ls21110lad.72.gmail; Thu, 30 Oct 2014 00:43:08 -0700 (PDT) X-Received: by 10.112.125.106 with SMTP id mp10mr17161217lbb.50.1414654988406; Thu, 30 Oct 2014 00:43:08 -0700 (PDT) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id jd2si10694153lbc.91.2014.10.30.00.43.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 30 Oct 2014 00:43:08 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by mail-la0-f43.google.com with SMTP id ge10so3900010lab.2 for ; Thu, 30 Oct 2014 00:43:08 -0700 (PDT) X-Received: by 10.152.6.228 with SMTP id e4mr16796384laa.71.1414654988161; Thu, 30 Oct 2014 00:43:08 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.84.229 with SMTP id c5csp790223lbz; Thu, 30 Oct 2014 00:43:07 -0700 (PDT) X-Received: by 10.70.41.138 with SMTP id f10mr15395506pdl.83.1414654986368; Thu, 30 Oct 2014 00:43:06 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ml10si5870402pab.207.2014.10.30.00.43.05 for ; Thu, 30 Oct 2014 00:43:06 -0700 (PDT) Received-SPF: none (google.com: linux-mmc-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756126AbaJ3HnE (ORCPT + 3 others); Thu, 30 Oct 2014 03:43:04 -0400 Received: from smtp100.ord1c.emailsrvr.com ([108.166.43.100]:43490 "EHLO smtp100.ord1c.emailsrvr.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752564AbaJ3HnD (ORCPT ); Thu, 30 Oct 2014 03:43:03 -0400 Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp13.relay.ord1c.emailsrvr.com (SMTP Server) with ESMTP id D6A9F3801B9; Thu, 30 Oct 2014 03:43:01 -0400 (EDT) X-Virus-Scanned: OK Received: by smtp13.relay.ord1c.emailsrvr.com (Authenticated sender: pramod.gurav-AT-smartplayin.com) with ESMTPSA id 2D41F38017B; Thu, 30 Oct 2014 03:42:59 -0400 (EDT) X-Sender-Id: pramod.gurav@smartplayin.com Received: from SPINITLTDL00278.smartplayin.local ([UNAVAILABLE]. [220.227.185.53]) (using TLSv1.1 with cipher DHE-RSA-AES256-SHA) by 0.0.0.0:465 (trex/5.3.2); Thu, 30 Oct 2014 07:43:01 GMT From: Pramod Gurav To: linux-kernel@vger.kernel.org Cc: Pramod Gurav , Chris Ball , Ulf Hansson , linux-mmc@vger.kernel.org Subject: [PATCH v2] mmc: davinci: Fix and simplify probe failure path Date: Thu, 30 Oct 2014 13:16:33 +0530 Message-Id: <1414655193-16952-1-git-send-email-pramod.gurav@smartplayin.com> X-Mailer: git-send-email 1.7.9.5 Sender: linux-mmc-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: pramod.gurav@smartplayin.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The sequence of resource release in probe failure path in this driver was wrong and needed fixes to cleanly unload the driver. This changes does the same by switching to managed resources and fixes return path to release resource in proper sequence. Cc: Chris Ball Cc: Ulf Hansson Cc: linux-mmc@vger.kernel.org Signed-off-by: Pramod Gurav --- Changes since v1: - Dropped IS_ERR check on devm_ioremap() return. - Fixed sequence on mmc_remove_host in fail as well as in remove function drivers/mmc/host/davinci_mmc.c | 91 +++++++++++++++------------------------- 1 file changed, 33 insertions(+), 58 deletions(-) diff --git a/drivers/mmc/host/davinci_mmc.c b/drivers/mmc/host/davinci_mmc.c index 5d4c5e0..dc49b22 100644 --- a/drivers/mmc/host/davinci_mmc.c +++ b/drivers/mmc/host/davinci_mmc.c @@ -1242,22 +1242,20 @@ static int __init davinci_mmcsd_probe(struct platform_device *pdev) return -ENOENT; } - ret = -ENODEV; r = platform_get_resource(pdev, IORESOURCE_MEM, 0); irq = platform_get_irq(pdev, 0); if (!r || irq == NO_IRQ) - goto out; + return -ENODEV; - ret = -EBUSY; mem_size = resource_size(r); - mem = request_mem_region(r->start, mem_size, pdev->name); + mem = devm_request_mem_region(&pdev->dev, r->start, mem_size, + pdev->name); if (!mem) - goto out; + return -EBUSY; - ret = -ENOMEM; mmc = mmc_alloc_host(sizeof(struct mmc_davinci_host), &pdev->dev); if (!mmc) - goto out; + return -ENOMEM; host = mmc_priv(mmc); host->mmc = mmc; /* Important */ @@ -1275,15 +1273,16 @@ static int __init davinci_mmcsd_probe(struct platform_device *pdev) host->txdma = r->start; host->mem_res = mem; - host->base = ioremap(mem->start, mem_size); - if (!host->base) - goto out; + host->base = devm_ioremap(&pdev->dev, mem->start, mem_size); + if (!host->base) { + ret = -ENOMEM; + goto err_ioremap; + } - ret = -ENXIO; - host->clk = clk_get(&pdev->dev, "MMCSDCLK"); + host->clk = devm_clk_get(&pdev->dev, "MMCSDCLK"); if (IS_ERR(host->clk)) { ret = PTR_ERR(host->clk); - goto out; + goto err_ioremap; } clk_enable(host->clk); host->mmc_input_clk = clk_get_rate(host->clk); @@ -1350,20 +1349,22 @@ static int __init davinci_mmcsd_probe(struct platform_device *pdev) ret = mmc_davinci_cpufreq_register(host); if (ret) { dev_err(&pdev->dev, "failed to register cpufreq\n"); - goto cpu_freq_fail; + goto err_cpu_freq; } ret = mmc_add_host(mmc); if (ret < 0) - goto out; + goto err_mmc_add; - ret = request_irq(irq, mmc_davinci_irq, 0, mmc_hostname(mmc), host); + ret = devm_request_irq(&pdev->dev, irq, mmc_davinci_irq, 0, + mmc_hostname(mmc), host); if (ret) - goto out; + goto err_request_irq; if (host->sdio_irq >= 0) { - ret = request_irq(host->sdio_irq, mmc_davinci_sdio_irq, 0, - mmc_hostname(mmc), host); + ret = devm_request_irq(&pdev->dev, host->sdio_irq, + mmc_davinci_sdio_irq, 0, + mmc_hostname(mmc), host); if (!ret) mmc->caps |= MMC_CAP_SDIO_IRQ; } @@ -1376,27 +1377,15 @@ static int __init davinci_mmcsd_probe(struct platform_device *pdev) return 0; -out: +err_request_irq: + mmc_remove_host(mmc); +err_mmc_add: mmc_davinci_cpufreq_deregister(host); -cpu_freq_fail: - if (host) { - davinci_release_dma_channels(host); - - if (host->clk) { - clk_disable(host->clk); - clk_put(host->clk); - } - - if (host->base) - iounmap(host->base); - } - - if (mmc) - mmc_free_host(mmc); - - if (mem) - release_resource(mem); - +err_cpu_freq: + davinci_release_dma_channels(host); + clk_disable(host->clk); +err_ioremap: + mmc_free_host(mmc); dev_dbg(&pdev->dev, "probe err %d\n", ret); return ret; @@ -1406,25 +1395,11 @@ static int __exit davinci_mmcsd_remove(struct platform_device *pdev) { struct mmc_davinci_host *host = platform_get_drvdata(pdev); - if (host) { - mmc_davinci_cpufreq_deregister(host); - - mmc_remove_host(host->mmc); - free_irq(host->mmc_irq, host); - if (host->mmc->caps & MMC_CAP_SDIO_IRQ) - free_irq(host->sdio_irq, host); - - davinci_release_dma_channels(host); - - clk_disable(host->clk); - clk_put(host->clk); - - iounmap(host->base); - - release_resource(host->mem_res); - - mmc_free_host(host->mmc); - } + mmc_remove_host(host->mmc); + mmc_davinci_cpufreq_deregister(host); + davinci_release_dma_channels(host); + clk_disable(host->clk); + mmc_free_host(host->mmc); return 0; }