alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 3/3] sound/soc/au1x: keep pointer to resource so it can be freed
@ 2011-10-18  3:45 Julia Lawall
  2011-10-19 14:50 ` Manuel Lauss
  0 siblings, 1 reply; 7+ messages in thread
From: Julia Lawall @ 2011-10-18  3:45 UTC (permalink / raw)
  To: Liam Girdwood
  Cc: alsa-devel, Takashi Iwai, Mark Brown, kernel-janitors,
	linux-kernel, Manuel Lauss, Axel Lin

From: Julia Lawall <julia@diku.dk>

Add a new variable for storing resources accessed subsequent to the one
accessed using request_mem_region, so the one accessed using
request_mem_region can be released if needed.

This code is also missing some calls to iounmap.

The semantic match that finds this problem is as follows:
(http://coccinelle.lip6.fr/)

// <smpl>
@r@
expression E, E1;
identifier f;
statement S1,S2,S3;
@@

if (E == NULL)
{
  ... when != if (E == NULL || ...) S1 else S2
      when != E = E1
*E->f
  ... when any
  return ...;
}
else S3
// </smpl>

Signed-off-by: Julia Lawall <julia@diku.dk>

---
 sound/soc/au1x/ac97c.c |   22 ++++++++++++----------
 sound/soc/au1x/i2sc.c  |   22 ++++++++++++----------
 2 files changed, 24 insertions(+), 20 deletions(-)

diff --git a/sound/soc/au1x/ac97c.c b/sound/soc/au1x/ac97c.c
index 13802ff..0188643 100644
--- a/sound/soc/au1x/ac97c.c
+++ b/sound/soc/au1x/ac97c.c
@@ -226,7 +226,7 @@ static struct snd_soc_dai_driver au1xac97c_dai_driver = {
 static int __devinit au1xac97c_drvprobe(struct platform_device *pdev)
 {
 	int ret;
-	struct resource *r;
+	struct resource *r, *r1;
 	struct au1xpsc_audio_data *ctx;
 
 	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
@@ -249,15 +249,15 @@ static int __devinit au1xac97c_drvprobe(struct platform_device *pdev)
 	if (!ctx->mmio)
 		goto out1;
 
-	r = platform_get_resource(pdev, IORESOURCE_DMA, 0);
-	if (!r)
-		goto out1;
-	ctx->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = r->start;
+	r1 = platform_get_resource(pdev, IORESOURCE_DMA, 0);
+	if (!r1)
+		goto out2;
+	ctx->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = r1->start;
 
-	r = platform_get_resource(pdev, IORESOURCE_DMA, 1);
-	if (!r)
-		goto out1;
-	ctx->dmaids[SNDRV_PCM_STREAM_CAPTURE] = r->start;
+	r1 = platform_get_resource(pdev, IORESOURCE_DMA, 1);
+	if (!r1)
+		goto out2;
+	ctx->dmaids[SNDRV_PCM_STREAM_CAPTURE] = r1->start;
 
 	/* switch it on */
 	WR(ctx, AC97_ENABLE, EN_D | EN_CE);
@@ -270,11 +270,13 @@ static int __devinit au1xac97c_drvprobe(struct platform_device *pdev)
 
 	ret = snd_soc_register_dai(&pdev->dev, &au1xac97c_dai_driver);
 	if (ret)
-		goto out1;
+		goto out2;
 
 	ac97c_workdata = ctx;
 	return 0;
 
+out2:
+	iounmap(ctx->mmio);
 out1:
 	release_mem_region(r->start, resource_size(r));
 out0:
diff --git a/sound/soc/au1x/i2sc.c b/sound/soc/au1x/i2sc.c
index 19e0d2a..3725c77 100644
--- a/sound/soc/au1x/i2sc.c
+++ b/sound/soc/au1x/i2sc.c
@@ -228,7 +228,7 @@ static struct snd_soc_dai_driver au1xi2s_dai_driver = {
 static int __devinit au1xi2s_drvprobe(struct platform_device *pdev)
 {
 	int ret;
-	struct resource *r;
+	struct resource *r, *r1;
 	struct au1xpsc_audio_data *ctx;
 
 	ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
@@ -249,24 +249,26 @@ static int __devinit au1xi2s_drvprobe(struct platform_device *pdev)
 	if (!ctx->mmio)
 		goto out1;
 
-	r = platform_get_resource(pdev, IORESOURCE_DMA, 0);
-	if (!r)
-		goto out1;
-	ctx->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = r->start;
+	r1 = platform_get_resource(pdev, IORESOURCE_DMA, 0);
+	if (!r1)
+		goto out2;
+	ctx->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = r1->start;
 
-	r = platform_get_resource(pdev, IORESOURCE_DMA, 1);
-	if (!r)
-		goto out1;
-	ctx->dmaids[SNDRV_PCM_STREAM_CAPTURE] = r->start;
+	r1 = platform_get_resource(pdev, IORESOURCE_DMA, 1);
+	if (!r1)
+		goto out2;
+	ctx->dmaids[SNDRV_PCM_STREAM_CAPTURE] = r1->start;
 
 	platform_set_drvdata(pdev, ctx);
 
 	ret = snd_soc_register_dai(&pdev->dev, &au1xi2s_dai_driver);
 	if (ret)
-		goto out1;
+		goto out2;
 
 	return 0;
 
+out2:
+	iounmap(ctx->mmio);
 out1:
 	release_mem_region(r->start, resource_size(r));
 out0:

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

* Re: [PATCH 3/3] sound/soc/au1x: keep pointer to resource so it can be freed
  2011-10-18  3:45 [PATCH 3/3] sound/soc/au1x: keep pointer to resource so it can be freed Julia Lawall
@ 2011-10-19 14:50 ` Manuel Lauss
  2011-10-19 15:09   ` Julia Lawall
  2011-10-19 16:47   ` Girdwood, Liam
  0 siblings, 2 replies; 7+ messages in thread
From: Manuel Lauss @ 2011-10-19 14:50 UTC (permalink / raw)
  To: Julia Lawall
  Cc: Liam Girdwood, kernel-janitors, Mark Brown, Jaroslav Kysela,
	Takashi Iwai, Axel Lin, alsa-devel, linux-kernel

On Tue, Oct 18, 2011 at 5:45 AM, Julia Lawall <julia@diku.dk> wrote:
> From: Julia Lawall <julia@diku.dk>
>
> Add a new variable for storing resources accessed subsequent to the one
> accessed using request_mem_region, so the one accessed using
> request_mem_region can be released if needed.
>
> This code is also missing some calls to iounmap.

How about something much simpler, like this:

>From 940e38b3f0beff6fcd8f62f627dce622e9ca0e54 Mon Sep 17 00:00:00 2001
From: Manuel Lauss <manuel.lauss@googlemail.com>
Date: Wed, 19 Oct 2011 16:45:12 +0200
Subject: [PATCH] ASoC: au1x: fix error paths in ac97c/i2cs probe callbacks.

add iounmap() and release the correct mem resource.

Signed-off-by: Manuel Lauss <manuel.lauss@googlemail.com>
---
 sound/soc/au1x/ac97c.c |    7 +++++--
 sound/soc/au1x/i2sc.c  |    7 +++++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/sound/soc/au1x/ac97c.c b/sound/soc/au1x/ac97c.c
index 13802ff..4ec39aa 100644
--- a/sound/soc/au1x/ac97c.c
+++ b/sound/soc/au1x/ac97c.c
@@ -251,12 +251,12 @@ static int __devinit au1xac97c_drvprobe(struct
platform_device *pdev)

 	r = platform_get_resource(pdev, IORESOURCE_DMA, 0);
 	if (!r)
-		goto out1;
+		goto out2;
 	ctx->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = r->start;

 	r = platform_get_resource(pdev, IORESOURCE_DMA, 1);
 	if (!r)
-		goto out1;
+		goto out2;
 	ctx->dmaids[SNDRV_PCM_STREAM_CAPTURE] = r->start;

 	/* switch it on */
@@ -275,7 +275,10 @@ static int __devinit au1xac97c_drvprobe(struct
platform_device *pdev)
 	ac97c_workdata = ctx;
 	return 0;

+out2:
+	iounmap(ctx->mmio);
 out1:
+	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	release_mem_region(r->start, resource_size(r));
 out0:
 	kfree(ctx);
diff --git a/sound/soc/au1x/i2sc.c b/sound/soc/au1x/i2sc.c
index 19e0d2a..59fb31a 100644
--- a/sound/soc/au1x/i2sc.c
+++ b/sound/soc/au1x/i2sc.c
@@ -251,12 +251,12 @@ static int __devinit au1xi2s_drvprobe(struct
platform_device *pdev)

 	r = platform_get_resource(pdev, IORESOURCE_DMA, 0);
 	if (!r)
-		goto out1;
+		goto out2;
 	ctx->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = r->start;

 	r = platform_get_resource(pdev, IORESOURCE_DMA, 1);
 	if (!r)
-		goto out1;
+		goto out2;
 	ctx->dmaids[SNDRV_PCM_STREAM_CAPTURE] = r->start;

 	platform_set_drvdata(pdev, ctx);
@@ -267,7 +267,10 @@ static int __devinit au1xi2s_drvprobe(struct
platform_device *pdev)

 	return 0;

+out2:
+	iounmap(ctx->mmio);
 out1:
+	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	release_mem_region(r->start, resource_size(r));
 out0:
 	kfree(ctx);
-- 
1.7.7

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

* Re: [PATCH 3/3] sound/soc/au1x: keep pointer to resource so it can be freed
  2011-10-19 14:50 ` Manuel Lauss
@ 2011-10-19 15:09   ` Julia Lawall
  2011-10-19 16:47   ` Girdwood, Liam
  1 sibling, 0 replies; 7+ messages in thread
From: Julia Lawall @ 2011-10-19 15:09 UTC (permalink / raw)
  To: Manuel Lauss
  Cc: alsa-devel, Takashi Iwai, Mark Brown, kernel-janitors,
	linux-kernel, Axel Lin, Liam Girdwood

On Wed, 19 Oct 2011, Manuel Lauss wrote:

> On Tue, Oct 18, 2011 at 5:45 AM, Julia Lawall <julia@diku.dk> wrote:
> > From: Julia Lawall <julia@diku.dk>
> >
> > Add a new variable for storing resources accessed subsequent to the one
> > accessed using request_mem_region, so the one accessed using
> > request_mem_region can be released if needed.
> >
> > This code is also missing some calls to iounmap.
> 
> How about something much simpler, like this:

If you like, I guess.  But I don't think I have seen that done before...

julia

> From 940e38b3f0beff6fcd8f62f627dce622e9ca0e54 Mon Sep 17 00:00:00 2001
> From: Manuel Lauss <manuel.lauss@googlemail.com>
> Date: Wed, 19 Oct 2011 16:45:12 +0200
> Subject: [PATCH] ASoC: au1x: fix error paths in ac97c/i2cs probe callbacks.
> 
> add iounmap() and release the correct mem resource.
> 
> Signed-off-by: Manuel Lauss <manuel.lauss@googlemail.com>
> ---
>  sound/soc/au1x/ac97c.c |    7 +++++--
>  sound/soc/au1x/i2sc.c  |    7 +++++--
>  2 files changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/sound/soc/au1x/ac97c.c b/sound/soc/au1x/ac97c.c
> index 13802ff..4ec39aa 100644
> --- a/sound/soc/au1x/ac97c.c
> +++ b/sound/soc/au1x/ac97c.c
> @@ -251,12 +251,12 @@ static int __devinit au1xac97c_drvprobe(struct
> platform_device *pdev)
> 
>  	r = platform_get_resource(pdev, IORESOURCE_DMA, 0);
>  	if (!r)
> -		goto out1;
> +		goto out2;
>  	ctx->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = r->start;
> 
>  	r = platform_get_resource(pdev, IORESOURCE_DMA, 1);
>  	if (!r)
> -		goto out1;
> +		goto out2;
>  	ctx->dmaids[SNDRV_PCM_STREAM_CAPTURE] = r->start;
> 
>  	/* switch it on */
> @@ -275,7 +275,10 @@ static int __devinit au1xac97c_drvprobe(struct
> platform_device *pdev)
>  	ac97c_workdata = ctx;
>  	return 0;
> 
> +out2:
> +	iounmap(ctx->mmio);
>  out1:
> +	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>  	release_mem_region(r->start, resource_size(r));
>  out0:
>  	kfree(ctx);
> diff --git a/sound/soc/au1x/i2sc.c b/sound/soc/au1x/i2sc.c
> index 19e0d2a..59fb31a 100644
> --- a/sound/soc/au1x/i2sc.c
> +++ b/sound/soc/au1x/i2sc.c
> @@ -251,12 +251,12 @@ static int __devinit au1xi2s_drvprobe(struct
> platform_device *pdev)
> 
>  	r = platform_get_resource(pdev, IORESOURCE_DMA, 0);
>  	if (!r)
> -		goto out1;
> +		goto out2;
>  	ctx->dmaids[SNDRV_PCM_STREAM_PLAYBACK] = r->start;
> 
>  	r = platform_get_resource(pdev, IORESOURCE_DMA, 1);
>  	if (!r)
> -		goto out1;
> +		goto out2;
>  	ctx->dmaids[SNDRV_PCM_STREAM_CAPTURE] = r->start;
> 
>  	platform_set_drvdata(pdev, ctx);
> @@ -267,7 +267,10 @@ static int __devinit au1xi2s_drvprobe(struct
> platform_device *pdev)
> 
>  	return 0;
> 
> +out2:
> +	iounmap(ctx->mmio);
>  out1:
> +	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
>  	release_mem_region(r->start, resource_size(r));
>  out0:
>  	kfree(ctx);
> -- 
> 1.7.7
> --
> 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] 7+ messages in thread

* Re: [PATCH 3/3] sound/soc/au1x: keep pointer to resource so it can be freed
  2011-10-19 14:50 ` Manuel Lauss
  2011-10-19 15:09   ` Julia Lawall
@ 2011-10-19 16:47   ` Girdwood, Liam
  2011-10-19 16:48     ` Mark Brown
  1 sibling, 1 reply; 7+ messages in thread
From: Girdwood, Liam @ 2011-10-19 16:47 UTC (permalink / raw)
  To: Manuel Lauss
  Cc: alsa-devel, Takashi Iwai, Mark Brown, kernel-janitors,
	linux-kernel, Julia Lawall, Axel Lin

On 19 October 2011 15:50, Manuel Lauss <manuel.lauss@googlemail.com> wrote:
> On Tue, Oct 18, 2011 at 5:45 AM, Julia Lawall <julia@diku.dk> wrote:
>> From: Julia Lawall <julia@diku.dk>
>>
>> Add a new variable for storing resources accessed subsequent to the one
>> accessed using request_mem_region, so the one accessed using
>> request_mem_region can be released if needed.
>>
>> This code is also missing some calls to iounmap.
>
> How about something much simpler, like this:
>
> From 940e38b3f0beff6fcd8f62f627dce622e9ca0e54 Mon Sep 17 00:00:00 2001
> From: Manuel Lauss <manuel.lauss@googlemail.com>
> Date: Wed, 19 Oct 2011 16:45:12 +0200
> Subject: [PATCH] ASoC: au1x: fix error paths in ac97c/i2cs probe callbacks.
>
> add iounmap() and release the correct mem resource.
>
> Signed-off-by: Manuel Lauss <manuel.lauss@googlemail.com>

Acked-by: Liam Girdwood <lrg@ti.com>

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

* Re: [PATCH 3/3] sound/soc/au1x: keep pointer to resource so it can be freed
  2011-10-19 16:47   ` Girdwood, Liam
@ 2011-10-19 16:48     ` Mark Brown
  2011-10-19 17:32       ` Julia Lawall
  0 siblings, 1 reply; 7+ messages in thread
From: Mark Brown @ 2011-10-19 16:48 UTC (permalink / raw)
  To: Girdwood, Liam
  Cc: alsa-devel, Takashi Iwai, kernel-janitors, linux-kernel,
	Manuel Lauss, Julia Lawall, Axel Lin

On Wed, Oct 19, 2011 at 05:47:25PM +0100, Girdwood, Liam wrote:
> > From 940e38b3f0beff6fcd8f62f627dce622e9ca0e54 Mon Sep 17 00:00:00 2001
> > From: Manuel Lauss <manuel.lauss@googlemail.com>
> > Date: Wed, 19 Oct 2011 16:45:12 +0200
> > Subject: [PATCH] ASoC: au1x: fix error paths in ac97c/i2cs probe callbacks.
> >
> > add iounmap() and release the correct mem resource.
> >
> > Signed-off-by: Manuel Lauss <manuel.lauss@googlemail.com>

> Acked-by: Liam Girdwood <lrg@ti.com>

...but since it was buried in the middle of the e-mail please resend
with Liam's ack for application.

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

* Re: [PATCH 3/3] sound/soc/au1x: keep pointer to resource so it can be freed
  2011-10-19 16:48     ` Mark Brown
@ 2011-10-19 17:32       ` Julia Lawall
  2011-10-19 17:34         ` Mark Brown
  0 siblings, 1 reply; 7+ messages in thread
From: Julia Lawall @ 2011-10-19 17:32 UTC (permalink / raw)
  To: Mark Brown
  Cc: Girdwood, Liam, Manuel Lauss, kernel-janitors, Jaroslav Kysela,
	Takashi Iwai, Axel Lin, alsa-devel, linux-kernel

I'm not sure how to proceed, since I originally sent 3 patches, all with 
the same problem.  I send another single patch that fixed the problems 
with nicer names than r and r1.  Should I send another single patch with 
Manuel's solution?  Or does Manuel want to do that?

julia


On Wed, 19 Oct 2011, Mark Brown wrote:

> On Wed, Oct 19, 2011 at 05:47:25PM +0100, Girdwood, Liam wrote:
> > > From 940e38b3f0beff6fcd8f62f627dce622e9ca0e54 Mon Sep 17 00:00:00 2001
> > > From: Manuel Lauss <manuel.lauss@googlemail.com>
> > > Date: Wed, 19 Oct 2011 16:45:12 +0200
> > > Subject: [PATCH] ASoC: au1x: fix error paths in ac97c/i2cs probe callbacks.
> > >
> > > add iounmap() and release the correct mem resource.
> > >
> > > Signed-off-by: Manuel Lauss <manuel.lauss@googlemail.com>
> 
> > Acked-by: Liam Girdwood <lrg@ti.com>
> 
> ...but since it was buried in the middle of the e-mail please resend
> with Liam's ack for application.
> --
> 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] 7+ messages in thread

* Re: [PATCH 3/3] sound/soc/au1x: keep pointer to resource so it can be freed
  2011-10-19 17:32       ` Julia Lawall
@ 2011-10-19 17:34         ` Mark Brown
  0 siblings, 0 replies; 7+ messages in thread
From: Mark Brown @ 2011-10-19 17:34 UTC (permalink / raw)
  To: Julia Lawall
  Cc: alsa-devel, Takashi Iwai, kernel-janitors, linux-kernel,
	Manuel Lauss, Axel Lin, Girdwood, Liam

On Wed, Oct 19, 2011 at 07:32:10PM +0200, Julia Lawall wrote:
> I'm not sure how to proceed, since I originally sent 3 patches, all with 
> the same problem.  I send another single patch that fixed the problems 
> with nicer names than r and r1.  Should I send another single patch with 
> Manuel's solution?  Or does Manuel want to do that?

I dunno, I guess sending Manuel's patch along with your other changes
might be the way forward?

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

end of thread, other threads:[~2011-10-19 17:34 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-10-18  3:45 [PATCH 3/3] sound/soc/au1x: keep pointer to resource so it can be freed Julia Lawall
2011-10-19 14:50 ` Manuel Lauss
2011-10-19 15:09   ` Julia Lawall
2011-10-19 16:47   ` Girdwood, Liam
2011-10-19 16:48     ` Mark Brown
2011-10-19 17:32       ` Julia Lawall
2011-10-19 17:34         ` Mark Brown

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).