diff mbox

[3/6] ASoC: Samsung-dma: Fix potential NULL pointer dereference

Message ID 1353488819-13902-3-git-send-email-sachin.kamat@linaro.org
State Accepted
Headers show

Commit Message

Sachin Kamat Nov. 21, 2012, 9:06 a.m. UTC
'substream' was dereferenced before the NULL check.
Moved the check earlier to prevent NULL pointer dereference.

Cc: Sangbeom Kim <sbkim73@samsung.com>
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>
Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
---
Build tested and based on linux-next 20121115.
---
 sound/soc/samsung/dma.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

Comments

Mark Brown Dec. 2, 2012, 4:12 a.m. UTC | #1
On Wed, Nov 21, 2012 at 02:36:56PM +0530, Sachin Kamat wrote:

>  static void audio_buffdone(void *data)
>  {
>  	struct snd_pcm_substream *substream = data;
> -	struct runtime_data *prtd = substream->runtime->private_data;
> +	struct runtime_data *prtd;

This should be a BUG_ON() or something rather than just a simple warning
- the checks here are redundant, there's no way we should ever end up
completing a buffer without an associated runtime.
diff mbox

Patch

diff --git a/sound/soc/samsung/dma.c b/sound/soc/samsung/dma.c
index b70964e..e59a4f4 100644
--- a/sound/soc/samsung/dma.c
+++ b/sound/soc/samsung/dma.c
@@ -114,17 +114,23 @@  static void dma_enqueue(struct snd_pcm_substream *substream)
 static void audio_buffdone(void *data)
 {
 	struct snd_pcm_substream *substream = data;
-	struct runtime_data *prtd = substream->runtime->private_data;
+	struct runtime_data *prtd;
 
 	pr_debug("Entered %s\n", __func__);
 
+	if (substream) {
+		prtd = substream->runtime->private_data;
+	} else {
+		pr_err("%s: Null data received\n", __func__);
+		return;
+	}
+
 	if (prtd->state & ST_RUNNING) {
 		prtd->dma_pos += prtd->dma_period;
 		if (prtd->dma_pos >= prtd->dma_end)
 			prtd->dma_pos = prtd->dma_start;
 
-		if (substream)
-			snd_pcm_period_elapsed(substream);
+		snd_pcm_period_elapsed(substream);
 
 		spin_lock(&prtd->lock);
 		if (!samsung_dma_has_circular()) {