linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] drivers/dma/sirf-dma.c: fix usage of devm functions
@ 2012-08-04  8:35 Julia Lawall
  2012-08-04 23:53 ` Barry Song
  2012-08-22  4:16 ` Vinod Koul
  0 siblings, 2 replies; 8+ messages in thread
From: Julia Lawall @ 2012-08-04  8:35 UTC (permalink / raw)
  To: Barry Song
  Cc: kernel-janitors, Vinod Koul, Dan Williams, linux-arm-kernel,
	linux-kernel

From: Julia Lawall <Julia.Lawall@lip6.fr>

Fix some problems with the use of devm_ functions.

devm_kzalloc: devm_kfree is not needed

devm_ioremap: iounmap should not be used, no free is needed

devm_request_irq: the devm_free_irq is followed by irq_dispose_mapping.  I
don't know if it is safe to move the freeing of the irq in this case, so I
have just un-devm'd this function, since the implicit freeing is never
taken advantage of.

In the original code failure of of_address_to_resource jumped to free_mem,
but should have jumped to irq_dispose, since irq_of_parse_and_map has
completed at this point.

In the original code unmap_mem was after irq_dispose, but it should have
been before, again since irq_of_parse_and_map has completed at this point.

One of these problems was found using the following semantic match:
(http://coccinelle.lip6.fr/)

// <smpl>
@@
expression x;
@@

*x = devm_ioremap(...)
...
iounmap(x);
// </smpl>

Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

---
Not compiled.  Does free_irq actually have to be called before
irq_dispose_mapping?

 drivers/dma/sirf-dma.c |   23 +++++++----------------
 1 file changed, 7 insertions(+), 16 deletions(-)

diff --git a/drivers/dma/sirf-dma.c b/drivers/dma/sirf-dma.c
index 434ad31..1af9e48 100644
--- a/drivers/dma/sirf-dma.c
+++ b/drivers/dma/sirf-dma.c
@@ -570,21 +570,19 @@ static int __devinit sirfsoc_dma_probe(struct platform_device *op)
 
 	if (of_property_read_u32(dn, "cell-index", &id)) {
 		dev_err(dev, "Fail to get DMAC index\n");
-		ret = -ENODEV;
-		goto free_mem;
+		return -ENODEV;
 	}
 
 	sdma->irq = irq_of_parse_and_map(dn, 0);
 	if (sdma->irq == NO_IRQ) {
 		dev_err(dev, "Error mapping IRQ!\n");
-		ret = -EINVAL;
-		goto free_mem;
+		return -EINVAL;
 	}
 
 	ret = of_address_to_resource(dn, 0, &res);
 	if (ret) {
 		dev_err(dev, "Error parsing memory region!\n");
-		goto free_mem;
+		goto irq_dispose;
 	}
 
 	regs_start = res.start;
@@ -597,12 +595,11 @@ static int __devinit sirfsoc_dma_probe(struct platform_device *op)
 		goto irq_dispose;
 	}
 
-	ret = devm_request_irq(dev, sdma->irq, &sirfsoc_dma_irq, 0, DRV_NAME,
-		sdma);
+	ret = request_irq(sdma->irq, &sirfsoc_dma_irq, 0, DRV_NAME, sdma);
 	if (ret) {
 		dev_err(dev, "Error requesting IRQ!\n");
 		ret = -EINVAL;
-		goto unmap_mem;
+		goto irq_dispose;
 	}
 
 	dma = &sdma->dma;
@@ -652,13 +649,9 @@ static int __devinit sirfsoc_dma_probe(struct platform_device *op)
 	return 0;
 
 free_irq:
-	devm_free_irq(dev, sdma->irq, sdma);
+	free_irq(sdma->irq, sdma);
 irq_dispose:
 	irq_dispose_mapping(sdma->irq);
-unmap_mem:
-	iounmap(sdma->base);
-free_mem:
-	devm_kfree(dev, sdma);
 	return ret;
 }
 
@@ -668,10 +661,8 @@ static int __devexit sirfsoc_dma_remove(struct platform_device *op)
 	struct sirfsoc_dma *sdma = dev_get_drvdata(dev);
 
 	dma_async_device_unregister(&sdma->dma);
-	devm_free_irq(dev, sdma->irq, sdma);
+	free_irq(sdma->irq, sdma);
 	irq_dispose_mapping(sdma->irq);
-	iounmap(sdma->base);
-	devm_kfree(dev, sdma);
 	return 0;
 }
 


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

* Re: [PATCH] drivers/dma/sirf-dma.c: fix usage of devm functions
  2012-08-04  8:35 [PATCH] drivers/dma/sirf-dma.c: fix usage of devm functions Julia Lawall
@ 2012-08-04 23:53 ` Barry Song
  2012-08-22  4:16 ` Vinod Koul
  1 sibling, 0 replies; 8+ messages in thread
From: Barry Song @ 2012-08-04 23:53 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Vinod Koul, Dan Williams, kernel-janitors, linux-kernel,
	linux-arm-kernel, DL-SHA-WorkGroupLinux

2012/8/4 Julia Lawall <Julia.Lawall@lip6.fr>
>
> From: Julia Lawall <Julia.Lawall@lip6.fr>
>
> Fix some problems with the use of devm_ functions.
>
> devm_kzalloc: devm_kfree is not needed
>
> devm_ioremap: iounmap should not be used, no free is needed
>
> devm_request_irq: the devm_free_irq is followed by irq_dispose_mapping.  I
> don't know if it is safe to move the freeing of the irq in this case, so I
> have just un-devm'd this function, since the implicit freeing is never
> taken advantage of.
>
> In the original code failure of of_address_to_resource jumped to free_mem,
> but should have jumped to irq_dispose, since irq_of_parse_and_map has
> completed at this point.
>
> In the original code unmap_mem was after irq_dispose, but it should have
> been before, again since irq_of_parse_and_map has completed at this point.
>
> One of these problems was found using the following semantic match:
> (http://coccinelle.lip6.fr/)
>
> // <smpl>
> @@
> expression x;
> @@
>
> *x = devm_ioremap(...)
> ...
> iounmap(x);
> // </smpl>
>
> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr>

Acked-by: Barry Song <Baohua.Song@csr.com>

thanks!

>
> ---
> Not compiled.  Does free_irq actually have to be called before
> irq_dispose_mapping?
>
>  drivers/dma/sirf-dma.c |   23 +++++++----------------
>  1 file changed, 7 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/dma/sirf-dma.c b/drivers/dma/sirf-dma.c
> index 434ad31..1af9e48 100644
> --- a/drivers/dma/sirf-dma.c
> +++ b/drivers/dma/sirf-dma.c
> @@ -570,21 +570,19 @@ static int __devinit sirfsoc_dma_probe(struct
> platform_device *op)
>
>         if (of_property_read_u32(dn, "cell-index", &id)) {
>                 dev_err(dev, "Fail to get DMAC index\n");
> -               ret = -ENODEV;
> -               goto free_mem;
> +               return -ENODEV;
>         }
>
>         sdma->irq = irq_of_parse_and_map(dn, 0);
>         if (sdma->irq == NO_IRQ) {
>                 dev_err(dev, "Error mapping IRQ!\n");
> -               ret = -EINVAL;
> -               goto free_mem;
> +               return -EINVAL;
>         }
>
>         ret = of_address_to_resource(dn, 0, &res);
>         if (ret) {
>                 dev_err(dev, "Error parsing memory region!\n");
> -               goto free_mem;
> +               goto irq_dispose;
>         }
>
>         regs_start = res.start;
> @@ -597,12 +595,11 @@ static int __devinit sirfsoc_dma_probe(struct
> platform_device *op)
>                 goto irq_dispose;
>         }
>
> -       ret = devm_request_irq(dev, sdma->irq, &sirfsoc_dma_irq, 0,
> DRV_NAME,
> -               sdma);
> +       ret = request_irq(sdma->irq, &sirfsoc_dma_irq, 0, DRV_NAME, sdma);
>         if (ret) {
>                 dev_err(dev, "Error requesting IRQ!\n");
>                 ret = -EINVAL;
> -               goto unmap_mem;
> +               goto irq_dispose;
>         }
>
>         dma = &sdma->dma;
> @@ -652,13 +649,9 @@ static int __devinit sirfsoc_dma_probe(struct
> platform_device *op)
>         return 0;
>
>  free_irq:
> -       devm_free_irq(dev, sdma->irq, sdma);
> +       free_irq(sdma->irq, sdma);
>  irq_dispose:
>         irq_dispose_mapping(sdma->irq);
> -unmap_mem:
> -       iounmap(sdma->base);
> -free_mem:
> -       devm_kfree(dev, sdma);
>         return ret;
>  }
>
> @@ -668,10 +661,8 @@ static int __devexit sirfsoc_dma_remove(struct
> platform_device *op)
>         struct sirfsoc_dma *sdma = dev_get_drvdata(dev);
>
>         dma_async_device_unregister(&sdma->dma);
> -       devm_free_irq(dev, sdma->irq, sdma);
> +       free_irq(sdma->irq, sdma);
>         irq_dispose_mapping(sdma->irq);
> -       iounmap(sdma->base);
> -       devm_kfree(dev, sdma);
>         return 0;
>  }

-barry

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

* Re: [PATCH] drivers/dma/sirf-dma.c: fix usage of devm functions
  2012-08-04  8:35 [PATCH] drivers/dma/sirf-dma.c: fix usage of devm functions Julia Lawall
  2012-08-04 23:53 ` Barry Song
@ 2012-08-22  4:16 ` Vinod Koul
  2012-08-22  5:25   ` Barry Song
  1 sibling, 1 reply; 8+ messages in thread
From: Vinod Koul @ 2012-08-22  4:16 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Barry Song, Dan Williams, kernel-janitors, linux-kernel,
	linux-arm-kernel

On Sat, 2012-08-04 at 10:35 +0200, Julia Lawall wrote:
> From: Julia Lawall <Julia.Lawall@lip6.fr>
> 
> Fix some problems with the use of devm_ functions.
Applied, thanks


-- 
~Vinod


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

* Re: [PATCH] drivers/dma/sirf-dma.c: fix usage of devm functions
  2012-08-22  4:16 ` Vinod Koul
@ 2012-08-22  5:25   ` Barry Song
  2012-08-22  5:30     ` Julia Lawall
  0 siblings, 1 reply; 8+ messages in thread
From: Barry Song @ 2012-08-22  5:25 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Julia Lawall, Dan Williams, kernel-janitors, linux-kernel,
	linux-arm-kernel, Barry Song

2012/8/22 Vinod Koul <vinod.koul@linux.intel.com>:
> On Sat, 2012-08-04 at 10:35 +0200, Julia Lawall wrote:
>> From: Julia Lawall <Julia.Lawall@lip6.fr>
>>
>> Fix some problems with the use of devm_ functions.
> Applied, thanks

the git log "drivers/dma/sirf-dma.c: fix usage of devm functions"
should be fixed.

>
>
> --
> ~Vinod
>

-barry

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

* Re: [PATCH] drivers/dma/sirf-dma.c: fix usage of devm functions
  2012-08-22  5:25   ` Barry Song
@ 2012-08-22  5:30     ` Julia Lawall
  2012-08-22  5:41       ` Barry Song
  0 siblings, 1 reply; 8+ messages in thread
From: Julia Lawall @ 2012-08-22  5:30 UTC (permalink / raw)
  To: Barry Song
  Cc: Vinod Koul, Julia Lawall, Dan Williams, kernel-janitors,
	linux-kernel, linux-arm-kernel, Barry Song

On Wed, 22 Aug 2012, Barry Song wrote:

> 2012/8/22 Vinod Koul <vinod.koul@linux.intel.com>:
>> On Sat, 2012-08-04 at 10:35 +0200, Julia Lawall wrote:
>>> From: Julia Lawall <Julia.Lawall@lip6.fr>
>>>
>>> Fix some problems with the use of devm_ functions.
>> Applied, thanks
>
> the git log "drivers/dma/sirf-dma.c: fix usage of devm functions"
> should be fixed.

What do you suggest?  The patch is about problems with the use of 
devm_kzalloc, devm_ioremap, and devm_request_irq.

thanks,
julia

>
>>
>>
>> --
>> ~Vinod
>>
>
> -barry
> --
> To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

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

* Re: [PATCH] drivers/dma/sirf-dma.c: fix usage of devm functions
  2012-08-22  5:30     ` Julia Lawall
@ 2012-08-22  5:41       ` Barry Song
  2012-08-22  6:34         ` Vinod Koul
  0 siblings, 1 reply; 8+ messages in thread
From: Barry Song @ 2012-08-22  5:41 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Vinod Koul, Dan Williams, kernel-janitors, linux-kernel,
	linux-arm-kernel, Barry Song

2012/8/22 Julia Lawall <julia.lawall@lip6.fr>:
> On Wed, 22 Aug 2012, Barry Song wrote:
>
>> 2012/8/22 Vinod Koul <vinod.koul@linux.intel.com>:
>>>
>>> On Sat, 2012-08-04 at 10:35 +0200, Julia Lawall wrote:
>>>>
>>>> From: Julia Lawall <Julia.Lawall@lip6.fr>
>>>>
>>>> Fix some problems with the use of devm_ functions.
>>>
>>> Applied, thanks
>>
>>
>> the git log "drivers/dma/sirf-dma.c: fix usage of devm functions"
>> should be fixed.
>
>
> What do you suggest?  The patch is about problems with the use of
> devm_kzalloc, devm_ioremap, and devm_request_irq.

i mean the prefix

dmaengine: sirf: .............

>
> thanks,
> julia

-barry

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

* Re: [PATCH] drivers/dma/sirf-dma.c: fix usage of devm functions
  2012-08-22  5:41       ` Barry Song
@ 2012-08-22  6:34         ` Vinod Koul
  2012-08-22  6:38           ` Julia Lawall
  0 siblings, 1 reply; 8+ messages in thread
From: Vinod Koul @ 2012-08-22  6:34 UTC (permalink / raw)
  To: Barry Song
  Cc: Julia Lawall, kernel-janitors, linux-kernel, Barry Song,
	Dan Williams, linux-arm-kernel

On Wed, 2012-08-22 at 13:41 +0800, Barry Song wrote:
> >>
> >>
> >> the git log "drivers/dma/sirf-dma.c: fix usage of devm functions"
> >> should be fixed.
> >
> >
> > What do you suggest?  The patch is about problems with the use of
> > devm_kzalloc, devm_ioremap, and devm_request_irq.
> 
> i mean the prefix
> 
> dmaengine: sirf: .............
That is the usual way, it helps if you see the notation used by
subsystem by checking patches being sent to subsystem, but it is not a
really big deal, pls take care of this in future.


-- 
~Vinod


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

* Re: [PATCH] drivers/dma/sirf-dma.c: fix usage of devm functions
  2012-08-22  6:34         ` Vinod Koul
@ 2012-08-22  6:38           ` Julia Lawall
  0 siblings, 0 replies; 8+ messages in thread
From: Julia Lawall @ 2012-08-22  6:38 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Barry Song, Julia Lawall, kernel-janitors, linux-kernel,
	Barry Song, Dan Williams, linux-arm-kernel

>> dmaengine: sirf: .............
> That is the usual way, it helps if you see the notation used by
> subsystem by checking patches being sent to subsystem, but it is not a
> really big deal, pls take care of this in future.

OK.

julia

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

end of thread, other threads:[~2012-08-22  6:38 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-08-04  8:35 [PATCH] drivers/dma/sirf-dma.c: fix usage of devm functions Julia Lawall
2012-08-04 23:53 ` Barry Song
2012-08-22  4:16 ` Vinod Koul
2012-08-22  5:25   ` Barry Song
2012-08-22  5:30     ` Julia Lawall
2012-08-22  5:41       ` Barry Song
2012-08-22  6:34         ` Vinod Koul
2012-08-22  6:38           ` Julia Lawall

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).