Skip to contentSkip to conversation

sound/soc/au1x: keep pointer to resource so it can be freed

PATCH In review Julia Lawall 4 participants 7 messages Oct 18, 2011 – Oct 19, 2011

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 3/3 sound/soc/au1x: keep pointer to resource so it can be freed

From: Julia Lawall <[email protected]>

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>

---
 sound/soc/au1x/ac97c.c |   22 ++++++++++++----------
 sound/soc/au1x/i2sc.c  |   22 ++++++++++++----------
 2 files changed, 24 insertions(+), 20 deletions(-)
sound/soc/au1x/ac97c.c +12 -10
index 13802ff..0188643 100644
@@ -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:
sound/soc/au1x/i2sc.c +12 -10
index 19e0d2a..3725c77 100644
@@ -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:
#1 lore raw
Quoted 7 lines · Julia Lawall

From: Julia Lawall <[email protected]>

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:

Quoted 1 line

From 940e38b3f0beff6fcd8f62f627dce622e9ca0e54 Mon Sep 17 00:00:00 2001

From: Manuel Lauss <[email protected]>
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.

---
 sound/soc/au1x/ac97c.c |    7 +++++--
 sound/soc/au1x/i2sc.c  |    7 +++++--
 2 files changed, 10 insertions(+), 4 deletions(-)
sound/soc/au1x/ac97c.c +0 -0
index 13802ff..4ec39aa 100644
@@ -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);

sound/soc/au1x/i2sc.c +0 -0
index 19e0d2a..59fb31a 100644
@@ -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);

Signature · 1 line
1.7.7
#2 lore raw
Quoted 10 lines · Manuel Lauss
Quoted 7 lines · Julia Lawall

From: Julia Lawall <[email protected]>

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

Quoted 84 lines

From 940e38b3f0beff6fcd8f62f627dce622e9ca0e54 Mon Sep 17 00:00:00 2001
From: Manuel Lauss <[email protected]>
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.

---
 sound/soc/au1x/ac97c.c |    7 +++++--
 sound/soc/au1x/i2sc.c  |    7 +++++--
 2 files changed, 10 insertions(+), 4 deletions(-)
sound/soc/au1x/ac97c.c +2 -2
index 13802ff..4ec39aa 100644
@@ -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;
 
sound/soc/au1x/ac97c.c +3 -0
 	/* 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:
sound/soc/au1x/ac97c.c +0 -0
 	kfree(ctx);
sound/soc/au1x/i2sc.c +2 -2
index 19e0d2a..59fb31a 100644
@@ -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;
 
sound/soc/au1x/i2sc.c +3 -0
 	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);

Signature · 5 lines
1.7.7
--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw
In reply to Manuel Lauss
Quoted 11 lines · Manuel Lauss
Quoted 7 lines · Julia Lawall

From: Julia Lawall <[email protected]>

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:

Quoted 8 lines

From 940e38b3f0beff6fcd8f62f627dce622e9ca0e54 Mon Sep 17 00:00:00 2001
From: Manuel Lauss <[email protected]>
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.

#4 lore raw
Quoted 10 lines · Liam
Quoted 8 lines

From 940e38b3f0beff6fcd8f62f627dce622e9ca0e54 Mon Sep 17 00:00:00 2001
From: Manuel Lauss <[email protected]>
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.

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

#5 lore raw

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

Quoted 19 lines · Mark Brown
Quoted 10 lines · Liam
Quoted 8 lines

From 940e38b3f0beff6fcd8f62f627dce622e9ca0e54 Mon Sep 17 00:00:00 2001
From: Manuel Lauss <[email protected]>
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.

...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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#6 lore raw
Quoted 4 lines · Julia Lawall

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?