Commit d484366b authored by Axel Lin's avatar Axel Lin Committed by Mark Brown

ASoC: 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: default avatarAxel Lin <axel.lin@gmail.com>
Reviewed-by: default avatarGuennadi Liakhovetski <g.liakhovetski@gmx.de>
Acked-by: default avatarLiam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: default avatarMark Brown <broonie@opensource.wolfsonmicro.com>
parent 4eaac505
...@@ -1076,7 +1076,6 @@ static __devinit int wm8978_register(struct wm8978_priv *wm8978) ...@@ -1076,7 +1076,6 @@ static __devinit int wm8978_register(struct wm8978_priv *wm8978)
err_codec: err_codec:
snd_soc_unregister_codec(codec); snd_soc_unregister_codec(codec);
err: err:
kfree(wm8978);
return ret; return ret;
} }
...@@ -1085,13 +1084,13 @@ static __devexit void wm8978_unregister(struct wm8978_priv *wm8978) ...@@ -1085,13 +1084,13 @@ static __devexit void wm8978_unregister(struct wm8978_priv *wm8978)
wm8978_set_bias_level(&wm8978->codec, SND_SOC_BIAS_OFF); wm8978_set_bias_level(&wm8978->codec, SND_SOC_BIAS_OFF);
snd_soc_unregister_dai(&wm8978_dai); snd_soc_unregister_dai(&wm8978_dai);
snd_soc_unregister_codec(&wm8978->codec); snd_soc_unregister_codec(&wm8978->codec);
kfree(wm8978);
wm8978_codec = NULL; wm8978_codec = NULL;
} }
static __devinit int wm8978_i2c_probe(struct i2c_client *i2c, static __devinit int wm8978_i2c_probe(struct i2c_client *i2c,
const struct i2c_device_id *id) const struct i2c_device_id *id)
{ {
int ret;
struct wm8978_priv *wm8978; struct wm8978_priv *wm8978;
struct snd_soc_codec *codec; struct snd_soc_codec *codec;
...@@ -1107,13 +1106,18 @@ static __devinit int wm8978_i2c_probe(struct i2c_client *i2c, ...@@ -1107,13 +1106,18 @@ static __devinit int wm8978_i2c_probe(struct i2c_client *i2c,
codec->dev = &i2c->dev; 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) static __devexit int wm8978_i2c_remove(struct i2c_client *client)
{ {
struct wm8978_priv *wm8978 = i2c_get_clientdata(client); struct wm8978_priv *wm8978 = i2c_get_clientdata(client);
wm8978_unregister(wm8978); wm8978_unregister(wm8978);
kfree(wm8978);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment