[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1347956633-15667-5-git-send-email-thierry.reding@avionic-design.de>
Date: Tue, 18 Sep 2012 10:23:52 +0200
From: Thierry Reding <thierry.reding@...onic-design.de>
To: Guan Xuetao <gxt@...c.pku.edu.cn>
Cc: Qin Rui <qinrui@...c.pku.edu.cn>, linux-kernel@...r.kernel.org
Subject: [PATCH v2 4/5] unicore32: pwm: Use managed resource allocations
This commit uses the managed resource allocation functions to simplify
the cleanup paths on error and removal.
Signed-off-by: Thierry Reding <thierry.reding@...onic-design.de>
---
arch/unicore32/kernel/pwm.c | 47 +++++++++------------------------------------
1 file changed, 9 insertions(+), 38 deletions(-)
diff --git a/arch/unicore32/kernel/pwm.c b/arch/unicore32/kernel/pwm.c
index 7e23470..724e860 100644
--- a/arch/unicore32/kernel/pwm.c
+++ b/arch/unicore32/kernel/pwm.c
@@ -160,19 +160,17 @@ static int __devinit pwm_probe(struct platform_device *pdev)
{
struct pwm_device *pwm;
struct resource *r;
- int ret = 0;
- pwm = kzalloc(sizeof(struct pwm_device), GFP_KERNEL);
+ pwm = devm_kzalloc(&pdev->dev, sizeof(struct pwm_device), GFP_KERNEL);
if (pwm == NULL) {
dev_err(&pdev->dev, "failed to allocate memory\n");
return -ENOMEM;
}
- pwm->clk = clk_get(NULL, "OST_CLK");
- if (IS_ERR(pwm->clk)) {
- ret = PTR_ERR(pwm->clk);
- goto err_free;
- }
+ pwm->clk = devm_clk_get(&pdev->dev, "OST_CLK");
+ if (IS_ERR(pwm->clk))
+ return PTR_ERR(pwm->clk);
+
pwm->clk_enabled = 0;
pwm->use_count = 0;
@@ -182,41 +180,21 @@ static int __devinit pwm_probe(struct platform_device *pdev)
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (r == NULL) {
dev_err(&pdev->dev, "no memory resource defined\n");
- ret = -ENODEV;
- goto err_free_clk;
- }
-
- r = request_mem_region(r->start, resource_size(r), pdev->name);
- if (r == NULL) {
- dev_err(&pdev->dev, "failed to request memory resource\n");
- ret = -EBUSY;
- goto err_free_clk;
+ return -ENODEV;
}
- pwm->base = ioremap_nocache(r->start, resource_size(r));
- if (pwm->base == NULL) {
- dev_err(&pdev->dev, "failed to remap memory resource\n");
- ret = -EADDRNOTAVAIL;
- goto err_release_mem;
- }
+ pwm->base = devm_request_and_ioremap(&pdev->dev, r);
+ if (pwm->base == NULL)
+ return -EADDRNOTAVAIL;
__add_pwm(pwm);
platform_set_drvdata(pdev, pwm);
return 0;
-
-err_release_mem:
- release_mem_region(r->start, resource_size(r));
-err_free_clk:
- clk_put(pwm->clk);
-err_free:
- kfree(pwm);
- return ret;
}
static int __devexit pwm_remove(struct platform_device *pdev)
{
struct pwm_device *pwm;
- struct resource *r;
pwm = platform_get_drvdata(pdev);
if (pwm == NULL)
@@ -226,13 +204,6 @@ static int __devexit pwm_remove(struct platform_device *pdev)
list_del(&pwm->node);
mutex_unlock(&pwm_lock);
- iounmap(pwm->base);
-
- r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- release_mem_region(r->start, resource_size(r));
-
- clk_put(pwm->clk);
- kfree(pwm);
return 0;
}
--
1.7.12
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists