[alsa-devel] [PATCH] ASoC: Fix passing platform_data to ac97 bus users and fix a leak.

Graham Gower graham.gower at gmail.com
Wed Mar 24 05:29:08 CET 2010


snd_soc_new_ac97_codec() allocates for codec->ac97, snd_soc_new_pcms()
then sets the platform_data. However, snd_ac97_mixer() overwrites
codec->ac97 with its own allocated struct snd_ac97.

Signed-off-by: Graham Gower <graham.gower at gmail.com>
---
 sound/soc/codecs/ac97.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/sound/soc/codecs/ac97.c b/sound/soc/codecs/ac97.c
index a1bbe16..64ec797 100644
--- a/sound/soc/codecs/ac97.c
+++ b/sound/soc/codecs/ac97.c
@@ -80,9 +80,11 @@ static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
 static int ac97_soc_probe(struct platform_device *pdev)
 {
 	struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+	struct snd_soc_card *card = socdev->card;
 	struct snd_soc_codec *codec;
 	struct snd_ac97_bus *ac97_bus;
 	struct snd_ac97_template ac97_template;
+	int i;
 	int ret = 0;
 
 	printk(KERN_INFO "AC97 SoC Audio Codec %s\n", AC97_VERSION);
@@ -118,11 +120,21 @@ static int ac97_soc_probe(struct platform_device *pdev)
 	if (ret < 0)
 		goto bus_err;
 
+	/* free the ac97 here so that we don't leak it in snd_ac97_mixer */
+	snd_soc_free_ac97_codec(codec);
+
 	memset(&ac97_template, 0, sizeof(struct snd_ac97_template));
 	ret = snd_ac97_mixer(ac97_bus, &ac97_template, &codec->ac97);
 	if (ret < 0)
 		goto bus_err;
 
+	for (i = 0; i < card->num_links; i++) {
+		if (card->dai_link[i].codec_dai->ac97_control) {
+			snd_ac97_dev_add_pdata(codec->ac97,
+				card->dai_link[i].cpu_dai->ac97_pdata);
+		}
+	}
+
 	return 0;
 
 bus_err:
-- 
1.6.4



More information about the Alsa-devel mailing list