aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/wm8750.c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2008-08-25 06:49:20 -0400
committerTakashi Iwai <tiwai@suse.de>2008-08-25 07:49:52 -0400
commit3051e41ab7daaa59d4564f20b25dcb8c03f35f2b (patch)
tree0908f13da020b0e6e5d025caa60b1fed4c056abc /sound/soc/codecs/wm8750.c
parentc5d44423d55e3abca7b1d544af9e4c97ec203999 (diff)
ALSA: ASoC: Fix double free and memory leak in many codec drivers
Many SoC audio codec drivers have improper freeing of memory in error paths. * codec is allocated in the platform device probe function, but is not freed there in case of error. Instead it is freed in the i2c device probe function's error path. However the success or failure of both functions is not linked, so this could result in a double free (if the platform device is successfully probed, the i2c device probing fails and then the platform driver is unregistered.) * codec->private_data is allocated in many platform device probe functions but not freed in their error paths. This patch hopefully solves all these problems. Signed-off-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/soc/codecs/wm8750.c')
-rw-r--r--sound/soc/codecs/wm8750.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/sound/soc/codecs/wm8750.c b/sound/soc/codecs/wm8750.c
index c6a8edf302a..dd1f55404b2 100644
--- a/sound/soc/codecs/wm8750.c
+++ b/sound/soc/codecs/wm8750.c
@@ -869,10 +869,9 @@ static int wm8750_codec_probe(struct i2c_adapter *adap, int addr, int kind)
869 client_template.addr = addr; 869 client_template.addr = addr;
870 870
871 i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL); 871 i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL);
872 if (i2c == NULL) { 872 if (i2c == NULL)
873 kfree(codec);
874 return -ENOMEM; 873 return -ENOMEM;
875 } 874
876 i2c_set_clientdata(i2c, codec); 875 i2c_set_clientdata(i2c, codec);
877 codec->control_data = i2c; 876 codec->control_data = i2c;
878 877
@@ -890,7 +889,6 @@ static int wm8750_codec_probe(struct i2c_adapter *adap, int addr, int kind)
890 return ret; 889 return ret;
891 890
892err: 891err:
893 kfree(codec);
894 kfree(i2c); 892 kfree(i2c);
895 return ret; 893 return ret;
896} 894}
@@ -966,6 +964,10 @@ static int wm8750_probe(struct platform_device *pdev)
966 /* Add other interfaces here */ 964 /* Add other interfaces here */
967#endif 965#endif
968 966
967 if (ret != 0) {
968 kfree(codec->private_data);
969 kfree(codec);
970 }
969 return ret; 971 return ret;
970} 972}
971 973