From: Kulikov Vasiliy Date: Fri, 16 Jul 2010 16:16:34 +0000 (+0400) Subject: ASoC: imx: check kzalloc() result and fix memory leak X-Git-Tag: v3.0~832^2~32^2~657 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=51b6dfb627d785ee92c2bd1e159e2de47cdc29c3;p=platform%2Fkernel%2Flinux-amlogic.git ASoC: imx: check kzalloc() result and fix memory leak If kzalloc() fails we must exit with -ENOMEM. Also we must free allocated runtime->private_data on error as it would be lost on next call to snd_imx_open(). Signed-off-by: Kulikov Vasiliy Acked-by: Liam Girdwood Signed-off-by: Mark Brown --- diff --git a/sound/soc/imx/imx-pcm-dma-mx2.c b/sound/soc/imx/imx-pcm-dma-mx2.c index 05f19c9..0a595da 100644 --- a/sound/soc/imx/imx-pcm-dma-mx2.c +++ b/sound/soc/imx/imx-pcm-dma-mx2.c @@ -292,12 +292,16 @@ static int snd_imx_open(struct snd_pcm_substream *substream) int ret; iprtd = kzalloc(sizeof(*iprtd), GFP_KERNEL); + if (iprtd == NULL) + return -ENOMEM; runtime->private_data = iprtd; ret = snd_pcm_hw_constraint_integer(substream->runtime, SNDRV_PCM_HW_PARAM_PERIODS); - if (ret < 0) + if (ret < 0) { + kfree(iprtd); return ret; + } snd_soc_set_runtime_hwparams(substream, &snd_imx_hardware); return 0;