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@xxxxxxx> Signed-off-by: Satendra Singh Thakur <sst2005@xxxxxxxxx> --- 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