alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Axel Lin <axel.lin@gmail.com>
To: linux-kernel <linux-kernel@vger.kernel.org>
Cc: Liam Girdwood <lrg@slimlogic.co.uk>,
	Mark Brown <broonie@opensource.wolfsonmicro.com>,
	Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.de>,
	Guennadi Liakhovetski <g.liakhovetski@gmx.de>,
	Tejun Heo <tj@kernel.org>,
	alsa-devel@alsa-project.org
Subject: [PATCH v2 11/12] wm8978: fix a memory leak if another WM8978 is registered
Date: Thu, 15 Jul 2010 16:37:06 +0800	[thread overview]
Message-ID: <1279183026.10733.2.camel@mola> (raw)
In-Reply-To: <1279163338.29294.30.camel@mola>

>From e53ff15ee6843d6591509f9aeeb2fa1a0c1eccee Mon Sep 17 00:00:00 2001
From: Axel Lin <axel.lin@gmail.com>
Date: Thu, 15 Jul 2010 16:33:20 +0800
Subject: [PATCH] wm8978: fix a memory leak if a wm8978_register fail

There is a memory leak found if wm8978_register() fail.
This patch moves the buffer allocate and release
at the same level to prevent the memory leak.

Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
 sound/soc/codecs/wm8978.c |   10 +++++++---
 1 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/sound/soc/codecs/wm8978.c b/sound/soc/codecs/wm8978.c
index 51d5f43..8a1ad77 100644
--- a/sound/soc/codecs/wm8978.c
+++ b/sound/soc/codecs/wm8978.c
@@ -1076,7 +1076,6 @@ static __devinit int wm8978_register(struct wm8978_priv *wm8978)
 err_codec:
 	snd_soc_unregister_codec(codec);
 err:
-	kfree(wm8978);
 	return ret;
 }
 
@@ -1085,13 +1084,13 @@ static __devexit void wm8978_unregister(struct wm8978_priv *wm8978)
 	wm8978_set_bias_level(&wm8978->codec, SND_SOC_BIAS_OFF);
 	snd_soc_unregister_dai(&wm8978_dai);
 	snd_soc_unregister_codec(&wm8978->codec);
-	kfree(wm8978);
 	wm8978_codec = NULL;
 }
 
 static __devinit int wm8978_i2c_probe(struct i2c_client *i2c,
 				      const struct i2c_device_id *id)
 {
+	int ret;
 	struct wm8978_priv *wm8978;
 	struct snd_soc_codec *codec;
 
@@ -1107,13 +1106,18 @@ static __devinit int wm8978_i2c_probe(struct i2c_client *i2c,
 
 	codec->dev = &i2c->dev;
 
-	return wm8978_register(wm8978);
+	ret = wm8978_register(wm8978);
+	if (ret < 0)
+		kfree(wm8978);
+
+	return ret;
 }
 
 static __devexit int wm8978_i2c_remove(struct i2c_client *client)
 {
 	struct wm8978_priv *wm8978 = i2c_get_clientdata(client);
 	wm8978_unregister(wm8978);
+	kfree(wm8978);
 	return 0;
 }
 
-- 
1.5.4.3

  reply	other threads:[~2010-07-15  8:37 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-07-15  2:49 [PATCH 0/12] sound/alsa/soc/codec: fix memory leak and resource relaim in error path Axel Lin
2010-07-15  2:50 ` [PATCH 1/12] ad1836: fix a memory leak if another ad1836 is registered Axel Lin
2010-07-20 10:31   ` Barry Song
2010-07-15  2:52 ` [PATCH 2/12] ak4642: fix a memory leak if failed to initialise AK4642 Axel Lin
2010-07-15  5:53   ` Kuninori Morimoto
2010-07-15  6:19     ` Axel Lin
2010-07-15  6:29       ` Kuninori Morimoto
2010-07-15  2:53 ` [PATCH 3/12] da7210: fix a memory leak if failed to initialise da7210 audio codec Axel Lin
2010-07-15  2:56 ` [PATCH 4/12] wm8523: fix resource reclaim in wm8523_register error path Axel Lin
2010-07-15  2:57 ` [PATCH 5/12] wm8711: fix a memory leak if another WM8711 is registered Axel Lin
2010-07-15  2:59 ` [PATCH 6/12] wm8904: fix resource reclaim in wm8904_register error path Axel Lin
2010-07-15  3:01 ` [PATCH 7/12] wm8940: fix resource reclaim in wm8940_register " Axel Lin
2010-07-15  7:04   ` Guennadi Liakhovetski
2010-07-15  7:42     ` Axel Lin
2010-07-15  7:59       ` Guennadi Liakhovetski
2010-07-15  8:54       ` Liam Girdwood
2010-07-15  7:48   ` [PATCH v2 7/12] wm8940: fix a memory leak if wm8940_register return error Axel Lin
2010-07-15  3:03 ` [PATCH 8/12] wm8955: fix resource reclaim in wm8955_register error path Axel Lin
2010-07-15  3:06 ` [PATCH 9/12] wm8961: fix resource reclaim in wm8961_register " Axel Lin
2010-07-15  3:07 ` [PATCH 10/12] wm8974: fix a memory leak if another WM8974 is registered Axel Lin
2010-07-15  3:08 ` [PATCH 11/12] wm8978: fix a memory leak if another WM8978 " Axel Lin
2010-07-15  8:37   ` Axel Lin [this message]
2010-07-15  8:53     ` [PATCH v2 " Guennadi Liakhovetski
2010-07-15  3:11 ` [PATCH 12/12] wm9081: fix resource reclaim in wm9081_register error path Axel Lin
2010-07-15  8:59 ` [PATCH 0/12] sound/alsa/soc/codec: fix memory leak and resource relaim in " Mark Brown
2010-07-19  1:41   ` Axel Lin

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=1279183026.10733.2.camel@mola \
    --to=axel.lin@gmail.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=g.liakhovetski@gmx.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lrg@slimlogic.co.uk \
    --cc=perex@perex.cz \
    --cc=tiwai@suse.de \
    --cc=tj@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).