From: Emil Goode <emilgoode@gmail.com>
To: dwmw2@infradead.org, artem.bityutskiy@linux.intel.com,
andrew@lunn.ch, wfp5p@virginia.edu, jg1.han@samsung.com
Cc: kernel-janitors@vger.kernel.org, Emil Goode <emilgoode@gmail.com>,
linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2] mtd: orion_nand: Improve error handling in orion_nand_probe
Date: Mon, 10 Jun 2013 02:00:42 +0200 [thread overview]
Message-ID: <1370822442-25217-1-git-send-email-emilgoode@gmail.com> (raw)
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 forget 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 <emilgoode@gmail.com>
---
This patch is only build tested
v2: Fix change log typo and remove error messages for kzalloc calls
drivers/mtd/nand/orion_nand.c | 49 +++++++++++++----------------------------
1 file changed, 15 insertions(+), 34 deletions(-)
diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
index 8fbd002..76b9fba 100644
--- a/drivers/mtd/nand/orion_nand.c
+++ b/drivers/mtd/nand/orion_nand.c
@@ -85,35 +85,24 @@ 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);
- if (!nc) {
- printk(KERN_ERR "orion_nand: failed to allocate device structure.\n");
- ret = -ENOMEM;
- goto no_res;
- }
+ nc = devm_kzalloc(&pdev->dev, sizeof(struct nand_chip) +
+ sizeof(struct mtd_info), GFP_KERNEL);
+ if (!nc)
+ 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);
- if (!board) {
- printk(KERN_ERR "orion_nand: failed to allocate board structure.\n");
- ret = -ENOMEM;
- goto no_res;
- }
+ GFP_KERNEL);
+ if (!board)
+ return -ENOMEM;
+
if (!of_property_read_u32(pdev->dev.of_node, "cle", &val))
board->cle = (u8)val;
else
@@ -167,7 +156,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 +165,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 +183,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);
--
1.7.10.4
next reply other threads:[~2013-06-09 23:59 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-10 0:00 Emil Goode [this message]
2013-06-10 5:34 ` [PATCH v2] mtd: orion_nand: Improve error handling in orion_nand_probe Jingoo Han
2013-06-10 10:35 ` Emil Goode
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1370822442-25217-1-git-send-email-emilgoode@gmail.com \
--to=emilgoode@gmail.com \
--cc=andrew@lunn.ch \
--cc=artem.bityutskiy@linux.intel.com \
--cc=dwmw2@infradead.org \
--cc=jg1.han@samsung.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=wfp5p@virginia.edu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).