From e38f7bcdbf4d26a1b9502a08eacdff6d17fa9895 Mon Sep 17 00:00:00 2001 From: Abhay Date: Thu, 6 Oct 2011 16:18:29 +0100 Subject: [PATCH] ASoC: sn95031: sst_platform: intel_sst: fix errors reported by klocwork Variables in audio driver code need to be freed properly to avoid possible memory leaks. Also the unchecked return of variables from called functions may cause out of bound errors like in case of array indexes. This patch fixes these errors (as pointed by the klocwork )in sst driver and ASoC code by freeing the memory of unused variables and checking on the returned value by called function to array index to avoid posible array out of bound runtime error. Change-Id: I1710889976e0d257ba2e7bede338cc2f056ae095 Signed-off-by: Abhay --- drivers/staging/intel_sst/intel_sst_app_interface.c | 4 +++- drivers/staging/intel_sst/intel_sst_drv_interface.c | 4 ++++ sound/soc/codecs/sn95031.c | 1 + sound/soc/mid-x86/sst_platform.c | 1 + 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/staging/intel_sst/intel_sst_app_interface.c b/drivers/staging/intel_sst/intel_sst_app_interface.c index 813115f..9c22fdd 100644 --- a/drivers/staging/intel_sst/intel_sst_app_interface.c +++ b/drivers/staging/intel_sst/intel_sst_app_interface.c @@ -896,8 +896,10 @@ long intel_sst_ioctl_dsp(unsigned int cmd, unsigned long arg) break; algo_params.reserved = 0; if (copy_from_user(msg->mailbox_data + sizeof(algo_params), - algo_params.params, algo_params.size)) + algo_params.params, algo_params.size)) { + kfree(msg); return -EFAULT; + } retval = sst_send_algo_ipc(&msg); if (retval) { diff --git a/drivers/staging/intel_sst/intel_sst_drv_interface.c b/drivers/staging/intel_sst/intel_sst_drv_interface.c index 6007c1e..4bcebed 100644 --- a/drivers/staging/intel_sst/intel_sst_drv_interface.c +++ b/drivers/staging/intel_sst/intel_sst_drv_interface.c @@ -273,6 +273,10 @@ int sst_get_stream(struct snd_sst_params *str_param) return -EIO; } i = sst_get_block_stream(sst_drv_ctx); + if (i < 0) { + pr_err("sst: invalid value for number of stream\n "); + return -EINVAL; + } response = sst_drv_ctx->alloc_block[i].ops_block.data; pr_debug("alloc block allocated = %d\n", i); if (i < 0) { diff --git a/sound/soc/codecs/sn95031.c b/sound/soc/codecs/sn95031.c index 8e0a2fc..488263a 100644 --- a/sound/soc/codecs/sn95031.c +++ b/sound/soc/codecs/sn95031.c @@ -1150,6 +1150,7 @@ static int sn95031_codec_probe(struct snd_soc_codec *codec) SN95031_AUDIO_DETECT_CODE); if (!audio_adc_handle) { pr_err("invalid ADC handle\n"); + kfree(sn95031_ctx); return -ENOMEM; } diff --git a/sound/soc/mid-x86/sst_platform.c b/sound/soc/mid-x86/sst_platform.c index 06530a4..f2705b3 100644 --- a/sound/soc/mid-x86/sst_platform.c +++ b/sound/soc/mid-x86/sst_platform.c @@ -288,6 +288,7 @@ static int sst_platform_open(struct snd_pcm_substream *substream) /* registering with SST driver to get access to SST APIs to use */ ret_val = register_sst_card(stream->sstdrv_ops); if (ret_val) { + kfree(stream); pr_err("sst: sst card registration failed\n"); goto out_reg_sst; } -- 2.7.4