diff options
author | Subhransu S. Prusty <subhransu.s.prusty@intel.com> | 2016-02-17 11:03:59 -0500 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2016-02-19 10:56:53 -0500 |
commit | 6793a3d70676c6f3d2ec0ce4e1e241617541702c (patch) | |
tree | eb9d4feb9c90fef1cda112fe65adf8f2b7a6c4b5 | |
parent | cd890ade492784ae06dadd20e688ba1760d3c801 (diff) |
ASoC: hdac_hdmi: Fix possible memory leak in hw_params
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>
-rw-r--r-- | sound/soc/codecs/hdac_hdmi.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/sound/soc/codecs/hdac_hdmi.c b/sound/soc/codecs/hdac_hdmi.c index 2884dbf0bc07..d2a2e1882fdd 100644 --- a/sound/soc/codecs/hdac_hdmi.c +++ b/sound/soc/codecs/hdac_hdmi.c | |||
@@ -405,9 +405,13 @@ static int hdac_hdmi_set_hw_params(struct snd_pcm_substream *substream, | |||
405 | return -ENODEV; | 405 | return -ENODEV; |
406 | } | 406 | } |
407 | 407 | ||
408 | dd = kzalloc(sizeof(*dd), GFP_KERNEL); | 408 | dd = snd_soc_dai_get_dma_data(dai, substream); |
409 | if (!dd) | 409 | if (!dd) { |
410 | return -ENOMEM; | 410 | dd = kzalloc(sizeof(*dd), GFP_KERNEL); |
411 | if (!dd) | ||
412 | return -ENOMEM; | ||
413 | } | ||
414 | |||
411 | dd->format = snd_hdac_calc_stream_format(params_rate(hparams), | 415 | dd->format = snd_hdac_calc_stream_format(params_rate(hparams), |
412 | params_channels(hparams), params_format(hparams), | 416 | params_channels(hparams), params_format(hparams), |
413 | 24, 0); | 417 | 24, 0); |
@@ -433,9 +437,11 @@ static int hdac_hdmi_playback_cleanup(struct snd_pcm_substream *substream, | |||
433 | AC_VERB_SET_STREAM_FORMAT, 0); | 437 | AC_VERB_SET_STREAM_FORMAT, 0); |
434 | 438 | ||
435 | dd = (struct hdac_ext_dma_params *)snd_soc_dai_get_dma_data(dai, substream); | 439 | dd = (struct hdac_ext_dma_params *)snd_soc_dai_get_dma_data(dai, substream); |
436 | snd_soc_dai_set_dma_data(dai, substream, NULL); | ||
437 | 440 | ||
438 | kfree(dd); | 441 | if (dd) { |
442 | snd_soc_dai_set_dma_data(dai, substream, NULL); | ||
443 | kfree(dd); | ||
444 | } | ||
439 | 445 | ||
440 | return 0; | 446 | return 0; |
441 | } | 447 | } |