Explorar o código

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 <segooon@gmail.com>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Kulikov Vasiliy %!s(int64=15) %!d(string=hai) anos
pai
achega
51b6dfb627
Modificáronse 1 ficheiros con 5 adicións e 1 borrados
  1. 5 1
      sound/soc/imx/imx-pcm-dma-mx2.c

+ 5 - 1
sound/soc/imx/imx-pcm-dma-mx2.c

@@ -292,12 +292,16 @@ static int snd_imx_open(struct snd_pcm_substream *substream)
 	int ret;
 	int ret;
 
 
 	iprtd = kzalloc(sizeof(*iprtd), GFP_KERNEL);
 	iprtd = kzalloc(sizeof(*iprtd), GFP_KERNEL);
+	if (iprtd == NULL)
+		return -ENOMEM;
 	runtime->private_data = iprtd;
 	runtime->private_data = iprtd;
 
 
 	ret = snd_pcm_hw_constraint_integer(substream->runtime,
 	ret = snd_pcm_hw_constraint_integer(substream->runtime,
 			SNDRV_PCM_HW_PARAM_PERIODS);
 			SNDRV_PCM_HW_PARAM_PERIODS);
-	if (ret < 0)
+	if (ret < 0) {
+		kfree(iprtd);
 		return ret;
 		return ret;
+	}
 
 
 	snd_soc_set_runtime_hwparams(substream, &snd_imx_hardware);
 	snd_soc_set_runtime_hwparams(substream, &snd_imx_hardware);
 	return 0;
 	return 0;