All of lore.kernel.org
 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
  0 siblings, 0 replies; 19+ 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] 19+ messages in thread

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

Thread overview: 19+ 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-18  3:45 ` Julia Lawall
2011-10-18  3:45 ` Julia Lawall
2011-10-19 14:50 ` Manuel Lauss
2011-10-19 14:50   ` Manuel Lauss
2011-10-19 15:09   ` Julia Lawall
2011-10-19 15:09     ` Julia Lawall
2011-10-19 15:09     ` [PATCH 3/3] sound/soc/au1x: keep pointer to resource so it can Julia Lawall
2011-10-19 16:47   ` [PATCH 3/3] sound/soc/au1x: keep pointer to resource so it can be freed Girdwood, Liam
2011-10-19 16:47     ` Girdwood, Liam
2011-10-19 16:47     ` Girdwood, Liam
2011-10-19 16:48     ` Mark Brown
2011-10-19 16:48       ` Mark Brown
2011-10-19 16:48       ` [PATCH 3/3] sound/soc/au1x: keep pointer to resource so it can Mark Brown
2011-10-19 17:32       ` [PATCH 3/3] sound/soc/au1x: keep pointer to resource so it can be freed Julia Lawall
2011-10-19 17:32         ` [PATCH 3/3] sound/soc/au1x: keep pointer to resource so it can Julia Lawall
2011-10-19 17:34         ` [PATCH 3/3] sound/soc/au1x: keep pointer to resource so it can be freed Mark Brown
2011-10-19 17:34           ` Mark Brown
2011-10-19 17:34           ` [PATCH 3/3] sound/soc/au1x: keep pointer to resource so it can Mark Brown

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.