From patchwork Sat Sep 1 16:33:10 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julia Lawall X-Patchwork-Id: 181147 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from merlin.infradead.org (unknown [IPv6:2001:4978:20e::2]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 903EF2C0094 for ; Sun, 2 Sep 2012 02:35:31 +1000 (EST) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1T7qdm-0002dp-2B; Sat, 01 Sep 2012 16:33:46 +0000 Received: from mail4-relais-sop.national.inria.fr ([192.134.164.105]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1T7qdh-0002cm-Nr for linux-mtd@lists.infradead.org; Sat, 01 Sep 2012 16:33:42 +0000 X-IronPort-AV: E=Sophos;i="4.80,353,1344204000"; d="scan'208";a="154399778" Received: from palace.lip6.fr (HELO localhost.localdomain) ([132.227.105.202]) by mail4-relais-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 01 Sep 2012 18:33:28 +0200 From: Julia Lawall To: David Woodhouse Subject: [PATCH 4/4] drivers/mtd/nand/mpc5121_nfc.c: some devm_ cleanups Date: Sat, 1 Sep 2012 18:33:10 +0200 Message-Id: <1346517191-8794-4-git-send-email-Julia.Lawall@lip6.fr> X-Mailer: git-send-email 1.7.8.6 In-Reply-To: <1346517191-8794-1-git-send-email-Julia.Lawall@lip6.fr> References: <1346517191-8794-1-git-send-email-Julia.Lawall@lip6.fr> X-Spam-Note: CRM114 invocation failed X-Spam-Score: -6.1 (------) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-6.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [192.134.164.105 listed in list.dnswl.org] 0.8 SPF_NEUTRAL SPF: sender does not match SPF record (neutral) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: linux-mtd@lists.infradead.org, kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-mtd-bounces@lists.infradead.org Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org From: Julia Lawall devm free functions should not have to be explicitly used. The only thing left that is useful in the function mpc5121_nfc_free is the call to clk_disable, which is moved to the call sites. This function also incorrectly called iounmap on devm_ioremap allocated data. Use devm_request_and_ioremap in place of devm_request_mem_region and devm_ioremap. Use devm_clk_get. A semantic match that finds the first problem is as follows: (http://coccinelle.lip6.fr/) // @@ @@ ( * devm_kfree(...); | * devm_free_irq(...); | * devm_iounmap(...); | * devm_release_region(...); | * devm_release_mem_region(...); ) // Signed-off-by: Julia Lawall --- drivers/mtd/nand/mpc5121_nfc.c | 35 +++++------------------------------ 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/drivers/mtd/nand/mpc5121_nfc.c b/drivers/mtd/nand/mpc5121_nfc.c index c259c24..45183ba 100644 --- a/drivers/mtd/nand/mpc5121_nfc.c +++ b/drivers/mtd/nand/mpc5121_nfc.c @@ -632,21 +632,6 @@ out: return ret; } -/* Free driver resources */ -static void mpc5121_nfc_free(struct device *dev, struct mtd_info *mtd) -{ - struct nand_chip *chip = mtd->priv; - struct mpc5121_nfc_prv *prv = chip->priv; - - if (prv->clk) { - clk_disable(prv->clk); - clk_put(prv->clk); - } - - if (prv->csreg) - iounmap(prv->csreg); -} - static int __devinit mpc5121_nfc_probe(struct platform_device *op) { struct device_node *rootnode, *dn = op->dev.of_node; @@ -713,12 +698,7 @@ static int __devinit mpc5121_nfc_probe(struct platform_device *op) regs_paddr = res.start; regs_size = resource_size(&res); - if (!devm_request_mem_region(dev, regs_paddr, regs_size, DRV_NAME)) { - dev_err(dev, "Error requesting memory region!\n"); - return -EBUSY; - } - - prv->regs = devm_ioremap(dev, regs_paddr, regs_size); + prv->regs = devm_request_and_ioremap(dev, &res); if (!prv->regs) { dev_err(dev, "Error mapping memory region!\n"); return -ENOMEM; @@ -752,11 +732,10 @@ static int __devinit mpc5121_nfc_probe(struct platform_device *op) of_node_put(rootnode); /* Enable NFC clock */ - prv->clk = clk_get(dev, "nfc_clk"); + prv->clk = devm_clk_get(dev, "nfc_clk"); if (IS_ERR(prv->clk)) { dev_err(dev, "Unable to acquire NFC clock!\n"); - retval = PTR_ERR(prv->clk); - goto error; + return PTR_ERR(prv->clk); } clk_enable(prv->clk); @@ -803,7 +782,6 @@ static int __devinit mpc5121_nfc_probe(struct platform_device *op) /* Detect NAND chips */ if (nand_scan(mtd, be32_to_cpup(chips_no))) { dev_err(dev, "NAND Flash not found !\n"); - devm_free_irq(dev, prv->irq, mtd); retval = -ENXIO; goto error; } @@ -828,7 +806,6 @@ static int __devinit mpc5121_nfc_probe(struct platform_device *op) default: dev_err(dev, "Unsupported NAND flash!\n"); - devm_free_irq(dev, prv->irq, mtd); retval = -ENXIO; goto error; } @@ -839,13 +816,12 @@ static int __devinit mpc5121_nfc_probe(struct platform_device *op) retval = mtd_device_parse_register(mtd, NULL, &ppdata, NULL, 0); if (retval) { dev_err(dev, "Error adding MTD device!\n"); - devm_free_irq(dev, prv->irq, mtd); goto error; } return 0; error: - mpc5121_nfc_free(dev, mtd); + clk_disable(prv->clk); return retval; } @@ -857,8 +833,7 @@ static int __devexit mpc5121_nfc_remove(struct platform_device *op) struct mpc5121_nfc_prv *prv = chip->priv; nand_release(mtd); - devm_free_irq(dev, prv->irq, mtd); - mpc5121_nfc_free(dev, mtd); + clk_disable(prv->clk); return 0; }