From: Andrew Lunn <andrew@lunn.ch>
To: Wei Yongjun <weiyj.lk@gmail.com>
Cc: andrew@lunn.ch, artem.bityutskiy@linux.intel.com,
devicetree-discuss@lists.ozlabs.org, jg1.han@samsung.com,
linux-kernel@vger.kernel.org, rob.herring@calxeda.com,
yongjun_wei@trendmicro.com.cn, wfp5p@virginia.edu,
linux-mtd@lists.infradead.org, grant.likely@linaro.org,
dwmw2@infradead.org
Subject: Re: [PATCH -next] mtd: orion_nand: convert to use devm_* APIs
Date: Wed, 17 Jul 2013 09:45:33 +0200 [thread overview]
Message-ID: <20130717074533.GA1026@lunn.ch> (raw)
In-Reply-To: <CAPgLHd8upcmfnQqHAWnqP7YBVYDVyoYKQ3WCh3c5+uY-EKr1jg@mail.gmail.com>
On Wed, Jul 17, 2013 at 10:09:10AM +0800, Wei Yongjun wrote:
> From: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
>
> Convert to use devm_* APIs to avoid resources leak on error handling case.
>
> Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn>
> ---
> drivers/mtd/nand/orion_nand.c | 29 +++++++++--------------------
> 1 file changed, 9 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
> index 46f308d..ce711b4 100644
> --- a/drivers/mtd/nand/orion_nand.c
> +++ b/drivers/mtd/nand/orion_nand.c
> @@ -85,25 +85,23 @@ 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;
> - }
> + if (!res)
> + return -ENODEV;
>
> - io_base = ioremap(res->start, resource_size(res));
> + io_base = devm_ioremap(&pdev->dev, res->start, resource_size(res));
> if (!io_base) {
> printk(KERN_ERR "orion_nand: ioremap failed\n");
> - ret = -EIO;
> - goto no_res;
> + return -EIO;
Hi Wei
Thanks for working on this.
The above code can be further simplified:
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
io_base = devm_ioremap_resource(&pdev->dev, res);
if (IS_ERR(io_base))
return PTR_ERR(io_base);
While you are editing this file, it would be nice to replace all the
printk() statements with dev_err(), dev_info() etc. Please do that as
a separate patch.
Thanks
Andrew
______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/
prev parent reply other threads:[~2013-07-17 7:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-07-17 2:09 [PATCH -next] mtd: orion_nand: convert to use devm_* APIs Wei Yongjun
2013-07-17 7:45 ` Andrew Lunn [this message]
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=20130717074533.GA1026@lunn.ch \
--to=andrew@lunn.ch \
--cc=artem.bityutskiy@linux.intel.com \
--cc=devicetree-discuss@lists.ozlabs.org \
--cc=dwmw2@infradead.org \
--cc=grant.likely@linaro.org \
--cc=jg1.han@samsung.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=rob.herring@calxeda.com \
--cc=weiyj.lk@gmail.com \
--cc=wfp5p@virginia.edu \
--cc=yongjun_wei@trendmicro.com.cn \
/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).