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: Axel Lin <axel.lin@gmail.com>
Reviewed-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>

authored by Axel Lin and committed by Mark Brown d484366b 4eaac505

+7 -3
+7 -3
sound/soc/codecs/wm8978.c
··· 1076 1076 err_codec: 1077 1077 snd_soc_unregister_codec(codec); 1078 1078 err: 1079 - kfree(wm8978); 1080 1079 return ret; 1081 1080 } 1082 1081 ··· 1084 1085 wm8978_set_bias_level(&wm8978->codec, SND_SOC_BIAS_OFF); 1085 1086 snd_soc_unregister_dai(&wm8978_dai); 1086 1087 snd_soc_unregister_codec(&wm8978->codec); 1087 - kfree(wm8978); 1088 1088 wm8978_codec = NULL; 1089 1089 } 1090 1090 1091 1091 static __devinit int wm8978_i2c_probe(struct i2c_client *i2c, 1092 1092 const struct i2c_device_id *id) 1093 1093 { 1094 + int ret; 1094 1095 struct wm8978_priv *wm8978; 1095 1096 struct snd_soc_codec *codec; 1096 1097 ··· 1106 1107 1107 1108 codec->dev = &i2c->dev; 1108 1109 1109 - return wm8978_register(wm8978); 1110 + ret = wm8978_register(wm8978); 1111 + if (ret < 0) 1112 + kfree(wm8978); 1113 + 1114 + return ret; 1110 1115 } 1111 1116 1112 1117 static __devexit int wm8978_i2c_remove(struct i2c_client *client) 1113 1118 { 1114 1119 struct wm8978_priv *wm8978 = i2c_get_clientdata(client); 1115 1120 wm8978_unregister(wm8978); 1121 + kfree(wm8978); 1116 1122 return 0; 1117 1123 } 1118 1124