public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] bus: omap_l3_noc.c: use devm functions
@ 2014-05-22 23:32 abdoulaye berthe
  2014-05-23 13:07 ` abdoulaye berthe
  0 siblings, 1 reply; 2+ messages in thread
From: abdoulaye berthe @ 2014-05-22 23:32 UTC (permalink / raw)
  To: berthe.ab, linux-kernel

This uses devm function to ease mem alloc

Signed-off-by: abdoulaye berthe <berthe.ab@gmail.com>
---
 drivers/bus/omap_l3_noc.c | 73 +++++++++++------------------------------------
 1 file changed, 17 insertions(+), 56 deletions(-)

diff --git a/drivers/bus/omap_l3_noc.c b/drivers/bus/omap_l3_noc.c
index feeecae..e8bcc8f 100644
--- a/drivers/bus/omap_l3_noc.c
+++ b/drivers/bus/omap_l3_noc.c
@@ -133,53 +133,28 @@ static int omap4_l3_probe(struct platform_device *pdev)
 	static struct omap4_l3 *l3;
 	struct resource	*res;
 	int ret;
+	struct device *dev = &pdev->dev;
 
-	l3 = kzalloc(sizeof(*l3), GFP_KERNEL);
+	l3 = devm_kzalloc(dev, sizeof(struct omap4_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");
-		ret = -ENODEV;
-		goto err0;
-	}
 
-	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;
-	}
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	l3->l3_base[0] = devm_ioremap(dev, res->start, resource_size(res));
+	if (IS_ERR(l3->l3_base[0]))
+		return PTR_ERR(l3->l3_base[0]);
 
 	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;
-	}
+	l3->l3_base[1] = devm_ioremap(dev, res->start, resource_size(res));
+	if (IS_ERR(l3->l3_base[1]))
+		return PTR_ERR(l3->l3_base[1]);
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
-	if (!res) {
-		dev_err(&pdev->dev, "couldn't find resource 2\n");
-		ret = -ENODEV;
-		goto err2;
-	}
-
-	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[2] = devm_ioremap(dev, res->start, resource_size(res));
+	if (IS_ERR(l3->l3_base[2]))
+		return PTR_ERR(l3->l3_base[2]);
 
 	/*
 	 * Setup interrupt Handlers
@@ -191,7 +166,8 @@ 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;
+		free_irq(l3->debug_irq, l3);
+		return ret;
 	}
 
 	l3->app_irq = platform_get_irq(pdev, 1);
@@ -201,22 +177,11 @@ static int omap4_l3_probe(struct platform_device *pdev)
 	if (ret) {
 		pr_crit("L3: request_irq failed to register for 0x%x\n",
 						l3->app_irq);
-		goto err4;
+		free_irq(l3->app_irq, l3);
+		free_irq(l3->debug_irq, l3);
+		return ret;
 	}
-
 	return 0;
-
-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]);
-err0:
-	kfree(l3);
-	return ret;
 }
 
 static int omap4_l3_remove(struct platform_device *pdev)
@@ -225,10 +190,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]);
-	kfree(l3);
 
 	return 0;
 }
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [PATCH] bus: omap_l3_noc.c: use devm functions
  2014-05-22 23:32 [PATCH] bus: omap_l3_noc.c: use devm functions abdoulaye berthe
@ 2014-05-23 13:07 ` abdoulaye berthe
  0 siblings, 0 replies; 2+ messages in thread
From: abdoulaye berthe @ 2014-05-23 13:07 UTC (permalink / raw)
  To: berthe.ab, linux-kernel

This uses devm function to ease mem alloc

Signed-off-by: abdoulaye berthe <berthe.ab@gmail.com>
---
 drivers/bus/omap_l3_noc.c | 85 +++++++++++++----------------------------------
 1 file changed, 23 insertions(+), 62 deletions(-)

diff --git a/drivers/bus/omap_l3_noc.c b/drivers/bus/omap_l3_noc.c
index feeecae..b496d3d 100644
--- a/drivers/bus/omap_l3_noc.c
+++ b/drivers/bus/omap_l3_noc.c
@@ -133,90 +133,55 @@ static int omap4_l3_probe(struct platform_device *pdev)
 	static struct omap4_l3 *l3;
 	struct resource	*res;
 	int ret;
+	struct device *dev = &pdev->dev;
 
-	l3 = kzalloc(sizeof(*l3), GFP_KERNEL);
+	l3 = devm_kzalloc(dev, sizeof(struct omap4_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");
-		ret = -ENODEV;
-		goto err0;
-	}
 
-	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;
-	}
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	l3->l3_base[0] = devm_ioremap(dev, res->start, resource_size(res));
+	if (IS_ERR(l3->l3_base[0]))
+		return PTR_ERR(l3->l3_base[0]);
 
 	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;
-	}
+	l3->l3_base[1] = devm_ioremap(dev, res->start, resource_size(res));
+	if (IS_ERR(l3->l3_base[1]))
+		return PTR_ERR(l3->l3_base[1]);
 
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 2);
-	if (!res) {
-		dev_err(&pdev->dev, "couldn't find resource 2\n");
-		ret = -ENODEV;
-		goto err2;
-	}
-
-	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[2] = devm_ioremap(dev, res->start, resource_size(res));
+	if (IS_ERR(l3->l3_base[2]))
+		return PTR_ERR(l3->l3_base[2]);
 
 	/*
 	 * 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);
+			  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);
-		goto err3;
+			l3->debug_irq);
+		free_irq(l3->debug_irq, l3);
+		return ret;
 	}
 
 	l3->app_irq = platform_get_irq(pdev, 1);
 	ret = request_irq(l3->app_irq,
-			l3_interrupt_handler,
-			IRQF_DISABLED, "l3-app-irq", l3);
+			  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;
+			l3->app_irq);
+		free_irq(l3->app_irq, l3);
+		free_irq(l3->debug_irq, l3);
+		return ret;
 	}
-
 	return 0;
-
-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]);
-err0:
-	kfree(l3);
-	return ret;
 }
 
 static int omap4_l3_remove(struct platform_device *pdev)
@@ -225,10 +190,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]);
-	kfree(l3);
 
 	return 0;
 }
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-05-23 13:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-22 23:32 [PATCH] bus: omap_l3_noc.c: use devm functions abdoulaye berthe
2014-05-23 13:07 ` abdoulaye berthe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox