2014-04-01 13:24:24

by Peter Ujfalusi

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

Hi,

Changes since v3:
- Tony's ack added

Changes since v2:
Comments from Alexander Shiyan addressed:
- Do not check the return of platform_get_resource() - no need to do that
- Use devm_ioremap_resource() instead devm_request_and_ioremap()

Changes since v1:
- Fixed Santosh's email address in the commit messages.

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.

This is a resend of an old series which I found when doing some spring cleanup
on my HDD:
http://www.spinics.net/lists/linux-omap/msg90531.html

Regards,
Peter
---
Peter Ujfalusi (5):
drivers: bus: omap_l3: Convert to use devm_kzalloc
drivers: bus: omap_l3: Convert to use devm_ioremap_resource()
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 | 102 +++++++++-------------------------------------
1 file changed, 20 insertions(+), 82 deletions(-)

--
1.9.1


2014-04-01 13:24:27

by Peter Ujfalusi

[permalink] [raw]
Subject: [PATCH v4 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]>
Reviewed-by: Santosh Shilimkar <[email protected]>
Acked-by: Tony Lindgren <[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 feeecae623f6..d25d727e7cfb 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.9.1

2014-04-01 13:24:38

by Peter Ujfalusi

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

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]>
Reviewed-by: Santosh Shilimkar <[email protected]>
Acked-by: Tony Lindgren <[email protected]>
---
drivers/bus/omap_l3_noc.c | 59 +++++++++--------------------------------------
1 file changed, 11 insertions(+), 48 deletions(-)

diff --git a/drivers/bus/omap_l3_noc.c b/drivers/bus/omap_l3_noc.c
index d25d727e7cfb..6f58be3c2f76 100644
--- a/drivers/bus/omap_l3_noc.c
+++ b/drivers/bus/omap_l3_noc.c
@@ -131,52 +131,24 @@ 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 < L3_MODULES; i++) {
+ struct resource *res = platform_get_resource(pdev,
+ IORESOURCE_MEM, i);

- 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_ioremap_resource(&pdev->dev, res);
+ if (IS_ERR(l3->l3_base[i])) {
+ dev_err(&pdev->dev, "ioremap %d failed\n", i);
+ return PTR_ERR(l3->l3_base[i]);
+ }
}

/*
@@ -189,7 +161,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 +178,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 +187,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.9.1

2014-04-01 13:24:36

by Peter Ujfalusi

[permalink] [raw]
Subject: [PATCH v4 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]>
Reviewed-by: Santosh Shilimkar <[email protected]>
Acked-by: Tony Lindgren <[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 6f58be3c2f76..25bcb60be880 100644
--- a/drivers/bus/omap_l3_noc.c
+++ b/drivers/bus/omap_l3_noc.c
@@ -155,9 +155,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);
@@ -165,29 +164,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.9.1

2014-04-01 13:25:11

by Peter Ujfalusi

[permalink] [raw]
Subject: [PATCH v4 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]>
Reviewed-by: Santosh Shilimkar <[email protected]>
Acked-by: Tony Lindgren <[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 25bcb60be880..0eff48585ae3 100644
--- a/drivers/bus/omap_l3_noc.c
+++ b/drivers/bus/omap_l3_noc.c
@@ -173,11 +173,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", },
@@ -190,7 +185,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.9.1

2014-04-01 13:24:34

by Peter Ujfalusi

[permalink] [raw]
Subject: [PATCH v4 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]>
Reviewed-by: Santosh Shilimkar <[email protected]>
Acked-by: Tony Lindgren <[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 0eff48585ae3..972691a668a3 100644
--- a/drivers/bus/omap_l3_noc.c
+++ b/drivers/bus/omap_l3_noc.c
@@ -158,8 +158,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;
}

@@ -167,8 +167,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.9.1