* [PATCH -next] mtd: orion_nand: convert to use devm_* APIs
@ 2013-07-17 2:09 ` Wei Yongjun
0 siblings, 0 replies; 5+ messages in thread
From: Wei Yongjun @ 2013-07-17 2:09 UTC (permalink / raw)
To: dwmw2, grant.likely, rob.herring, artem.bityutskiy, jg1.han,
andrew, wfp5p
Cc: yongjun_wei, linux-mtd, devicetree-discuss, linux-kernel
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;
}
if (pdev->dev.of_node) {
@@ -111,8 +109,7 @@ static int __init orion_nand_probe(struct platform_device *pdev)
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;
@@ -186,10 +183,6 @@ no_dev:
clk_disable_unprepare(clk);
clk_put(clk);
}
- iounmap(io_base);
-no_res:
- kfree(nc);
-
return ret;
}
@@ -201,10 +194,6 @@ static int orion_nand_remove(struct platform_device *pdev)
nand_release(mtd);
- iounmap(nc->IO_ADDR_W);
-
- kfree(nc);
-
clk = clk_get(&pdev->dev, NULL);
if (!IS_ERR(clk)) {
clk_disable_unprepare(clk);
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH -next] mtd: orion_nand: convert to use devm_* APIs
@ 2013-07-17 2:09 ` Wei Yongjun
0 siblings, 0 replies; 5+ messages in thread
From: Wei Yongjun @ 2013-07-17 2:09 UTC (permalink / raw)
To: dwmw2-wEGCiKHe2LqWVfeAwA7xHQ,
grant.likely-QSEj5FYQhm4dnm+yROfE0A,
rob.herring-bsGFqQB8/DxBDgjK7y7TUQ,
artem.bityutskiy-VuQAYsv1563Yd54FQh9/CA,
jg1.han-Sze3O3UU22JBDgjK7y7TUQ, andrew-g2DYL2Zd6BY,
wfp5p-4Ng6DfrEGID2fBVCVOL8/A
Cc: yongjun_wei-zrsr2BFq86L20UzCJQGyNP8+0UxHXcjY,
linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r,
devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ,
linux-kernel-u79uwXL29TY76Z2rM5mHXA
From: Wei Yongjun <yongjun_wei-zrsr2BFq86L20UzCJQGyNP8+0UxHXcjY@public.gmane.org>
Convert to use devm_* APIs to avoid resources leak on error handling case.
Signed-off-by: Wei Yongjun <yongjun_wei-zrsr2BFq86L20UzCJQGyNP8+0UxHXcjY@public.gmane.org>
---
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;
}
if (pdev->dev.of_node) {
@@ -111,8 +109,7 @@ static int __init orion_nand_probe(struct platform_device *pdev)
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;
@@ -186,10 +183,6 @@ no_dev:
clk_disable_unprepare(clk);
clk_put(clk);
}
- iounmap(io_base);
-no_res:
- kfree(nc);
-
return ret;
}
@@ -201,10 +194,6 @@ static int orion_nand_remove(struct platform_device *pdev)
nand_release(mtd);
- iounmap(nc->IO_ADDR_W);
-
- kfree(nc);
-
clk = clk_get(&pdev->dev, NULL);
if (!IS_ERR(clk)) {
clk_disable_unprepare(clk);
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH -next] mtd: orion_nand: convert to use devm_* APIs
2013-07-17 2:09 ` Wei Yongjun
(?)
@ 2013-07-17 7:45 ` Andrew Lunn
-1 siblings, 0 replies; 5+ messages in thread
From: Andrew Lunn @ 2013-07-17 7:45 UTC (permalink / raw)
To: Wei Yongjun
Cc: dwmw2, grant.likely, rob.herring, artem.bityutskiy, jg1.han,
andrew, wfp5p, yongjun_wei, linux-mtd, devicetree-discuss,
linux-kernel
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH -next] mtd: orion_nand: convert to use devm_* APIs
@ 2013-07-17 7:45 ` Andrew Lunn
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Lunn @ 2013-07-17 7:45 UTC (permalink / raw)
To: Wei Yongjun
Cc: andrew, artem.bityutskiy, devicetree-discuss, jg1.han,
linux-kernel, rob.herring, yongjun_wei, wfp5p, linux-mtd,
grant.likely, dwmw2
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/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH -next] mtd: orion_nand: convert to use devm_* APIs
@ 2013-07-17 7:45 ` Andrew Lunn
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Lunn @ 2013-07-17 7:45 UTC (permalink / raw)
To: Wei Yongjun
Cc: andrew, artem.bityutskiy, devicetree-discuss, jg1.han,
linux-kernel, rob.herring, yongjun_wei, wfp5p, linux-mtd,
grant.likely, dwmw2
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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-07-17 8:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-07-17 2:09 [PATCH -next] mtd: orion_nand: convert to use devm_* APIs Wei Yongjun
2013-07-17 2:09 ` Wei Yongjun
2013-07-17 7:45 ` Andrew Lunn
2013-07-17 7:45 ` Andrew Lunn
2013-07-17 7:45 ` Andrew Lunn
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.