2013-05-02 12:09:56

by Peter Ujfalusi

[permalink] [raw]
Subject: [PATCH 0/5] drivers: bus: omap_l3: Conversion to devm_*

Hi,

Cleanup of platform probe and remove (removing the remove function at the end)
with converting the driver to use the devm_* versions kzalloc, ioremap and
request_irq.

Regards,
Peter
---
Peter Ujfalusi (5):
drivers: bus: omap_l3: Convert to use devm_kzalloc
drivers: bus: omap_l3: Convert to use devm_request_and_ioremap()
drivers: bus: omap_l3: Convert to use devm_request_irq()
drivers: bus: omap_l3: Remove the platform driver's remove function
drivers: bus: omap_l3: Change pr_crit() to dev_err() when IRQ request
fails

drivers/bus/omap_l3_noc.c | 106 +++++++++++-----------------------------------
1 file changed, 24 insertions(+), 82 deletions(-)

--
1.8.2.1


2013-05-02 12:10:09

by Peter Ujfalusi

[permalink] [raw]
Subject: [PATCH 5/5] drivers: bus: omap_l3: Change pr_crit() to dev_err() when IRQ request fails

Use dev_err() which will going to print the driver's name as well and the
KERN_ERR level is sufficient in this case (we also print via dev_err when
there is an error with the mem resources)

Signed-off-by: Peter Ujfalusi <[email protected]>
---
drivers/bus/omap_l3_noc.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/bus/omap_l3_noc.c b/drivers/bus/omap_l3_noc.c
index ed428ad..3a36e3e 100644
--- a/drivers/bus/omap_l3_noc.c
+++ b/drivers/bus/omap_l3_noc.c
@@ -162,8 +162,8 @@ static int omap4_l3_probe(struct platform_device *pdev)
ret = devm_request_irq(&pdev->dev, l3->debug_irq, l3_interrupt_handler,
IRQF_DISABLED, "l3-dbg-irq", l3);
if (ret) {
- pr_crit("L3: request_irq failed to register for 0x%x\n",
- l3->debug_irq);
+ dev_err(&pdev->dev, "request_irq failed for %d\n",
+ l3->debug_irq);
return ret;
}

@@ -171,8 +171,7 @@ static int omap4_l3_probe(struct platform_device *pdev)
ret = devm_request_irq(&pdev->dev, l3->app_irq, l3_interrupt_handler,
IRQF_DISABLED, "l3-app-irq", l3);
if (ret)
- pr_crit("L3: request_irq failed to register for 0x%x\n",
- l3->app_irq);
+ dev_err(&pdev->dev, "request_irq failed for %d\n", l3->app_irq);

return ret;
}
--
1.8.2.1

2013-05-02 12:10:04

by Peter Ujfalusi

[permalink] [raw]
Subject: [PATCH 1/5] drivers: bus: omap_l3: Convert to use devm_kzalloc

We can remove the kfree() calls from probe and remove.

Signed-off-by: Peter Ujfalusi <[email protected]>
---
drivers/bus/omap_l3_noc.c | 11 +++--------
1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/drivers/bus/omap_l3_noc.c b/drivers/bus/omap_l3_noc.c
index feeecae..d25d727 100644
--- a/drivers/bus/omap_l3_noc.c
+++ b/drivers/bus/omap_l3_noc.c
@@ -134,7 +134,7 @@ static int omap4_l3_probe(struct platform_device *pdev)
struct resource *res;
int ret;

- l3 = kzalloc(sizeof(*l3), GFP_KERNEL);
+ l3 = devm_kzalloc(&pdev->dev, sizeof(*l3), GFP_KERNEL);
if (!l3)
return -ENOMEM;

@@ -142,15 +142,13 @@ static int omap4_l3_probe(struct platform_device *pdev)
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) {
dev_err(&pdev->dev, "couldn't find resource 0\n");
- ret = -ENODEV;
- goto err0;
+ return -ENODEV;
}

l3->l3_base[0] = ioremap(res->start, resource_size(res));
if (!l3->l3_base[0]) {
dev_err(&pdev->dev, "ioremap failed\n");
- ret = -ENOMEM;
- goto err0;
+ return -ENOMEM;
}

res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
@@ -214,8 +212,6 @@ err2:
iounmap(l3->l3_base[1]);
err1:
iounmap(l3->l3_base[0]);
-err0:
- kfree(l3);
return ret;
}

@@ -228,7 +224,6 @@ static int omap4_l3_remove(struct platform_device *pdev)
iounmap(l3->l3_base[0]);
iounmap(l3->l3_base[1]);
iounmap(l3->l3_base[2]);
- kfree(l3);

return 0;
}
--
1.8.2.1

2013-05-02 12:10:46

by Peter Ujfalusi

[permalink] [raw]
Subject: [PATCH 4/5] drivers: bus: omap_l3: Remove the platform driver's remove function

It is NOP after the devm_* conversion.

Signed-off-by: Peter Ujfalusi <[email protected]>
---
drivers/bus/omap_l3_noc.c | 6 ------
1 file changed, 6 deletions(-)

diff --git a/drivers/bus/omap_l3_noc.c b/drivers/bus/omap_l3_noc.c
index 2bbc87b..ed428ad 100644
--- a/drivers/bus/omap_l3_noc.c
+++ b/drivers/bus/omap_l3_noc.c
@@ -177,11 +177,6 @@ static int omap4_l3_probe(struct platform_device *pdev)
return ret;
}

-static int omap4_l3_remove(struct platform_device *pdev)
-{
- return 0;
-}
-
#if defined(CONFIG_OF)
static const struct of_device_id l3_noc_match[] = {
{.compatible = "ti,omap4-l3-noc", },
@@ -194,7 +189,6 @@ MODULE_DEVICE_TABLE(of, l3_noc_match);

static struct platform_driver omap4_l3_driver = {
.probe = omap4_l3_probe,
- .remove = omap4_l3_remove,
.driver = {
.name = "omap_l3_noc",
.owner = THIS_MODULE,
--
1.8.2.1

2013-05-02 12:10:02

by Peter Ujfalusi

[permalink] [raw]
Subject: [PATCH 2/5] drivers: bus: omap_l3: Convert to use devm_request_and_ioremap()

We can then remove the iounmap() calls from probe and remove.
Since the driver requests the resources via index we can do the mem resource
request within a for loop.

Signed-off-by: Peter Ujfalusi <[email protected]>
---
drivers/bus/omap_l3_noc.c | 63 +++++++++++------------------------------------
1 file changed, 15 insertions(+), 48 deletions(-)

diff --git a/drivers/bus/omap_l3_noc.c b/drivers/bus/omap_l3_noc.c
index d25d727..ca95d3d 100644
--- a/drivers/bus/omap_l3_noc.c
+++ b/drivers/bus/omap_l3_noc.c
@@ -131,52 +131,28 @@ static irqreturn_t l3_interrupt_handler(int irq, void *_l3)
static int omap4_l3_probe(struct platform_device *pdev)
{
static struct omap4_l3 *l3;
- struct resource *res;
- int ret;
+ int ret, i;

l3 = devm_kzalloc(&pdev->dev, sizeof(*l3), GFP_KERNEL);
if (!l3)
return -ENOMEM;

platform_set_drvdata(pdev, l3);
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- if (!res) {
- dev_err(&pdev->dev, "couldn't find resource 0\n");
- return -ENODEV;
- }
-
- l3->l3_base[0] = ioremap(res->start, resource_size(res));
- if (!l3->l3_base[0]) {
- dev_err(&pdev->dev, "ioremap failed\n");
- return -ENOMEM;
- }
-
- res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
- if (!res) {
- dev_err(&pdev->dev, "couldn't find resource 1\n");
- ret = -ENODEV;
- goto err1;
- }

- l3->l3_base[1] = ioremap(res->start, resource_size(res));
- if (!l3->l3_base[1]) {
- dev_err(&pdev->dev, "ioremap failed\n");
- ret = -ENOMEM;
- goto err1;
- }
-
- res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
- if (!res) {
- dev_err(&pdev->dev, "couldn't find resource 2\n");
- ret = -ENODEV;
- goto err2;
- }
+ /* Get mem resources */
+ for (i = 0; i < 3; i++) {
+ struct resource *res = platform_get_resource(pdev,
+ IORESOURCE_MEM, i);
+ if (!res) {
+ dev_err(&pdev->dev, "couldn't find resource %d\n", i);
+ return -ENODEV;
+ }

- l3->l3_base[2] = ioremap(res->start, resource_size(res));
- if (!l3->l3_base[2]) {
- dev_err(&pdev->dev, "ioremap failed\n");
- ret = -ENOMEM;
- goto err2;
+ l3->l3_base[i] = devm_request_and_ioremap(&pdev->dev, res);
+ if (!l3->l3_base[i]) {
+ dev_err(&pdev->dev, "ioremap %d failed\n", i);
+ return -ENOMEM;
+ }
}

/*
@@ -189,7 +165,7 @@ static int omap4_l3_probe(struct platform_device *pdev)
if (ret) {
pr_crit("L3: request_irq failed to register for 0x%x\n",
l3->debug_irq);
- goto err3;
+ return ret;
}

l3->app_irq = platform_get_irq(pdev, 1);
@@ -206,12 +182,6 @@ static int omap4_l3_probe(struct platform_device *pdev)

err4:
free_irq(l3->debug_irq, l3);
-err3:
- iounmap(l3->l3_base[2]);
-err2:
- iounmap(l3->l3_base[1]);
-err1:
- iounmap(l3->l3_base[0]);
return ret;
}

@@ -221,9 +191,6 @@ static int omap4_l3_remove(struct platform_device *pdev)

free_irq(l3->app_irq, l3);
free_irq(l3->debug_irq, l3);
- iounmap(l3->l3_base[0]);
- iounmap(l3->l3_base[1]);
- iounmap(l3->l3_base[2]);

return 0;
}
--
1.8.2.1

2013-05-02 12:11:28

by Peter Ujfalusi

[permalink] [raw]
Subject: [PATCH 3/5] drivers: bus: omap_l3: Convert to use devm_request_irq()

With this we can remove the free_irq() calls from probe and remove.

Signed-off-by: Peter Ujfalusi <[email protected]>
---
drivers/bus/omap_l3_noc.c | 23 +++++------------------
1 file changed, 5 insertions(+), 18 deletions(-)

diff --git a/drivers/bus/omap_l3_noc.c b/drivers/bus/omap_l3_noc.c
index ca95d3d..2bbc87b 100644
--- a/drivers/bus/omap_l3_noc.c
+++ b/drivers/bus/omap_l3_noc.c
@@ -159,9 +159,8 @@ static int omap4_l3_probe(struct platform_device *pdev)
* Setup interrupt Handlers
*/
l3->debug_irq = platform_get_irq(pdev, 0);
- ret = request_irq(l3->debug_irq,
- l3_interrupt_handler,
- IRQF_DISABLED, "l3-dbg-irq", l3);
+ ret = devm_request_irq(&pdev->dev, l3->debug_irq, l3_interrupt_handler,
+ IRQF_DISABLED, "l3-dbg-irq", l3);
if (ret) {
pr_crit("L3: request_irq failed to register for 0x%x\n",
l3->debug_irq);
@@ -169,29 +168,17 @@ static int omap4_l3_probe(struct platform_device *pdev)
}

l3->app_irq = platform_get_irq(pdev, 1);
- ret = request_irq(l3->app_irq,
- l3_interrupt_handler,
- IRQF_DISABLED, "l3-app-irq", l3);
- if (ret) {
+ ret = devm_request_irq(&pdev->dev, l3->app_irq, l3_interrupt_handler,
+ IRQF_DISABLED, "l3-app-irq", l3);
+ if (ret)
pr_crit("L3: request_irq failed to register for 0x%x\n",
l3->app_irq);
- goto err4;
- }
-
- return 0;

-err4:
- free_irq(l3->debug_irq, l3);
return ret;
}

static int omap4_l3_remove(struct platform_device *pdev)
{
- struct omap4_l3 *l3 = platform_get_drvdata(pdev);
-
- free_irq(l3->app_irq, l3);
- free_irq(l3->debug_irq, l3);
-
return 0;
}

--
1.8.2.1

2013-05-07 12:51:47

by Santosh Shilimkar

[permalink] [raw]
Subject: Re: [PATCH 0/5] drivers: bus: omap_l3: Conversion to devm_*

On Thursday 02 May 2013 05:39 PM, Peter Ujfalusi wrote:
> Hi,
>
> Cleanup of platform probe and remove (removing the remove function at the end)
> with converting the driver to use the devm_* versions kzalloc, ioremap and
> request_irq.
>
Thanks Peter. All patches looks fine to my eyes. In the last patch wher
you are changing the error level is bit debatable but I agree with you.

So FWIW,
Reviewed-by: Santosh Shilimkar <[email protected]>


> Peter Ujfalusi (5):
> drivers: bus: omap_l3: Convert to use devm_kzalloc
> drivers: bus: omap_l3: Convert to use devm_request_and_ioremap()
> drivers: bus: omap_l3: Convert to use devm_request_irq()
> drivers: bus: omap_l3: Remove the platform driver's remove function
> drivers: bus: omap_l3: Change pr_crit() to dev_err() when IRQ request
> fails
>
> drivers/bus/omap_l3_noc.c | 106 +++++++++++-----------------------------------
> 1 file changed, 24 insertions(+), 82 deletions(-)
>