All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] dma: coh901318: use devm allocation
@ 2012-06-12 18:19 Linus Walleij
  2012-06-14  3:13 ` Vinod Koul
  0 siblings, 1 reply; 2+ messages in thread
From: Linus Walleij @ 2012-06-12 18:19 UTC (permalink / raw)
  To: Vinod Koul; +Cc: linux-kernel, Dan Williams, Linus Walleij

From: Linus Walleij <linus.walleij@linaro.org>

Allocate memory, region, remap and irq for device state using
devm_* helpers to simplify memory accounting.

Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/dma/coh901318.c |   72 ++++++++++++++++-------------------------------
 1 file changed, 24 insertions(+), 48 deletions(-)

diff --git a/drivers/dma/coh901318.c b/drivers/dma/coh901318.c
index e67b4e0..aa384e5 100644
--- a/drivers/dma/coh901318.c
+++ b/drivers/dma/coh901318.c
@@ -1438,34 +1438,32 @@ static int __init coh901318_probe(struct platform_device *pdev)
 
 	io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!io)
-		goto err_get_resource;
+		return -ENODEV;
 
 	/* Map DMA controller registers to virtual memory */
-	if (request_mem_region(io->start,
-			       resource_size(io),
-			       pdev->dev.driver->name) == NULL) {
-		err = -EBUSY;
-		goto err_request_mem;
-	}
+	if (devm_request_mem_region(&pdev->dev,
+				    io->start,
+				    resource_size(io),
+				    pdev->dev.driver->name) == NULL)
+		return -ENOMEM;
 
 	pdata = pdev->dev.platform_data;
 	if (!pdata)
-		goto err_no_platformdata;
+		return -ENODEV;
 
-	base = kmalloc(ALIGN(sizeof(struct coh901318_base), 4) +
-		       pdata->max_channels *
-		       sizeof(struct coh901318_chan),
-		       GFP_KERNEL);
+	base = devm_kzalloc(&pdev->dev,
+			    ALIGN(sizeof(struct coh901318_base), 4) +
+			    pdata->max_channels *
+			    sizeof(struct coh901318_chan),
+			    GFP_KERNEL);
 	if (!base)
-		goto err_alloc_coh_dma_channels;
+		return -ENOMEM;
 
 	base->chans = ((void *)base) + ALIGN(sizeof(struct coh901318_base), 4);
 
-	base->virtbase = ioremap(io->start, resource_size(io));
-	if (!base->virtbase) {
-		err = -ENOMEM;
-		goto err_no_ioremap;
-	}
+	base->virtbase = devm_ioremap(&pdev->dev, io->start, resource_size(io));
+	if (!base->virtbase)
+		return -ENOMEM;
 
 	base->dev = &pdev->dev;
 	base->platform = pdata;
@@ -1474,25 +1472,20 @@ static int __init coh901318_probe(struct platform_device *pdev)
 
 	COH901318_DEBUGFS_ASSIGN(debugfs_dma_base, base);
 
-	platform_set_drvdata(pdev, base);
-
 	irq = platform_get_irq(pdev, 0);
 	if (irq < 0)
-		goto err_no_irq;
-
-	err = request_irq(irq, dma_irq_handler, IRQF_DISABLED,
-			  "coh901318", base);
-	if (err) {
-		dev_crit(&pdev->dev,
-			 "Cannot allocate IRQ for DMA controller!\n");
-		goto err_request_irq;
-	}
+		return irq;
+
+	err = devm_request_irq(&pdev->dev, irq, dma_irq_handler, IRQF_DISABLED,
+			       "coh901318", base);
+	if (err)
+		return err;
 
 	err = coh901318_pool_create(&base->pool, &pdev->dev,
 				    sizeof(struct coh901318_lli),
 				    32);
 	if (err)
-		goto err_pool_create;
+		return err;
 
 	/* init channels for device transfers */
 	coh901318_base_init(&base->dma_slave,  base->platform->chans_slave,
@@ -1538,6 +1531,7 @@ static int __init coh901318_probe(struct platform_device *pdev)
 	if (err)
 		goto err_register_memcpy;
 
+	platform_set_drvdata(pdev, base);
 	dev_info(&pdev->dev, "Initialized COH901318 DMA on virtual base 0x%08x\n",
 		(u32) base->virtbase);
 
@@ -1547,19 +1541,6 @@ static int __init coh901318_probe(struct platform_device *pdev)
 	dma_async_device_unregister(&base->dma_slave);
  err_register_slave:
 	coh901318_pool_destroy(&base->pool);
- err_pool_create:
-	free_irq(platform_get_irq(pdev, 0), base);
- err_request_irq:
- err_no_irq:
-	iounmap(base->virtbase);
- err_no_ioremap:
-	kfree(base);
- err_alloc_coh_dma_channels:
- err_no_platformdata:
-	release_mem_region(pdev->resource->start,
-			   resource_size(pdev->resource));
- err_request_mem:
- err_get_resource:
 	return err;
 }
 
@@ -1570,11 +1551,6 @@ static int __exit coh901318_remove(struct platform_device *pdev)
 	dma_async_device_unregister(&base->dma_memcpy);
 	dma_async_device_unregister(&base->dma_slave);
 	coh901318_pool_destroy(&base->pool);
-	free_irq(platform_get_irq(pdev, 0), base);
-	iounmap(base->virtbase);
-	kfree(base);
-	release_mem_region(pdev->resource->start,
-			   resource_size(pdev->resource));
 	return 0;
 }
 
-- 
1.7.9.2


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

* Re: [PATCH] dma: coh901318: use devm allocation
  2012-06-12 18:19 [PATCH] dma: coh901318: use devm allocation Linus Walleij
@ 2012-06-14  3:13 ` Vinod Koul
  0 siblings, 0 replies; 2+ messages in thread
From: Vinod Koul @ 2012-06-14  3:13 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-kernel, Dan Williams, Linus Walleij

On Tue, 2012-06-12 at 20:19 +0200, Linus Walleij wrote:
> From: Linus Walleij <linus.walleij@linaro.org>
> 
> Allocate memory, region, remap and irq for device state using
> devm_* helpers to simplify memory accounting.
> 
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Applied, thanks

> ---
>  drivers/dma/coh901318.c |   72 ++++++++++++++++-------------------------------
>  1 file changed, 24 insertions(+), 48 deletions(-)
> 
> diff --git a/drivers/dma/coh901318.c b/drivers/dma/coh901318.c
> index e67b4e0..aa384e5 100644
> --- a/drivers/dma/coh901318.c
> +++ b/drivers/dma/coh901318.c
> @@ -1438,34 +1438,32 @@ static int __init coh901318_probe(struct platform_device *pdev)
>  
>  	io = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>  	if (!io)
> -		goto err_get_resource;
> +		return -ENODEV;
>  
>  	/* Map DMA controller registers to virtual memory */
> -	if (request_mem_region(io->start,
> -			       resource_size(io),
> -			       pdev->dev.driver->name) == NULL) {
> -		err = -EBUSY;
> -		goto err_request_mem;
> -	}
> +	if (devm_request_mem_region(&pdev->dev,
> +				    io->start,
> +				    resource_size(io),
> +				    pdev->dev.driver->name) == NULL)
> +		return -ENOMEM;
>  
>  	pdata = pdev->dev.platform_data;
>  	if (!pdata)
> -		goto err_no_platformdata;
> +		return -ENODEV;
>  
> -	base = kmalloc(ALIGN(sizeof(struct coh901318_base), 4) +
> -		       pdata->max_channels *
> -		       sizeof(struct coh901318_chan),
> -		       GFP_KERNEL);
> +	base = devm_kzalloc(&pdev->dev,
> +			    ALIGN(sizeof(struct coh901318_base), 4) +
> +			    pdata->max_channels *
> +			    sizeof(struct coh901318_chan),
> +			    GFP_KERNEL);
>  	if (!base)
> -		goto err_alloc_coh_dma_channels;
> +		return -ENOMEM;
>  
>  	base->chans = ((void *)base) + ALIGN(sizeof(struct coh901318_base), 4);
>  
> -	base->virtbase = ioremap(io->start, resource_size(io));
> -	if (!base->virtbase) {
> -		err = -ENOMEM;
> -		goto err_no_ioremap;
> -	}
> +	base->virtbase = devm_ioremap(&pdev->dev, io->start, resource_size(io));
> +	if (!base->virtbase)
> +		return -ENOMEM;
>  
>  	base->dev = &pdev->dev;
>  	base->platform = pdata;
> @@ -1474,25 +1472,20 @@ static int __init coh901318_probe(struct platform_device *pdev)
>  
>  	COH901318_DEBUGFS_ASSIGN(debugfs_dma_base, base);
>  
> -	platform_set_drvdata(pdev, base);
> -
>  	irq = platform_get_irq(pdev, 0);
>  	if (irq < 0)
> -		goto err_no_irq;
> -
> -	err = request_irq(irq, dma_irq_handler, IRQF_DISABLED,
> -			  "coh901318", base);
> -	if (err) {
> -		dev_crit(&pdev->dev,
> -			 "Cannot allocate IRQ for DMA controller!\n");
> -		goto err_request_irq;
> -	}
> +		return irq;
> +
> +	err = devm_request_irq(&pdev->dev, irq, dma_irq_handler, IRQF_DISABLED,
> +			       "coh901318", base);
> +	if (err)
> +		return err;
>  
>  	err = coh901318_pool_create(&base->pool, &pdev->dev,
>  				    sizeof(struct coh901318_lli),
>  				    32);
>  	if (err)
> -		goto err_pool_create;
> +		return err;
>  
>  	/* init channels for device transfers */
>  	coh901318_base_init(&base->dma_slave,  base->platform->chans_slave,
> @@ -1538,6 +1531,7 @@ static int __init coh901318_probe(struct platform_device *pdev)
>  	if (err)
>  		goto err_register_memcpy;
>  
> +	platform_set_drvdata(pdev, base);
>  	dev_info(&pdev->dev, "Initialized COH901318 DMA on virtual base 0x%08x\n",
>  		(u32) base->virtbase);
>  
> @@ -1547,19 +1541,6 @@ static int __init coh901318_probe(struct platform_device *pdev)
>  	dma_async_device_unregister(&base->dma_slave);
>   err_register_slave:
>  	coh901318_pool_destroy(&base->pool);
> - err_pool_create:
> -	free_irq(platform_get_irq(pdev, 0), base);
> - err_request_irq:
> - err_no_irq:
> -	iounmap(base->virtbase);
> - err_no_ioremap:
> -	kfree(base);
> - err_alloc_coh_dma_channels:
> - err_no_platformdata:
> -	release_mem_region(pdev->resource->start,
> -			   resource_size(pdev->resource));
> - err_request_mem:
> - err_get_resource:
>  	return err;
>  }
>  
> @@ -1570,11 +1551,6 @@ static int __exit coh901318_remove(struct platform_device *pdev)
>  	dma_async_device_unregister(&base->dma_memcpy);
>  	dma_async_device_unregister(&base->dma_slave);
>  	coh901318_pool_destroy(&base->pool);
> -	free_irq(platform_get_irq(pdev, 0), base);
> -	iounmap(base->virtbase);
> -	kfree(base);
> -	release_mem_region(pdev->resource->start,
> -			   resource_size(pdev->resource));
>  	return 0;
>  }
>  
> -- 
> 1.7.9.2
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/


-- 
~Vinod


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

end of thread, other threads:[~2012-06-14  3:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-12 18:19 [PATCH] dma: coh901318: use devm allocation Linus Walleij
2012-06-14  3:13 ` Vinod Koul

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.