All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] iommu/msm: Switch to using managed resources
@ 2014-08-04 12:07 Pramod Gurav
       [not found] ` <1407154057-25440-1-git-send-email-pramod.gurav-edOiRQu9Xnj5XLMNweQjbQ@public.gmane.org>
  0 siblings, 1 reply; 3+ messages in thread
From: Pramod Gurav @ 2014-08-04 12:07 UTC (permalink / raw)
  To: iommu, linux-kernel, linux-arm-msm
  Cc: Pramod Gurav, Stepan Moskovchenko, Joerg Roedel, Stephen Boyd

This switches the driver to using managed resources to simplify error
handling and to do away with remove function.

CC: Stepan Moskovchenko <stepanm@codeaurora.org>
CC: Joerg Roedel <joro@8bytes.org>
CC: Stephen Boyd <sboyd@codeaurora.org>
Signed-off-by: Pramod Gurav <pramod.gurav@smartplayin.com>
---
 drivers/iommu/msm_iommu_dev.c |   76 +++++++++++------------------------------
 1 file changed, 19 insertions(+), 57 deletions(-)

diff --git a/drivers/iommu/msm_iommu_dev.c b/drivers/iommu/msm_iommu_dev.c
index 61def7cb..38a538f 100644
--- a/drivers/iommu/msm_iommu_dev.c
+++ b/drivers/iommu/msm_iommu_dev.c
@@ -140,39 +140,29 @@ static int msm_iommu_probe(struct platform_device *pdev)
 		return 0;
 	}
 
-	drvdata = kzalloc(sizeof(*drvdata), GFP_KERNEL);
-
-	if (!drvdata) {
-		ret = -ENOMEM;
-		goto fail;
-	}
+	if (!iommu_dev)
+		return -ENOMEM;
 
-	if (!iommu_dev) {
-		ret = -ENODEV;
-		goto fail;
-	}
+	drvdata = devm_kzalloc(&pdev->dev, sizeof(*drvdata), GFP_KERNEL);
+	if (!drvdata)
+		return -ENOMEM;
 
-	iommu_pclk = clk_get(NULL, "smmu_pclk");
-	if (IS_ERR(iommu_pclk)) {
-		ret = -ENODEV;
-		goto fail;
-	}
+	iommu_pclk = devm_clk_get(&pdev->dev, "smmu_pclk");
+	if (IS_ERR(iommu_pclk))
+		return -ENODEV;
 
 	ret = clk_prepare_enable(iommu_pclk);
 	if (ret)
-		goto fail_enable;
-
-	iommu_clk = clk_get(&pdev->dev, "iommu_clk");
+		return ret;
 
+	iommu_clk = devm_clk_get(&pdev->dev, "iommu_clk");
 	if (!IS_ERR(iommu_clk))	{
 		if (clk_get_rate(iommu_clk) == 0)
 			clk_set_rate(iommu_clk, 1);
 
 		ret = clk_prepare_enable(iommu_clk);
-		if (ret) {
-			clk_put(iommu_clk);
+		if (ret)
 			goto fail_pclk;
-		}
 	} else
 		iommu_clk = NULL;
 
@@ -205,14 +195,13 @@ static int msm_iommu_probe(struct platform_device *pdev)
 		goto fail_clk;
 	}
 
-	ret = request_irq(irq, msm_iommu_fault_handler, 0,
+	ret = devm_request_irq(&pdev->dev, irq, msm_iommu_fault_handler, 0,
 			"msm_iommu_secure_irpt_handler", drvdata);
 	if (ret) {
 		pr_err("Request IRQ %d failed with ret=%d\n", irq, ret);
 		goto fail_clk;
 	}
 
-
 	drvdata->pclk = iommu_pclk;
 	drvdata->clk = iommu_clk;
 	drvdata->base = regs_base;
@@ -231,16 +220,10 @@ static int msm_iommu_probe(struct platform_device *pdev)
 
 	return 0;
 fail_clk:
-	if (iommu_clk) {
+	if (iommu_clk)
 		clk_disable(iommu_clk);
-		clk_put(iommu_clk);
-	}
 fail_pclk:
 	clk_disable_unprepare(iommu_pclk);
-fail_enable:
-	clk_put(iommu_pclk);
-fail:
-	kfree(drvdata);
 	return ret;
 }
 
@@ -250,14 +233,9 @@ static int msm_iommu_remove(struct platform_device *pdev)
 
 	drv = platform_get_drvdata(pdev);
 	if (drv) {
-		if (drv->clk) {
+		if (drv->clk)
 			clk_unprepare(drv->clk);
-			clk_put(drv->clk);
-		}
 		clk_unprepare(drv->pclk);
-		clk_put(drv->pclk);
-		memset(drv, 0, sizeof(*drv));
-		kfree(drv);
 	}
 	return 0;
 }
@@ -276,7 +254,8 @@ static int msm_iommu_ctx_probe(struct platform_device *pdev)
 	if (!drvdata)
 		return -ENODEV;
 
-	ctx_drvdata = kzalloc(sizeof(*ctx_drvdata), GFP_KERNEL);
+	ctx_drvdata = devm_kzalloc(&pdev->dev, sizeof(*ctx_drvdata),
+				   GFP_KERNEL);
 	if (!ctx_drvdata)
 		return -ENOMEM;
 
@@ -288,14 +267,12 @@ static int msm_iommu_ctx_probe(struct platform_device *pdev)
 
 	ret = clk_prepare_enable(drvdata->pclk);
 	if (ret)
-		goto fail;
+		return ret;
 
 	if (drvdata->clk) {
 		ret = clk_prepare_enable(drvdata->clk);
-		if (ret) {
+		if (ret)
 			clk_disable_unprepare(drvdata->pclk);
-			goto fail;
-		}
 	}
 
 	/* Program the M2V tables for this context */
@@ -329,20 +306,6 @@ static int msm_iommu_ctx_probe(struct platform_device *pdev)
 
 	dev_info(&pdev->dev, "context %s using bank %d\n", c->name, c->num);
 	return 0;
-fail:
-	kfree(ctx_drvdata);
-	return ret;
-}
-
-static int msm_iommu_ctx_remove(struct platform_device *pdev)
-{
-	struct msm_iommu_ctx_drvdata *drv = NULL;
-	drv = platform_get_drvdata(pdev);
-	if (drv) {
-		memset(drv, 0, sizeof(struct msm_iommu_ctx_drvdata));
-		kfree(drv);
-	}
-	return 0;
 }
 
 static struct platform_driver msm_iommu_driver = {
@@ -350,7 +313,7 @@ static struct platform_driver msm_iommu_driver = {
 		.name	= "msm_iommu",
 	},
 	.probe		= msm_iommu_probe,
-	.remove		= msm_iommu_remove,
+	.remove         = msm_iommu_remove,
 };
 
 static struct platform_driver msm_iommu_ctx_driver = {
@@ -358,7 +321,6 @@ static struct platform_driver msm_iommu_ctx_driver = {
 		.name	= "msm_iommu_ctx",
 	},
 	.probe		= msm_iommu_ctx_probe,
-	.remove		= msm_iommu_ctx_remove,
 };
 
 static int __init msm_iommu_driver_init(void)
-- 
1.7.9.5

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

* Re: [PATCH] iommu/msm: Switch to using managed resources
  2014-08-04 12:07 [PATCH] iommu/msm: Switch to using managed resources Pramod Gurav
@ 2014-08-18 16:53     ` Joerg Roedel
  0 siblings, 0 replies; 3+ messages in thread
From: Joerg Roedel @ 2014-08-18 16:53 UTC (permalink / raw)
  To: Pramod Gurav
  Cc: linux-arm-msm-u79uwXL29TY76Z2rM5mHXA,
	iommu-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA, Stephen Boyd,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA, Stepan Moskovchenko

On Mon, Aug 04, 2014 at 05:37:37PM +0530, Pramod Gurav wrote:
> This switches the driver to using managed resources to simplify error
> handling and to do away with remove function.
> 
> CC: Stepan Moskovchenko <stepanm-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
> CC: Joerg Roedel <joro-zLv9SwRftAIdnm+yROfE0A@public.gmane.org>
> CC: Stephen Boyd <sboyd-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
> Signed-off-by: Pramod Gurav <pramod.gurav-edOiRQu9Xnj5XLMNweQjbQ@public.gmane.org>
> ---
>  drivers/iommu/msm_iommu_dev.c |   76 +++++++++++------------------------------
>  1 file changed, 19 insertions(+), 57 deletions(-)

How have you tested this?


	Joerg

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

* Re: [PATCH] iommu/msm: Switch to using managed resources
@ 2014-08-18 16:53     ` Joerg Roedel
  0 siblings, 0 replies; 3+ messages in thread
From: Joerg Roedel @ 2014-08-18 16:53 UTC (permalink / raw)
  To: Pramod Gurav
  Cc: iommu, linux-kernel, linux-arm-msm, Stepan Moskovchenko, Stephen Boyd

On Mon, Aug 04, 2014 at 05:37:37PM +0530, Pramod Gurav wrote:
> This switches the driver to using managed resources to simplify error
> handling and to do away with remove function.
> 
> CC: Stepan Moskovchenko <stepanm@codeaurora.org>
> CC: Joerg Roedel <joro@8bytes.org>
> CC: Stephen Boyd <sboyd@codeaurora.org>
> Signed-off-by: Pramod Gurav <pramod.gurav@smartplayin.com>
> ---
>  drivers/iommu/msm_iommu_dev.c |   76 +++++++++++------------------------------
>  1 file changed, 19 insertions(+), 57 deletions(-)

How have you tested this?


	Joerg


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

end of thread, other threads:[~2014-08-18 16:53 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-04 12:07 [PATCH] iommu/msm: Switch to using managed resources Pramod Gurav
     [not found] ` <1407154057-25440-1-git-send-email-pramod.gurav-edOiRQu9Xnj5XLMNweQjbQ@public.gmane.org>
2014-08-18 16:53   ` Joerg Roedel
2014-08-18 16:53     ` Joerg Roedel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.