Skip to content

Commit

Permalink
ASoC: imx: check kzalloc() result and fix memory leak
Browse files Browse the repository at this point in the history
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 <segooon@gmail.com>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
  • Loading branch information
Kulikov Vasiliy authored and Mark Brown committed Jul 17, 2010
1 parent 51b6dfb commit 50e8ce1
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion sound/soc/imx/imx-pcm-fiq.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ 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;

iprtd->substream = substream;
Expand All @@ -202,8 +204,10 @@ static int snd_imx_open(struct snd_pcm_substream *substream)

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;
Expand Down

0 comments on commit 50e8ce1

Please sign in to comment.