From patchwork Mon Nov 10 20:17:03 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: lautriv X-Patchwork-Id: 5269041 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 83DE89F3ED for ; Mon, 10 Nov 2014 20:19:47 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 842DA2015A for ; Mon, 10 Nov 2014 20:19:46 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9752620142 for ; Mon, 10 Nov 2014 20:19:45 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XnvOk-0003o4-Ti; Mon, 10 Nov 2014 20:17:14 +0000 Received: from coldplug.net ([109.75.184.172] helo=external.coldplug.net) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1XnvOg-0003ki-VY for linux-arm-kernel@lists.infradead.org; Mon, 10 Nov 2014 20:17:12 +0000 Received: from localhost (localhost [127.0.0.1]) by external.coldplug.net (Postfix) with ESMTP id A74733A540 for ; Mon, 10 Nov 2014 21:16:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=coldplug.net; h= content-type:content-type:in-reply-to:references:subject:subject :to:mime-version:user-agent:from:from:date:date:message-id; s= dkim; t=1415650607; x=1416514607; bh=t4uUC52EUKhr9MWKy98f42yPhFS Pw4WoMGh1K/UL1V0=; b=L7S7HjA58oQq1AaOG0SkFB0SYxYvef36bLMKboKYiBj Yg2bnhZiyZ98jiLFWkXDI3K6MA7NBJrZINMqNZ2IUYBO7108ee3ORIET8762qDvw JSPdHKcdzlhfnuydKznaES4mBSyaba2luC1JMhCn7Nc0v3kWDO1NWnBgc0ANcK/o = X-Virus-Scanned: Debian amavisd-new at MYHOSTNAME Received: from external.coldplug.net ([127.0.0.1]) by localhost (external.coldplug.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 5hLXMYV1B5os for ; Mon, 10 Nov 2014 21:16:47 +0100 (CET) Received: from [10.0.0.248] (f050083102.adsl.alicedsl.de [78.50.83.102]) by external.coldplug.net (Postfix) with ESMTPSA id D0DB13A348; Mon, 10 Nov 2014 21:16:24 +0100 (CET) Message-ID: <54611D3F.2010903@coldplug.net> Date: Mon, 10 Nov 2014 21:17:03 +0100 From: lautriv User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.2.0 MIME-Version: 1.0 To: Alexey Charkov Subject: Re: [PATCH] mmc: wmt-sdmmc: fix unmatched release_mem_region References: <1415567571-6144-1-git-send-email-alchark@gmail.com> <545FE821.5060107@coldplug.net> In-Reply-To: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20141110_121711_357986_D8F1B97A X-CRM114-Status: GOOD ( 21.12 ) X-Spam-Score: -0.4 (/) Cc: Ulf Hansson , "linux-mmc@vger.kernel.org" , Chris Ball , linux-kernel , Tony Prisk , Fabio Estevam , "linux-arm-kernel@lists.infradead.org" X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On 11/10/2014 06:15 AM, Alexey Charkov wrote: > 2014-11-10 1:18 GMT+03:00 lautriv : >> On 11/09/2014 10:55 PM, Fabio Estevam wrote: >>> On Sun, Nov 9, 2014 at 7:12 PM, Alexey Charkov wrote: >>> >>>> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); >>>> + if (!res) { >>>> + ret = -ENODEV; >>>> + goto fail1; >>> You could save this NULL check... >>> >>>> + } >>>> mmc = mmc_alloc_host(sizeof(struct wmt_mci_priv), &pdev->dev); >>>> if (!mmc) { >>>> dev_err(&pdev->dev, "Failed to allocate mmc_host\n"); >>>> @@ -813,7 +819,7 @@ static int wmt_mci_probe(struct platform_device >>>> *pdev) >>>> if (of_get_property(np, "cd-inverted", NULL)) >>>> priv->cd_inverted = 1; >>>> >>>> - priv->sdmmc_base = of_iomap(np, 0); >>> If you move ' res = platform_get_resource' right here as >>> devm_ioremap_resource() already does the NULL check. >>> >>>> + priv->sdmmc_base = devm_ioremap_resource(&pdev->dev, res); >>>> if (!priv->sdmmc_base) { >>>> dev_err(&pdev->dev, "Failed to map IO space\n"); >>>> ret = -ENOMEM; >> This was the original intention but it would fall between the failX jumps, i >> discussed that with Alexey and we decided to change it with the cleanup to >> hold this patch small. > I think Fabio means something slightly different than what we > discussed. We haven't realized that the first thing > devm_ioremap_resource does is exactly that (!res) check, so we can > skip ours altogether. > > Looking at the function code a bit closer, we should also make the > check look like "if (IS_ERR(priv->sdmmc_base)", kill the dev_err call > (as it's also done internally), and then just do "ret = > PTR_ERR(priv->sdmmc_base)" and jump to the label. > > Thanks a lot, > Alexey > Sorry for the delay, 8880's are used to crash a lot since we have not enought information ;) Attached a changed patch which will hopefully meet all needs. From 7c8ebb55fde8786cd16d95659ff73675bedc287c Mon Sep 17 00:00:00 2001 From: Helmut Stengele Date: Mon, 10 Nov 2014 11:26:51 +0100 Subject: [PATCH] mmc: vt8500: change resource-mapping to devm_* Current code calls release_mem_region upon module unload without requesting the region first. This patch fixes it by moving to a devres-based ioremap implementation, which handles requesting and releasing memory region internally. This also makes the error/unload paths a bit simpler. Signed-off-by: Helmut Stengele --- drivers/mmc/host/wmt-sdmmc.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/drivers/mmc/host/wmt-sdmmc.c b/drivers/mmc/host/wmt-sdmmc.c index 54181b4..f874d36 100644 --- a/drivers/mmc/host/wmt-sdmmc.c +++ b/drivers/mmc/host/wmt-sdmmc.c @@ -759,6 +759,7 @@ static int wmt_mci_probe(struct platform_device *pdev) const struct wmt_mci_caps *wmt_caps; int ret; int regular_irq, dma_irq; + struct resource *res; if (!of_id || !of_id->data) { dev_err(&pdev->dev, "Controller capabilities data missing\n"); @@ -813,10 +814,11 @@ static int wmt_mci_probe(struct platform_device *pdev) if (of_get_property(np, "cd-inverted", NULL)) priv->cd_inverted = 1; - priv->sdmmc_base = of_iomap(np, 0); + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + priv->sdmmc_base = devm_ioremap_resource(&pdev->dev, res); if (!priv->sdmmc_base) { dev_err(&pdev->dev, "Failed to map IO space\n"); - ret = -ENOMEM; + ret = PTR_ERR(priv->sdmmc_base); goto fail2; } @@ -826,7 +828,7 @@ static int wmt_mci_probe(struct platform_device *pdev) ret = request_irq(regular_irq, wmt_mci_regular_isr, 0, "sdmmc", priv); if (ret) { dev_err(&pdev->dev, "Register regular IRQ fail\n"); - goto fail3; + goto fail2; } ret = request_irq(dma_irq, wmt_mci_dma_isr, 0, "sdmmc", priv); @@ -869,8 +871,6 @@ fail5: free_irq(dma_irq, priv); fail4: free_irq(regular_irq, priv); -fail3: - iounmap(priv->sdmmc_base); fail2: mmc_free_host(mmc); fail1: @@ -881,7 +881,6 @@ static int wmt_mci_remove(struct platform_device *pdev) { struct mmc_host *mmc; struct wmt_mci_priv *priv; - struct resource *res; u32 reg_tmp; mmc = platform_get_drvdata(pdev); @@ -904,14 +903,9 @@ static int wmt_mci_remove(struct platform_device *pdev) free_irq(priv->irq_regular, priv); free_irq(priv->irq_dma, priv); - iounmap(priv->sdmmc_base); - clk_disable_unprepare(priv->clk_sdmmc); clk_put(priv->clk_sdmmc); - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - release_mem_region(res->start, resource_size(res)); - mmc_free_host(mmc); dev_info(&pdev->dev, "WMT MCI device removed\n"); -- 1.7.10.4