2012-06-29 13:30:37

by Axel Lin

[permalink] [raw]
Subject: [PATCH 1/4] pwm: Convert pwm-imx to use devm_* APIs

Signed-off-by: Axel Lin <[email protected]>
---
drivers/pwm/pwm-imx.c | 55 +++++++++----------------------------------------
1 file changed, 10 insertions(+), 45 deletions(-)

diff --git a/drivers/pwm/pwm-imx.c b/drivers/pwm/pwm-imx.c
index 900d145..d878c13 100644
--- a/drivers/pwm/pwm-imx.c
+++ b/drivers/pwm/pwm-imx.c
@@ -159,18 +159,16 @@ static int __devinit imx_pwm_probe(struct platform_device *pdev)
struct resource *r;
int ret = 0;

- imx = kzalloc(sizeof(*imx), GFP_KERNEL);
+ imx = devm_kzalloc(&pdev->dev, sizeof(*imx), GFP_KERNEL);
if (imx == NULL) {
dev_err(&pdev->dev, "failed to allocate memory\n");
return -ENOMEM;
}

- imx->clk = clk_get(&pdev->dev, "pwm");
+ imx->clk = devm_clk_get(&pdev->dev, "pwm");

- if (IS_ERR(imx->clk)) {
- ret = PTR_ERR(imx->clk);
- goto err_free;
- }
+ if (IS_ERR(imx->clk))
+ return PTR_ERR(imx->clk);

imx->chip.ops = &imx_pwm_ops;
imx->chip.dev = &pdev->dev;
@@ -182,46 +180,24 @@ static int __devinit imx_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;
}

- imx->mmio_base = ioremap(r->start, resource_size(r));
- if (imx->mmio_base == NULL) {
- dev_err(&pdev->dev, "failed to ioremap() registers\n");
- ret = -ENODEV;
- goto err_free_mem;
- }
+ imx->mmio_base = devm_request_and_ioremap(&pdev->dev, r);
+ if (imx->mmio_base == NULL)
+ return -ENODEV;

ret = pwmchip_add(&imx->chip);
if (ret < 0)
- goto err_iounmap;
+ return ret;

platform_set_drvdata(pdev, imx);
return 0;
-
-err_iounmap:
- iounmap(imx->mmio_base);
-err_free_mem:
- release_mem_region(r->start, resource_size(r));
-err_free_clk:
- clk_put(imx->clk);
-err_free:
- kfree(imx);
- return ret;
}

static int __devexit imx_pwm_remove(struct platform_device *pdev)
{
struct imx_chip *imx;
- struct resource *r;
int ret;

imx = platform_get_drvdata(pdev);
@@ -229,18 +205,7 @@ static int __devexit imx_pwm_remove(struct platform_device *pdev)
return -ENODEV;

ret = pwmchip_remove(&imx->chip);
- if (ret)
- return ret;
-
- iounmap(imx->mmio_base);
-
- r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- release_mem_region(r->start, resource_size(r));
-
- clk_put(imx->clk);
-
- kfree(imx);
- return 0;
+ return ret;
}

static struct platform_driver imx_pwm_driver = {
--
1.7.9.5



2012-06-29 13:31:29

by Axel Lin

[permalink] [raw]
Subject: [PATCH 2/4] pwm: Convert pwm-pxa to use devm_* APIs

Signed-off-by: Axel Lin <[email protected]>
---
drivers/pwm/pwm-pxa.c | 49 ++++++++++---------------------------------------
1 file changed, 10 insertions(+), 39 deletions(-)

diff --git a/drivers/pwm/pwm-pxa.c b/drivers/pwm/pwm-pxa.c
index d5c6ce5..1cf0597 100644
--- a/drivers/pwm/pwm-pxa.c
+++ b/drivers/pwm/pwm-pxa.c
@@ -1,5 +1,5 @@
/*
- * linux/arch/arm/mach-pxa/pwm.c
+ * drivers/pwm/pwm-pxa.c
*
* simple driver for PWM (Pulse Width Modulator) controller
*
@@ -145,17 +145,16 @@ static int __devinit pwm_probe(struct platform_device *pdev)
struct resource *r;
int ret = 0;

- pwm = kzalloc(sizeof(*pwm), GFP_KERNEL);
+ pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL);
if (pwm == NULL) {
dev_err(&pdev->dev, "failed to allocate memory\n");
return -ENOMEM;
}

- pwm->clk = clk_get(&pdev->dev, NULL);
- if (IS_ERR(pwm->clk)) {
- ret = PTR_ERR(pwm->clk);
- goto err_free;
- }
+ pwm->clk = devm_clk_get(&pdev->dev, NULL);
+ if (IS_ERR(pwm->clk))
+ return PTR_ERR(pwm->clk);
+
pwm->clk_enabled = 0;

pwm->chip.dev = &pdev->dev;
@@ -166,23 +165,12 @@ 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->mmio_base = ioremap(r->start, resource_size(r));
- if (pwm->mmio_base == NULL) {
- dev_err(&pdev->dev, "failed to ioremap() registers\n");
- ret = -ENODEV;
- goto err_free_mem;
- }
+ pwm->mmio_base = devm_request_and_ioremap(&pdev->dev, r);
+ if (pwm->mmio_base == NULL)
+ return -ENODEV;

ret = pwmchip_add(&pwm->chip);
if (ret < 0) {
@@ -192,34 +180,17 @@ static int __devinit pwm_probe(struct platform_device *pdev)

platform_set_drvdata(pdev, pwm);
return 0;
-
-err_free_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 pxa_pwm_chip *chip;
- struct resource *r;

chip = platform_get_drvdata(pdev);
if (chip == NULL)
return -ENODEV;

pwmchip_remove(&chip->chip);
-
- iounmap(chip->mmio_base);
-
- r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- release_mem_region(r->start, resource_size(r));
-
- clk_put(chip->clk);
- kfree(chip);
return 0;
}

--
1.7.9.5


2012-06-29 13:32:22

by Axel Lin

[permalink] [raw]
Subject: [PATCH 3/4] pwm: Convert pwm-samsung to use devm_* APIs

Signed-off-by: Axel Lin <[email protected]>
---
drivers/pwm/pwm-samsung.c | 24 ++++++------------------
1 file changed, 6 insertions(+), 18 deletions(-)

diff --git a/drivers/pwm/pwm-samsung.c b/drivers/pwm/pwm-samsung.c
index c40c37e..35fa0e8 100644
--- a/drivers/pwm/pwm-samsung.c
+++ b/drivers/pwm/pwm-samsung.c
@@ -1,4 +1,4 @@
-/* arch/arm/plat-s3c/pwm.c
+/* drivers/pwm/pwm-samsung.c
*
* Copyright (c) 2007 Ben Dooks
* Copyright (c) 2008 Simtec Electronics
@@ -215,7 +215,7 @@ static int s3c_pwm_probe(struct platform_device *pdev)
return -ENXIO;
}

- s3c = kzalloc(sizeof(*s3c), GFP_KERNEL);
+ s3c = devm_kzalloc(&pdev->dev, sizeof(*s3c), GFP_KERNEL);
if (s3c == NULL) {
dev_err(dev, "failed to allocate pwm_device\n");
return -ENOMEM;
@@ -227,18 +227,16 @@ static int s3c_pwm_probe(struct platform_device *pdev)
s3c->chip.base = -1;
s3c->chip.npwm = 1;

- s3c->clk = clk_get(dev, "pwm-tin");
+ s3c->clk = devm_clk_get(dev, "pwm-tin");
if (IS_ERR(s3c->clk)) {
dev_err(dev, "failed to get pwm tin clk\n");
- ret = PTR_ERR(s3c->clk);
- goto err_alloc;
+ return PTR_ERR(s3c->clk);
}

- s3c->clk_div = clk_get(dev, "pwm-tdiv");
+ s3c->clk_div = devm_clk_get(dev, "pwm-tdiv");
if (IS_ERR(s3c->clk_div)) {
dev_err(dev, "failed to get pwm tdiv clk\n");
- ret = PTR_ERR(s3c->clk_div);
- goto err_clk_tin;
+ return PTR_ERR(s3c->clk_div);
}

clk_enable(s3c->clk);
@@ -272,13 +270,6 @@ static int s3c_pwm_probe(struct platform_device *pdev)
err_clk_tdiv:
clk_disable(s3c->clk_div);
clk_disable(s3c->clk);
- clk_put(s3c->clk_div);
-
- err_clk_tin:
- clk_put(s3c->clk);
-
- err_alloc:
- kfree(s3c);
return ret;
}

@@ -293,9 +284,6 @@ static int __devexit s3c_pwm_remove(struct platform_device *pdev)

clk_disable(s3c->clk_div);
clk_disable(s3c->clk);
- clk_put(s3c->clk_div);
- clk_put(s3c->clk);
- kfree(s3c);

return 0;
}
--
1.7.9.5


2012-06-29 13:38:37

by Axel Lin

[permalink] [raw]
Subject: [PATCH 4/4] pwm: Convert pwm-vt8500 to use devm_* APIs

Signed-off-by: Axel Lin <[email protected]>
---
drivers/pwm/pwm-vt8500.c | 45 ++++++++-------------------------------------
1 file changed, 8 insertions(+), 37 deletions(-)

diff --git a/drivers/pwm/pwm-vt8500.c b/drivers/pwm/pwm-vt8500.c
index 3db0746..92f7475 100644
--- a/drivers/pwm/pwm-vt8500.c
+++ b/drivers/pwm/pwm-vt8500.c
@@ -1,5 +1,5 @@
/*
- * arch/arm/mach-vt8500/pwm.c
+ * drivers/pwm/pwm-vt8500.c
*
* Copyright (C) 2010 Alexey Charkov <[email protected]>
*
@@ -113,7 +113,7 @@ static int __devinit pwm_probe(struct platform_device *pdev)
struct resource *r;
int ret;

- chip = kzalloc(sizeof(*chip), GFP_KERNEL);
+ chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
if (chip == NULL) {
dev_err(&pdev->dev, "failed to allocate memory\n");
return -ENOMEM;
@@ -127,44 +127,24 @@ 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;
- }
-
- 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;
+ return -ENODEV;
}

- chip->base = ioremap(r->start, resource_size(r));
- if (chip->base == NULL) {
- dev_err(&pdev->dev, "failed to ioremap() registers\n");
- ret = -ENODEV;
- goto err_free_mem;
- }
+ chip->base = devm_request_and_ioremap(&pdev->dev, r);
+ if (chip->base == NULL)
+ return -ENODEV;

ret = pwmchip_add(&chip->chip);
if (ret < 0)
- goto err_unmap;
+ return ret;

platform_set_drvdata(pdev, chip);
return ret;
-
-err_unmap:
- iounmap(chip->base);
-err_free_mem:
- release_mem_region(r->start, resource_size(r));
-err_free:
- kfree(chip);
- return ret;
}

static int __devexit pwm_remove(struct platform_device *pdev)
{
struct vt8500_chip *chip;
- struct resource *r;
int err;

chip = platform_get_drvdata(pdev);
@@ -172,16 +152,7 @@ static int __devexit pwm_remove(struct platform_device *pdev)
return -ENODEV;

err = pwmchip_remove(&chip->chip);
- if (err < 0)
- return err;
-
- iounmap(chip->base);
-
- r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- release_mem_region(r->start, resource_size(r));
-
- kfree(chip);
- return 0;
+ return err;
}

static struct platform_driver pwm_driver = {
--
1.7.9.5


2012-06-30 18:44:08

by Thierry Reding

[permalink] [raw]
Subject: Re: [PATCH 1/4] pwm: Convert pwm-imx to use devm_* APIs

On Fri, Jun 29, 2012 at 09:30:28PM +0800, Axel Lin wrote:
> Signed-off-by: Axel Lin <[email protected]>
> ---
> drivers/pwm/pwm-imx.c | 55 +++++++++----------------------------------------
> 1 file changed, 10 insertions(+), 45 deletions(-)
>
> diff --git a/drivers/pwm/pwm-imx.c b/drivers/pwm/pwm-imx.c
[...]
> @@ -182,46 +180,24 @@ static int __devinit imx_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;
> }
>
> - imx->mmio_base = ioremap(r->start, resource_size(r));
> - if (imx->mmio_base == NULL) {
> - dev_err(&pdev->dev, "failed to ioremap() registers\n");
> - ret = -ENODEV;
> - goto err_free_mem;
> - }
> + imx->mmio_base = devm_request_and_ioremap(&pdev->dev, r);
> + if (imx->mmio_base == NULL)
> + return -ENODEV;

The documentation says that the standard error code for failure here is
EADDRNOTAVAIL.

> @@ -229,18 +205,7 @@ static int __devexit imx_pwm_remove(struct platform_device *pdev)
> return -ENODEV;
>
> ret = pwmchip_remove(&imx->chip);
> - if (ret)
> - return ret;
> -
> - iounmap(imx->mmio_base);
> -
> - r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> - release_mem_region(r->start, resource_size(r));
> -
> - clk_put(imx->clk);
> -
> - kfree(imx);
> - return 0;
> + return ret;

I think you can just "return pwmchip_remove(...);", no need to store the
result in ret.

Thierry


Attachments:
(No filename) (1.69 kB)
(No filename) (836.00 B)
Download all attachments

2012-06-30 19:38:29

by Thierry Reding

[permalink] [raw]
Subject: Re: [PATCH 2/4] pwm: Convert pwm-pxa to use devm_* APIs

On Fri, Jun 29, 2012 at 09:31:22PM +0800, Axel Lin wrote:
> Signed-off-by: Axel Lin <[email protected]>
> ---
> drivers/pwm/pwm-pxa.c | 49 ++++++++++---------------------------------------
> 1 file changed, 10 insertions(+), 39 deletions(-)
>
> diff --git a/drivers/pwm/pwm-pxa.c b/drivers/pwm/pwm-pxa.c
> index d5c6ce5..1cf0597 100644
> --- a/drivers/pwm/pwm-pxa.c
> +++ b/drivers/pwm/pwm-pxa.c
> @@ -1,5 +1,5 @@
> /*
> - * linux/arch/arm/mach-pxa/pwm.c
> + * drivers/pwm/pwm-pxa.c
> *
> * simple driver for PWM (Pulse Width Modulator) controller
> *
> @@ -145,17 +145,16 @@ static int __devinit pwm_probe(struct platform_device *pdev)
> struct resource *r;
> int ret = 0;
>
> - pwm = kzalloc(sizeof(*pwm), GFP_KERNEL);
> + pwm = devm_kzalloc(&pdev->dev, sizeof(*pwm), GFP_KERNEL);
> if (pwm == NULL) {
> dev_err(&pdev->dev, "failed to allocate memory\n");
> return -ENOMEM;
> }
>
> - pwm->clk = clk_get(&pdev->dev, NULL);
> - if (IS_ERR(pwm->clk)) {
> - ret = PTR_ERR(pwm->clk);
> - goto err_free;
> - }
> + pwm->clk = devm_clk_get(&pdev->dev, NULL);
> + if (IS_ERR(pwm->clk))
> + return PTR_ERR(pwm->clk);
> +
> pwm->clk_enabled = 0;
>
> pwm->chip.dev = &pdev->dev;
> @@ -166,23 +165,12 @@ 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->mmio_base = ioremap(r->start, resource_size(r));
> - if (pwm->mmio_base == NULL) {
> - dev_err(&pdev->dev, "failed to ioremap() registers\n");
> - ret = -ENODEV;
> - goto err_free_mem;
> - }
> + pwm->mmio_base = devm_request_and_ioremap(&pdev->dev, r);
> + if (pwm->mmio_base == NULL)
> + return -ENODEV;

Same comment as for the first patch.

> ret = pwmchip_add(&pwm->chip);
> if (ret < 0) {
> @@ -192,34 +180,17 @@ static int __devinit pwm_probe(struct platform_device *pdev)
>
> platform_set_drvdata(pdev, pwm);
> return 0;
> -
> -err_free_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 pxa_pwm_chip *chip;
> - struct resource *r;
>
> chip = platform_get_drvdata(pdev);
> if (chip == NULL)
> return -ENODEV;
>
> pwmchip_remove(&chip->chip);
> -
> - iounmap(chip->mmio_base);
> -
> - r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> - release_mem_region(r->start, resource_size(r));
> -
> - clk_put(chip->clk);
> - kfree(chip);
> return 0;

This should probably also be "return pwmchip_remove(...);". But that's
an unrelated change so I'll do that in a separate commit.

Thierry


Attachments:
(No filename) (2.95 kB)
(No filename) (836.00 B)
Download all attachments

2012-06-30 19:45:38

by Thierry Reding

[permalink] [raw]
Subject: Re: [PATCH 4/4] pwm: Convert pwm-vt8500 to use devm_* APIs

On Fri, Jun 29, 2012 at 09:33:05PM +0800, Axel Lin wrote:
> Signed-off-by: Axel Lin <[email protected]>
> ---
> drivers/pwm/pwm-vt8500.c | 45 ++++++++-------------------------------------
> 1 file changed, 8 insertions(+), 37 deletions(-)
>
> diff --git a/drivers/pwm/pwm-vt8500.c b/drivers/pwm/pwm-vt8500.c
[...]
> @@ -127,44 +127,24 @@ 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;
> - }
> -
> - 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;
> + return -ENODEV;
> }
>
> - chip->base = ioremap(r->start, resource_size(r));
> - if (chip->base == NULL) {
> - dev_err(&pdev->dev, "failed to ioremap() registers\n");
> - ret = -ENODEV;
> - goto err_free_mem;
> - }
> + chip->base = devm_request_and_ioremap(&pdev->dev, r);
> + if (chip->base == NULL)
> + return -ENODEV;

EADDRNOTAVAIL as well.

> @@ -172,16 +152,7 @@ static int __devexit pwm_remove(struct platform_device *pdev)
> return -ENODEV;
>
> err = pwmchip_remove(&chip->chip);
> - if (err < 0)
> - return err;
> -
> - iounmap(chip->base);
> -
> - r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> - release_mem_region(r->start, resource_size(r));
> -
> - kfree(chip);
> - return 0;
> + return err;

And merge these two remaining lines.

Thierry


Attachments:
(No filename) (1.53 kB)
(No filename) (836.00 B)
Download all attachments