* [PATCH RESEND 4/7] watchdog: nuc900_wdt: use devm_*() functions
@ 2013-04-29 9:35 Jingoo Han
2013-04-29 18:02 ` Guenter Roeck
0 siblings, 1 reply; 4+ messages in thread
From: Jingoo Han @ 2013-04-29 9:35 UTC (permalink / raw)
To: 'Andrew Morton'
Cc: linux-kernel, 'Wim Van Sebroeck', linux-watchdog,
Jingoo Han
Use devm_*() functions to make cleanup paths simpler.
Signed-off-by: Jingoo Han <jg1.han@samsung.com>
---
drivers/watchdog/nuc900_wdt.c | 45 ++++++++--------------------------------
1 files changed, 9 insertions(+), 36 deletions(-)
diff --git a/drivers/watchdog/nuc900_wdt.c b/drivers/watchdog/nuc900_wdt.c
index 04c45a1..89e8991 100644
--- a/drivers/watchdog/nuc900_wdt.c
+++ b/drivers/watchdog/nuc900_wdt.c
@@ -246,7 +246,8 @@ static int nuc900wdt_probe(struct platform_device *pdev)
{
int ret = 0;
- nuc900_wdt = kzalloc(sizeof(struct nuc900_wdt), GFP_KERNEL);
+ nuc900_wdt = devm_kzalloc(&pdev->dev, sizeof(struct nuc900_wdt),
+ GFP_KERNEL);
if (!nuc900_wdt)
return -ENOMEM;
@@ -257,30 +258,18 @@ static int nuc900wdt_probe(struct platform_device *pdev)
nuc900_wdt->res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (nuc900_wdt->res == NULL) {
dev_err(&pdev->dev, "no memory resource specified\n");
- ret = -ENOENT;
- goto err_get;
+ return -ENOENT;
}
- if (!request_mem_region(nuc900_wdt->res->start,
- resource_size(nuc900_wdt->res), pdev->name)) {
- dev_err(&pdev->dev, "failed to get memory region\n");
- ret = -ENOENT;
- goto err_get;
- }
-
- nuc900_wdt->wdt_base = ioremap(nuc900_wdt->res->start,
- resource_size(nuc900_wdt->res));
- if (nuc900_wdt->wdt_base == NULL) {
- dev_err(&pdev->dev, "failed to ioremap() region\n");
- ret = -EINVAL;
- goto err_req;
- }
+ nuc900_wdt->wdt_base = devm_ioremap_resource(&pdev->dev,
+ nuc900_wdt->res);
+ if (IS_ERR(nuc900_wdt->wdt_base))
+ return PTR_ERR(nuc900_wdt->wdt_base);
- nuc900_wdt->wdt_clock = clk_get(&pdev->dev, NULL);
+ nuc900_wdt->wdt_clock = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(nuc900_wdt->wdt_clock)) {
dev_err(&pdev->dev, "failed to find watchdog clock source\n");
- ret = PTR_ERR(nuc900_wdt->wdt_clock);
- goto err_map;
+ return PTR_ERR(nuc900_wdt->wdt_clock);
}
clk_enable(nuc900_wdt->wdt_clock);
@@ -298,14 +287,6 @@ static int nuc900wdt_probe(struct platform_device *pdev)
err_clk:
clk_disable(nuc900_wdt->wdt_clock);
- clk_put(nuc900_wdt->wdt_clock);
-err_map:
- iounmap(nuc900_wdt->wdt_base);
-err_req:
- release_mem_region(nuc900_wdt->res->start,
- resource_size(nuc900_wdt->res));
-err_get:
- kfree(nuc900_wdt);
return ret;
}
@@ -314,14 +295,6 @@ static int nuc900wdt_remove(struct platform_device *pdev)
misc_deregister(&nuc900wdt_miscdev);
clk_disable(nuc900_wdt->wdt_clock);
- clk_put(nuc900_wdt->wdt_clock);
-
- iounmap(nuc900_wdt->wdt_base);
-
- release_mem_region(nuc900_wdt->res->start,
- resource_size(nuc900_wdt->res));
-
- kfree(nuc900_wdt);
return 0;
}
--
1.7.2.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH RESEND 4/7] watchdog: nuc900_wdt: use devm_*() functions
2013-04-29 9:35 Jingoo Han
@ 2013-04-29 18:02 ` Guenter Roeck
2013-04-30 2:14 ` Jingoo Han
0 siblings, 1 reply; 4+ messages in thread
From: Guenter Roeck @ 2013-04-29 18:02 UTC (permalink / raw)
To: Jingoo Han
Cc: 'Andrew Morton', linux-kernel, 'Wim Van Sebroeck',
linux-watchdog
On Mon, Apr 29, 2013 at 06:35:33PM +0900, Jingoo Han wrote:
> Use devm_*() functions to make cleanup paths simpler.
>
> Signed-off-by: Jingoo Han <jg1.han@samsung.com>
> ---
> drivers/watchdog/nuc900_wdt.c | 45 ++++++++--------------------------------
> 1 files changed, 9 insertions(+), 36 deletions(-)
>
> diff --git a/drivers/watchdog/nuc900_wdt.c b/drivers/watchdog/nuc900_wdt.c
> index 04c45a1..89e8991 100644
> --- a/drivers/watchdog/nuc900_wdt.c
> +++ b/drivers/watchdog/nuc900_wdt.c
> @@ -246,7 +246,8 @@ static int nuc900wdt_probe(struct platform_device *pdev)
> {
> int ret = 0;
>
> - nuc900_wdt = kzalloc(sizeof(struct nuc900_wdt), GFP_KERNEL);
> + nuc900_wdt = devm_kzalloc(&pdev->dev, sizeof(struct nuc900_wdt),
> + GFP_KERNEL);
General hint: sizeof(*nuc900_wdt) is preferred by most maintainers.
> if (!nuc900_wdt)
> return -ENOMEM;
>
> @@ -257,30 +258,18 @@ static int nuc900wdt_probe(struct platform_device *pdev)
> nuc900_wdt->res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> if (nuc900_wdt->res == NULL) {
It is no longer necessary to save the resource in nuc900_wdt, as it is only
used in the probe function. So you might as well drop the variable from the
structure and declare it locally.
> dev_err(&pdev->dev, "no memory resource specified\n");
> - ret = -ENOENT;
> - goto err_get;
> + return -ENOENT;
> }
>
> - if (!request_mem_region(nuc900_wdt->res->start,
> - resource_size(nuc900_wdt->res), pdev->name)) {
> - dev_err(&pdev->dev, "failed to get memory region\n");
> - ret = -ENOENT;
> - goto err_get;
> - }
> -
> - nuc900_wdt->wdt_base = ioremap(nuc900_wdt->res->start,
> - resource_size(nuc900_wdt->res));
> - if (nuc900_wdt->wdt_base == NULL) {
> - dev_err(&pdev->dev, "failed to ioremap() region\n");
> - ret = -EINVAL;
> - goto err_req;
> - }
> + nuc900_wdt->wdt_base = devm_ioremap_resource(&pdev->dev,
> + nuc900_wdt->res);
> + if (IS_ERR(nuc900_wdt->wdt_base))
> + return PTR_ERR(nuc900_wdt->wdt_base);
>
Does devm_ioremap_resource() spit out an error if it fails ?
If not, you might want to add an error message for consistency
with the other messages.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH RESEND 4/7] watchdog: nuc900_wdt: use devm_*() functions
2013-04-29 18:02 ` Guenter Roeck
@ 2013-04-30 2:14 ` Jingoo Han
0 siblings, 0 replies; 4+ messages in thread
From: Jingoo Han @ 2013-04-30 2:14 UTC (permalink / raw)
To: 'Guenter Roeck'
Cc: 'Andrew Morton', linux-kernel, 'Wim Van Sebroeck',
linux-watchdog, Thierry Reding, Jingoo Han
> -----Original Message-----
> From: Guenter Roeck [mailto:linux@roeck-us.net]
> Sent: Tuesday, April 30, 2013 3:03 AM
> To: Jingoo Han
> Cc: 'Andrew Morton'; linux-kernel@vger.kernel.org; 'Wim Van Sebroeck'; linux-watchdog@vger.kernel.org
> Subject: Re: [PATCH RESEND 4/7] watchdog: nuc900_wdt: use devm_*() functions
>
> On Mon, Apr 29, 2013 at 06:35:33PM +0900, Jingoo Han wrote:
> > Use devm_*() functions to make cleanup paths simpler.
> >
> > Signed-off-by: Jingoo Han <jg1.han@samsung.com>
> > ---
> > drivers/watchdog/nuc900_wdt.c | 45 ++++++++--------------------------------
> > 1 files changed, 9 insertions(+), 36 deletions(-)
> >
> > diff --git a/drivers/watchdog/nuc900_wdt.c b/drivers/watchdog/nuc900_wdt.c
> > index 04c45a1..89e8991 100644
> > --- a/drivers/watchdog/nuc900_wdt.c
> > +++ b/drivers/watchdog/nuc900_wdt.c
> > @@ -246,7 +246,8 @@ static int nuc900wdt_probe(struct platform_device *pdev)
> > {
> > int ret = 0;
> >
> > - nuc900_wdt = kzalloc(sizeof(struct nuc900_wdt), GFP_KERNEL);
> > + nuc900_wdt = devm_kzalloc(&pdev->dev, sizeof(struct nuc900_wdt),
> > + GFP_KERNEL);
>
> General hint: sizeof(*nuc900_wdt) is preferred by most maintainers.
OK, I will fix it.
>
> > if (!nuc900_wdt)
> > return -ENOMEM;
> >
> > @@ -257,30 +258,18 @@ static int nuc900wdt_probe(struct platform_device *pdev)
> > nuc900_wdt->res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > if (nuc900_wdt->res == NULL) {
>
> It is no longer necessary to save the resource in nuc900_wdt, as it is only
> used in the probe function. So you might as well drop the variable from the
> structure and declare it locally.
OK, I will drop 'nuc900_wdt->res' variable from the 'nuc900_wdt' structure and
declare it as logical variable.
>
> > dev_err(&pdev->dev, "no memory resource specified\n");
> > - ret = -ENOENT;
> > - goto err_get;
> > + return -ENOENT;
> > }
> >
> > - if (!request_mem_region(nuc900_wdt->res->start,
> > - resource_size(nuc900_wdt->res), pdev->name)) {
> > - dev_err(&pdev->dev, "failed to get memory region\n");
> > - ret = -ENOENT;
> > - goto err_get;
> > - }
> > -
> > - nuc900_wdt->wdt_base = ioremap(nuc900_wdt->res->start,
> > - resource_size(nuc900_wdt->res));
> > - if (nuc900_wdt->wdt_base == NULL) {
> > - dev_err(&pdev->dev, "failed to ioremap() region\n");
> > - ret = -EINVAL;
> > - goto err_req;
> > - }
> > + nuc900_wdt->wdt_base = devm_ioremap_resource(&pdev->dev,
> > + nuc900_wdt->res);
> > + if (IS_ERR(nuc900_wdt->wdt_base))
> > + return PTR_ERR(nuc900_wdt->wdt_base);
> >
> Does devm_ioremap_resource() spit out an error if it fails ?
> If not, you might want to add an error message for consistency
> with the other messages.
I CC'ed Thierry Reding who is the author of devm_ioremap_resource().
Um, devm_ioremap_resource() spits out an error if it fails.
According to commit message of the previous patch made by Thierry Reding,
"devm_ioremap_resource() provides its own error messages so all explicit
error messages can be removed from the failure code paths."
Thus, there is no need to add an error message.
Best regards,
Jingoo Han
>
> Thanks,
> Guenter
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH RESEND 4/7] watchdog: nuc900_wdt: use devm_*() functions
@ 2013-05-02 5:51 Jingoo Han
0 siblings, 0 replies; 4+ messages in thread
From: Jingoo Han @ 2013-05-02 5:51 UTC (permalink / raw)
To: 'Andrew Morton'
Cc: linux-kernel, 'Wim Van Sebroeck', linux-watchdog,
'Guenter Roeck', Jingoo Han
Use devm_*() functions to make cleanup paths simpler.
Signed-off-by: Jingoo Han <jg1.han@samsung.com>
---
drivers/watchdog/nuc900_wdt.c | 50 +++++++++--------------------------------
1 files changed, 11 insertions(+), 39 deletions(-)
diff --git a/drivers/watchdog/nuc900_wdt.c b/drivers/watchdog/nuc900_wdt.c
index 04c45a1..e2b6d2c 100644
--- a/drivers/watchdog/nuc900_wdt.c
+++ b/drivers/watchdog/nuc900_wdt.c
@@ -61,7 +61,6 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started "
"(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
struct nuc900_wdt {
- struct resource *res;
struct clk *wdt_clock;
struct platform_device *pdev;
void __iomem *wdt_base;
@@ -244,9 +243,11 @@ static struct miscdevice nuc900wdt_miscdev = {
static int nuc900wdt_probe(struct platform_device *pdev)
{
+ struct resource *res;
int ret = 0;
- nuc900_wdt = kzalloc(sizeof(struct nuc900_wdt), GFP_KERNEL);
+ nuc900_wdt = devm_kzalloc(&pdev->dev, sizeof(*nuc900_wdt),
+ GFP_KERNEL);
if (!nuc900_wdt)
return -ENOMEM;
@@ -254,33 +255,20 @@ static int nuc900wdt_probe(struct platform_device *pdev)
spin_lock_init(&nuc900_wdt->wdt_lock);
- nuc900_wdt->res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- if (nuc900_wdt->res == NULL) {
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (res == NULL) {
dev_err(&pdev->dev, "no memory resource specified\n");
- ret = -ENOENT;
- goto err_get;
+ return -ENOENT;
}
- if (!request_mem_region(nuc900_wdt->res->start,
- resource_size(nuc900_wdt->res), pdev->name)) {
- dev_err(&pdev->dev, "failed to get memory region\n");
- ret = -ENOENT;
- goto err_get;
- }
-
- nuc900_wdt->wdt_base = ioremap(nuc900_wdt->res->start,
- resource_size(nuc900_wdt->res));
- if (nuc900_wdt->wdt_base == NULL) {
- dev_err(&pdev->dev, "failed to ioremap() region\n");
- ret = -EINVAL;
- goto err_req;
- }
+ nuc900_wdt->wdt_base = devm_ioremap_resource(&pdev->dev, res);
+ if (IS_ERR(nuc900_wdt->wdt_base))
+ return PTR_ERR(nuc900_wdt->wdt_base);
- nuc900_wdt->wdt_clock = clk_get(&pdev->dev, NULL);
+ nuc900_wdt->wdt_clock = devm_clk_get(&pdev->dev, NULL);
if (IS_ERR(nuc900_wdt->wdt_clock)) {
dev_err(&pdev->dev, "failed to find watchdog clock source\n");
- ret = PTR_ERR(nuc900_wdt->wdt_clock);
- goto err_map;
+ return PTR_ERR(nuc900_wdt->wdt_clock);
}
clk_enable(nuc900_wdt->wdt_clock);
@@ -298,14 +286,6 @@ static int nuc900wdt_probe(struct platform_device *pdev)
err_clk:
clk_disable(nuc900_wdt->wdt_clock);
- clk_put(nuc900_wdt->wdt_clock);
-err_map:
- iounmap(nuc900_wdt->wdt_base);
-err_req:
- release_mem_region(nuc900_wdt->res->start,
- resource_size(nuc900_wdt->res));
-err_get:
- kfree(nuc900_wdt);
return ret;
}
@@ -314,14 +294,6 @@ static int nuc900wdt_remove(struct platform_device *pdev)
misc_deregister(&nuc900wdt_miscdev);
clk_disable(nuc900_wdt->wdt_clock);
- clk_put(nuc900_wdt->wdt_clock);
-
- iounmap(nuc900_wdt->wdt_base);
-
- release_mem_region(nuc900_wdt->res->start,
- resource_size(nuc900_wdt->res));
-
- kfree(nuc900_wdt);
return 0;
}
--
1.7.2.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-05-02 5:51 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-05-02 5:51 [PATCH RESEND 4/7] watchdog: nuc900_wdt: use devm_*() functions Jingoo Han
-- strict thread matches above, loose matches on Subject: below --
2013-04-29 9:35 Jingoo Han
2013-04-29 18:02 ` Guenter Roeck
2013-04-30 2:14 ` Jingoo Han
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).