All of lore.kernel.org
 help / color / mirror / Atom feed
From: Satendra Singh Thakur <sst2005@gmail.com>
To: unlisted-recipients:; (no To-header on input)
Cc: satendrasingh.thakur@hcl.com,
	Satendra Singh Thakur <sst2005@gmail.com>,
	Dan Williams <dan.j.williams@intel.com>,
	Vinod Koul <vkoul@kernel.org>,
	dmaengine@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 2/9] probe/dma/jz4740: removed redundant code from jz4740 dma controller's     probe function
Date: Sun, 15 Sep 2019 12:59:03 +0530	[thread overview]
Message-ID: <20190915072903.23522-1-sst2005@gmail.com> (raw)
In-Reply-To: <20190915072644.23329-1-sst2005@gmail.com>

1. In order to remove duplicate code, following functions:
devm_kzalloc
platform_get_resource
devm_ioremap_resource
clk_get
clk_prepare_enable
platform_get_irq
are replaced with a macro devm_platform_probe_helper_clk.

2. Added irq field in the struct jz4740_dma_dev.
Removed platform_get_irq from remove method.

3. This patch depends on the file include/linux/probe-helper.h
which is pushed in previous patch [01/09].

Signed-off-by: Satendra Singh Thakur <satendrasingh.thakur@hcl.com>
Signed-off-by: Satendra Singh Thakur <sst2005@gmail.com>
---
 drivers/dma/dma-jz4740.c | 33 +++++++++++++--------------------
 1 file changed, 13 insertions(+), 20 deletions(-)

diff --git a/drivers/dma/dma-jz4740.c b/drivers/dma/dma-jz4740.c
index 39c676c47082..b012896d02bb 100644
--- a/drivers/dma/dma-jz4740.c
+++ b/drivers/dma/dma-jz4740.c
@@ -15,6 +15,7 @@
 #include <linux/spinlock.h>
 #include <linux/irq.h>
 #include <linux/clk.h>
+#include <linux/probe-helper.h>
 
 #include "virt-dma.h"
 
@@ -121,6 +122,7 @@ struct jz4740_dma_dev {
 	struct dma_device ddev;
 	void __iomem *base;
 	struct clk *clk;
+	int irq;
 
 	struct jz4740_dmaengine_chan chan[JZ_DMA_NR_CHANS];
 };
@@ -519,27 +521,19 @@ static int jz4740_dma_probe(struct platform_device *pdev)
 	struct jz4740_dma_dev *dmadev;
 	struct dma_device *dd;
 	unsigned int i;
-	struct resource *res;
 	int ret;
-	int irq;
 
-	dmadev = devm_kzalloc(&pdev->dev, sizeof(*dmadev), GFP_KERNEL);
-	if (!dmadev)
-		return -EINVAL;
+	/*
+	 * This macro internally combines following functions:
+	 * devm_kzalloc, platform_get_resource, devm_ioremap_resource,
+	 * devm_clk_get, platform_get_irq, clk_prepare_enable
+	 */
+	ret = devm_platform_probe_helper_clk(pdev, dmadev, "dma");
+	if (ret < 0)
+		return ret;
 
 	dd = &dmadev->ddev;
 
-	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	dmadev->base = devm_ioremap_resource(&pdev->dev, res);
-	if (IS_ERR(dmadev->base))
-		return PTR_ERR(dmadev->base);
-
-	dmadev->clk = clk_get(&pdev->dev, "dma");
-	if (IS_ERR(dmadev->clk))
-		return PTR_ERR(dmadev->clk);
-
-	clk_prepare_enable(dmadev->clk);
-
 	dma_cap_set(DMA_SLAVE, dd->cap_mask);
 	dma_cap_set(DMA_CYCLIC, dd->cap_mask);
 	dd->device_free_chan_resources = jz4740_dma_free_chan_resources;
@@ -567,8 +561,8 @@ static int jz4740_dma_probe(struct platform_device *pdev)
 	if (ret)
 		goto err_clk;
 
-	irq = platform_get_irq(pdev, 0);
-	ret = request_irq(irq, jz4740_dma_irq, 0, dev_name(&pdev->dev), dmadev);
+	ret = request_irq(dmadev->irq, jz4740_dma_irq, 0,
+			dev_name(&pdev->dev), dmadev);
 	if (ret)
 		goto err_unregister;
 
@@ -598,9 +592,8 @@ static void jz4740_cleanup_vchan(struct dma_device *dmadev)
 static int jz4740_dma_remove(struct platform_device *pdev)
 {
 	struct jz4740_dma_dev *dmadev = platform_get_drvdata(pdev);
-	int irq = platform_get_irq(pdev, 0);
 
-	free_irq(irq, dmadev);
+	free_irq(dmadev->irq, dmadev);
 
 	jz4740_cleanup_vchan(&dmadev->ddev);
 	dma_async_device_unregister(&dmadev->ddev);
-- 
2.17.1


  reply	other threads:[~2019-09-15  7:29 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-15  7:00 [PATCH 0/9] added helper macros to remove duplicate code from probe functions of the platform drivers Satendra Singh Thakur
2019-09-15  7:00 ` Satendra Singh Thakur
2019-09-15  7:26 ` [PATCH 1/9] probe/dma : added helper macros to remove redundant/duplicate code from probe functions of the dma controller drivers Satendra Singh Thakur
2019-09-15  7:26   ` Satendra Singh Thakur
2019-09-15  7:29   ` Satendra Singh Thakur [this message]
2019-09-15  7:29   ` [PATCH 3/9] probe/dma/zx: removed redundant code from zx dma controller's probe function Satendra Singh Thakur
2019-09-15  7:29     ` Satendra Singh Thakur
2019-09-15  7:30   ` [PATCH 4/9] probe/dma/qcom-bam: removed redundant code from qcom bam " Satendra Singh Thakur
2019-09-15  7:30   ` [PATCH 5/9] probe/dma/mtk-hs: removed redundant code from mediatek hs " Satendra Singh Thakur
2019-09-15  7:30     ` Satendra Singh Thakur
2019-09-15  7:30     ` Satendra Singh Thakur
2019-09-15  7:31   ` [PATCH 6/9] probe/dma/sun6i: removed redundant code from sun6i " Satendra Singh Thakur
2019-09-15  7:31     ` Satendra Singh Thakur
2019-09-15  7:32   ` [PATCH 7/9] probe/dma/sun4i: removed redundant code from sun4i " Satendra Singh Thakur
2019-09-15  7:32     ` Satendra Singh Thakur
2019-09-15  7:32   ` [PATCH 8/9] probe/dma/axi: removed redundant code from axi " Satendra Singh Thakur
2019-09-15  7:32   ` [PATCH 9/9] probe/dma/owl: removed redundant code from owl " Satendra Singh Thakur
2019-09-15  7:32     ` Satendra Singh Thakur
2019-09-18 10:27 ` [PATCH 0/9] added helper macros to remove duplicate code from probe functions of the platform drivers Vinod Koul
2019-09-18 10:27   ` Vinod Koul
2019-09-21 14:57   ` Satendra Singh Thakur
2019-09-21 14:57     ` Satendra Singh Thakur
2019-09-24 19:27     ` Vinod Koul
2019-09-24 19:27       ` Vinod Koul

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190915072903.23522-1-sst2005@gmail.com \
    --to=sst2005@gmail.com \
    --cc=dan.j.williams@intel.com \
    --cc=dmaengine@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=satendrasingh.thakur@hcl.com \
    --cc=vkoul@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.