]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - sound/soc/codecs/wm8731.c
ALSA: ASoC: Fix double free and memory leak in many codec drivers
[linux-2.6-omap-h63xx.git] / sound / soc / codecs / wm8731.c
index 77880537a3cda1dfa34407ef10171a31bb4a36c8..9402fcaf04fa50b0c1c71bf2f3026e3aa0985ec8 100644 (file)
 #define AUDIO_NAME "wm8731"
 #define WM8731_VERSION "0.13"
 
-/*
- * Debug
- */
-
-#define WM8731_DEBUG 0
-
-#ifdef WM8731_DEBUG
-#define dbg(format, arg...) \
-       printk(KERN_DEBUG AUDIO_NAME ": " format "\n" , ## arg)
-#else
-#define dbg(format, arg...) do {} while (0)
-#endif
-#define err(format, arg...) \
-       printk(KERN_ERR AUDIO_NAME ": " format "\n" , ## arg)
-#define info(format, arg...) \
-       printk(KERN_INFO AUDIO_NAME ": " format "\n" , ## arg)
-#define warn(format, arg...) \
-       printk(KERN_WARNING AUDIO_NAME ": " format "\n" , ## arg)
-
 struct snd_soc_codec_device soc_codec_dev_wm8731;
 
 /* codec private data */
@@ -337,7 +318,7 @@ static void wm8731_shutdown(struct snd_pcm_substream *substream)
        }
 }
 
-static int wm8731_mute(struct snd_soc_codec_dai *dai, int mute)
+static int wm8731_mute(struct snd_soc_dai *dai, int mute)
 {
        struct snd_soc_codec *codec = dai->codec;
        u16 mute_reg = wm8731_read_reg_cache(codec, WM8731_APDIGI) & 0xfff7;
@@ -349,7 +330,7 @@ static int wm8731_mute(struct snd_soc_codec_dai *dai, int mute)
        return 0;
 }
 
-static int wm8731_set_dai_sysclk(struct snd_soc_codec_dai *codec_dai,
+static int wm8731_set_dai_sysclk(struct snd_soc_dai *codec_dai,
                int clk_id, unsigned int freq, int dir)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
@@ -368,7 +349,7 @@ static int wm8731_set_dai_sysclk(struct snd_soc_codec_dai *codec_dai,
 }
 
 
-static int wm8731_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
+static int wm8731_set_dai_fmt(struct snd_soc_dai *codec_dai,
                unsigned int fmt)
 {
        struct snd_soc_codec *codec = codec_dai->codec;
@@ -462,7 +443,7 @@ static int wm8731_set_bias_level(struct snd_soc_codec *codec,
 #define WM8731_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
        SNDRV_PCM_FMTBIT_S24_LE)
 
-struct snd_soc_codec_dai wm8731_dai = {
+struct snd_soc_dai wm8731_dai = {
        .name = "WM8731",
        .playback = {
                .stream_name = "Playback",
@@ -615,28 +596,26 @@ static int wm8731_codec_probe(struct i2c_adapter *adap, int addr, int kind)
        client_template.addr = addr;
 
        i2c = kmemdup(&client_template, sizeof(client_template), GFP_KERNEL);
-       if (i2c == NULL) {
-               kfree(codec);
+       if (i2c == NULL)
                return -ENOMEM;
-       }
+
        i2c_set_clientdata(i2c, codec);
        codec->control_data = i2c;
 
        ret = i2c_attach_client(i2c);
        if (ret < 0) {
-               err("failed to attach codec at addr %x\n", addr);
+               pr_err("failed to attach codec at addr %x\n", addr);
                goto err;
        }
 
        ret = wm8731_init(socdev);
        if (ret < 0) {
-               err("failed to initialise WM8731\n");
+               pr_err("failed to initialise WM8731\n");
                goto err;
        }
        return ret;
 
 err:
-       kfree(codec);
        kfree(i2c);
        return ret;
 }
@@ -681,7 +660,7 @@ static int wm8731_probe(struct platform_device *pdev)
        struct wm8731_priv *wm8731;
        int ret = 0;
 
-       info("WM8731 Audio Codec %s", WM8731_VERSION);
+       pr_info("WM8731 Audio Codec %s", WM8731_VERSION);
 
        setup = socdev->codec_data;
        codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
@@ -712,6 +691,11 @@ static int wm8731_probe(struct platform_device *pdev)
 #else
        /* Add other interfaces here */
 #endif
+
+       if (ret != 0) {
+               kfree(codec->private_data);
+               kfree(codec);
+       }
        return ret;
 }