aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs/wm8753.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/wm8753.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/wm8753.c')
-rw-r--r--sound/soc/codecs/wm8753.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c
index 8604809f0c36..35bf1c369870 100644
--- a/sound/soc/codecs/wm8753.c
+++ b/sound/soc/codecs/wm8753.c
@@ -1661,10 +1661,9 @@ static int wm8753_codec_probe(struct i2c_adapter *adap, int addr, int kind)
1661 client_template.addr = addr; 1661 client_template.addr = addr;
1662 1662
1663 i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL); 1663 i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL);
1664 if (!i2c) { 1664 if (!i2c)
1665 kfree(codec);
1666 return -ENOMEM; 1665 return -ENOMEM;
1667 } 1666
1668 i2c_set_clientdata(i2c, codec); 1667 i2c_set_clientdata(i2c, codec);
1669 codec->control_data = i2c; 1668 codec->control_data = i2c;
1670 1669
@@ -1683,7 +1682,6 @@ static int wm8753_codec_probe(struct i2c_adapter *adap, int addr, int kind)
1683 return ret; 1682 return ret;
1684 1683
1685err: 1684err:
1686 kfree(codec);
1687 kfree(i2c); 1685 kfree(i2c);
1688 return ret; 1686 return ret;
1689} 1687}
@@ -1760,6 +1758,11 @@ static int wm8753_probe(struct platform_device *pdev)
1760#else 1758#else
1761 /* Add other interfaces here */ 1759 /* Add other interfaces here */
1762#endif 1760#endif
1761
1762 if (ret != 0) {
1763 kfree(codec->private_data);
1764 kfree(codec);
1765 }
1763 return ret; 1766 return ret;
1764} 1767}
1765 1768