ASoC: hdac_hdmi: Fix possible memory leak in hw_params
authorSubhransu S. Prusty <subhransu.s.prusty@intel.com>
Wed, 17 Feb 2016 16:03:59 +0000 (21:33 +0530)
committerMark Brown <broonie@kernel.org>
Fri, 19 Feb 2016 15:56:53 +0000 (00:56 +0900)
It's possible for hw_params to be called two times. So add NULL
check to prevent memory leak.

Signed-off-by: Subhransu S. Prusty <subhransu.s.prusty@intel.com>
Signed-off-by: Vinod Koul <vinod.koul@intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/codecs/hdac_hdmi.c

index 2884dbf0bc072ba80d883f475c753d9712998efc..d2a2e1882fdd2288dcca04751b3b0567cffdcdc9 100644 (file)
@@ -405,9 +405,13 @@ static int hdac_hdmi_set_hw_params(struct snd_pcm_substream *substream,
                return -ENODEV;
        }
 
-       dd = kzalloc(sizeof(*dd), GFP_KERNEL);
-       if (!dd)
-               return -ENOMEM;
+       dd = snd_soc_dai_get_dma_data(dai, substream);
+       if (!dd) {
+               dd = kzalloc(sizeof(*dd), GFP_KERNEL);
+               if (!dd)
+                       return -ENOMEM;
+       }
+
        dd->format = snd_hdac_calc_stream_format(params_rate(hparams),
                        params_channels(hparams), params_format(hparams),
                        24, 0);
@@ -433,9 +437,11 @@ static int hdac_hdmi_playback_cleanup(struct snd_pcm_substream *substream,
                                AC_VERB_SET_STREAM_FORMAT, 0);
 
        dd = (struct hdac_ext_dma_params *)snd_soc_dai_get_dma_data(dai, substream);
-       snd_soc_dai_set_dma_data(dai, substream, NULL);
 
-       kfree(dd);
+       if (dd) {
+               snd_soc_dai_set_dma_data(dai, substream, NULL);
+               kfree(dd);
+       }
 
        return 0;
 }