public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Axel Lin <axel.lin@gmail.com>
To: linux-kernel <linux-kernel@vger.kernel.org>
Cc: Sascha Hauer <s.hauer@pengutronix.de>,
	Liam Girdwood <lrg@slimlogic.co.uk>,
	Mark Brown <broonie@opensource.wolfsonmicro.com>,
	alsa-devel@alsa-project.org
Subject: [PATCH 8/8] ASoC: phycore-ac97: fix resource leak
Date: Thu, 25 Nov 2010 15:14:03 +0800	[thread overview]
Message-ID: <1290669243.30158.22.camel@mola> (raw)
In-Reply-To: <1290668785.30158.7.camel@mola>

Fix imx_phycore_init() error path and imx_phycore_exit() to properly free
allocated resources.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
 sound/soc/imx/phycore-ac97.c |   28 +++++++++++++++++++++-------
 1 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/sound/soc/imx/phycore-ac97.c b/sound/soc/imx/phycore-ac97.c
index db157f7..a7deb5c 100644
--- a/sound/soc/imx/phycore-ac97.c
+++ b/sound/soc/imx/phycore-ac97.c
@@ -42,6 +42,7 @@ static struct snd_soc_card imx_phycore = {
 	.num_links	= ARRAY_SIZE(imx_phycore_dai_ac97),
 };
 
+static struct platform_device *imx_phycore_snd_ac97_device;
 static struct platform_device *imx_phycore_snd_device;
 
 static int __init imx_phycore_init(void)
@@ -52,29 +53,42 @@ static int __init imx_phycore_init(void)
 		/* return happy. We might run on a totally different machine */
 		return 0;
 
-	imx_phycore_snd_device = platform_device_alloc("soc-audio", -1);
-	if (!imx_phycore_snd_device)
+	imx_phycore_snd_ac97_device = platform_device_alloc("soc-audio", -1);
+	if (!imx_phycore_snd_ac97_device)
 		return -ENOMEM;
 
-	platform_set_drvdata(imx_phycore_snd_device, &imx_phycore);
-	ret = platform_device_add(imx_phycore_snd_device);
+	platform_set_drvdata(imx_phycore_snd_ac97_device, &imx_phycore);
+	ret = platform_device_add(imx_phycore_snd_ac97_device);
+	if (ret)
+		goto fail1;
 
 	imx_phycore_snd_device = platform_device_alloc("wm9712-codec", -1);
-	if (!imx_phycore_snd_device)
-		return -ENOMEM;
+	if (!imx_phycore_snd_device) {
+		ret = -ENOMEM;
+		goto fail2;
+	}
 	ret = platform_device_add(imx_phycore_snd_device);
 
 	if (ret) {
 		printk(KERN_ERR "ASoC: Platform device allocation failed\n");
-		platform_device_put(imx_phycore_snd_device);
+		goto fail3;
 	}
 
+	return 0;
+
+fail3:
+	platform_device_put(imx_phycore_snd_device);
+fail2:
+	platform_device_del(imx_phycore_snd_ac97_device);
+fail1:
+	platform_device_put(imx_phycore_snd_ac97_device);
 	return ret;
 }
 
 static void __exit imx_phycore_exit(void)
 {
 	platform_device_unregister(imx_phycore_snd_device);
+	platform_device_unregister(imx_phycore_snd_ac97_device);
 }
 
 late_initcall(imx_phycore_init);
-- 
1.7.2




  parent reply	other threads:[~2010-11-25  7:08 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-25  7:06 [PATCH 0/8] ASoC: fix resource leak in error paths Axel Lin
2010-11-25  7:07 ` [PATCH 1/8] ASoC: efika-audio-fabric: fix resource leak in efika_fabric_init error path Axel Lin
2010-11-25  7:08 ` [PATCH 2/8] ASoC: pcm030-audio-fabric: fix resource leak in pcm030_fabric_init " Axel Lin
2010-11-25  7:10 ` [PATCH 3/8] ASoC: snd-soc-afeb9260: remove unneeded platform_device_del in " Axel Lin
2010-11-25  7:11 ` [PATCH 4/8] ASoC: sam9g20_wm8731: fix resource leak in at91sam9g20ek_init " Axel Lin
2010-11-25  7:11 ` [PATCH 5/8] ASoC: smdk_wm9713: fix resource leak in smdk_init " Axel Lin
2010-11-25  7:12 ` [PATCH 6/8] ASoC: simone: fix resource leak in simone_init " Axel Lin
2010-11-25  8:06   ` Mika Westerberg
2010-11-25  7:13 ` [PATCH 7/8] ASoC: imx-ssi: fix resource leak Axel Lin
2010-11-25  9:19   ` Sascha Hauer
2010-11-25  7:14 ` Axel Lin [this message]
2010-11-25  9:19   ` [PATCH 8/8] ASoC: phycore-ac97: " Sascha Hauer
2010-11-25 10:47 ` [PATCH 0/8] ASoC: fix resource leak in error paths Liam Girdwood
2010-11-25 11:14 ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1290669243.30158.22.camel@mola \
    --to=axel.lin@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lrg@slimlogic.co.uk \
    --cc=s.hauer@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox