From patchwork Sun Jun 9 09:08:22 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Emil Goode X-Patchwork-Id: 250016 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 73DF92C02A3 for ; Sun, 9 Jun 2013 19:13:22 +1000 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ulbg3-0007gW-OJ; Sun, 09 Jun 2013 09:12:45 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ulbfl-0002kK-GI; Sun, 09 Jun 2013 09:12:25 +0000 Received: from mail-lb0-f181.google.com ([209.85.217.181]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ulbfi-0002jW-T0 for linux-mtd@lists.infradead.org; Sun, 09 Jun 2013 09:12:24 +0000 Received: by mail-lb0-f181.google.com with SMTP id w10so2707591lbi.40 for ; Sun, 09 Jun 2013 02:11:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer; bh=4JPMI6KF2R5fDdT4i5htVXeKc/24XC+zxZmkltDmmrg=; b=dM0Pw5HLleI3z/1FuEesfMnJDX42Z3Autqg+EseULQtTNJJJz/v2StSKoBhiggdpfM HEtSq3II8oQiXsm2SoRvvJOBmawF8taOSy//S0Qkx1h+SZJb8t9ni//U4iFZZ96eSwxa fLygxkyynXbj2RDDyHJt5az1XNvLnGX4mVRkyFQAeeny5Q/feLZDCHpCN2mFkjTttvgX gipX6/BjGLpSEuFmYRQwHY/oJ49EVLy83SbVNHq9TLcBMDBhlC3W0f2Mt7+ak22hSmpV LtWq/+6Wv+5BD+ubET/njC9TXukI63BoSJjc01doxPCzW2VrEv4Xw7NKXvWgDPMbl/Je +ceg== X-Received: by 10.112.205.163 with SMTP id lh3mr4367549lbc.45.1370769118549; Sun, 09 Jun 2013 02:11:58 -0700 (PDT) Received: from localhost.localdomain (c193-14-104-184.cust.tele2.se. [193.14.104.184]) by mx.google.com with ESMTPSA id z9sm2385476lae.7.2013.06.09.02.11.56 for (version=TLSv1.2 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 09 Jun 2013 02:11:57 -0700 (PDT) From: Emil Goode To: dwmw2@infradead.org, artem.bityutskiy@linux.intel.com, andrew@lunn.ch, wfp5p@virginia.edu, jg1.han@samsung.com Subject: [PATCH] mtd: orion_nand: Improve error handling in orion_nand_probe Date: Sun, 9 Jun 2013 11:08:22 +0200 Message-Id: <1370768902-20239-1-git-send-email-emilgoode@gmail.com> X-Mailer: git-send-email 1.7.10.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130609_051223_085781_146D4287 X-CRM114-Status: GOOD ( 15.63 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (emilgoode[at]gmail.com) -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.217.181 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature Cc: kernel-janitors@vger.kernel.org, Emil Goode , linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.15 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" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org This patch fixes some issues in the error handling and simplifies the code by converting to devm* functions. If the kzalloc call fails it is unnecessary to use the label no_res and pass a NULL pointer to kfree. If the devm_kzalloc call fails on line 110 we forgett to call iounmap for the previous ioremap call. The following changes are introduced: - Convert to devm_kzalloc and remove calls to kfree. - Convert to devm_ioremap_resource that adds a missing call to *request_mem_region and remove calls to iounmap. - The devm_ioremap_resource function checks the passed resource so we can remove the NULL check after the platform_get_resource call. Signed-off-by: Emil Goode --- The patch is only build tested drivers/mtd/nand/orion_nand.c | 39 +++++++++++---------------------------- 1 file changed, 11 insertions(+), 28 deletions(-) diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c index 8fbd002..cc22f2f 100644 --- a/drivers/mtd/nand/orion_nand.c +++ b/drivers/mtd/nand/orion_nand.c @@ -85,34 +85,25 @@ static int __init orion_nand_probe(struct platform_device *pdev) int ret = 0; u32 val = 0; - nc = kzalloc(sizeof(struct nand_chip) + sizeof(struct mtd_info), GFP_KERNEL); + nc = devm_kzalloc(&pdev->dev, sizeof(struct nand_chip) + + sizeof(struct mtd_info), GFP_KERNEL); if (!nc) { printk(KERN_ERR "orion_nand: failed to allocate device structure.\n"); - ret = -ENOMEM; - goto no_res; + return -ENOMEM; } mtd = (struct mtd_info *)(nc + 1); res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) { - ret = -ENODEV; - goto no_res; - } - - io_base = ioremap(res->start, resource_size(res)); - if (!io_base) { - printk(KERN_ERR "orion_nand: ioremap failed\n"); - ret = -EIO; - goto no_res; - } + io_base = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(io_base)) + return PTR_ERR(io_base); if (pdev->dev.of_node) { board = devm_kzalloc(&pdev->dev, sizeof(struct orion_nand_data), - GFP_KERNEL); + GFP_KERNEL); if (!board) { printk(KERN_ERR "orion_nand: failed to allocate board structure.\n"); - ret = -ENOMEM; - goto no_res; + return -ENOMEM; } if (!of_property_read_u32(pdev->dev.of_node, "cle", &val)) board->cle = (u8)val; @@ -167,7 +158,7 @@ static int __init orion_nand_probe(struct platform_device *pdev) if (nand_scan(mtd, 1)) { ret = -ENXIO; - goto no_dev; + goto disable_clk; } mtd->name = "orion_nand"; @@ -176,20 +167,17 @@ static int __init orion_nand_probe(struct platform_device *pdev) board->parts, board->nr_parts); if (ret) { nand_release(mtd); - goto no_dev; + goto disable_clk; } return 0; -no_dev: +disable_clk: if (!IS_ERR(clk)) { clk_disable_unprepare(clk); clk_put(clk); } platform_set_drvdata(pdev, NULL); - iounmap(io_base); -no_res: - kfree(nc); return ret; } @@ -197,15 +185,10 @@ no_res: static int orion_nand_remove(struct platform_device *pdev) { struct mtd_info *mtd = platform_get_drvdata(pdev); - struct nand_chip *nc = mtd->priv; struct clk *clk; nand_release(mtd); - iounmap(nc->IO_ADDR_W); - - kfree(nc); - clk = clk_get(&pdev->dev, NULL); if (!IS_ERR(clk)) { clk_disable_unprepare(clk);