[alsa-devel] [RFC][PATCH] ALSA: pcm_native.c initialize drec and num_drecs before it get used

Jaswinder Singh Rajput jaswinder at kernel.org
Sat Sep 12 20:17:45 CEST 2009


[This is untested]

drec and num_drecs is used uninitialized for nonblock(goto lock)

This also fixed following compilation warnings :

  CC [M]  sound/core/pcm_native.o
sound/core/pcm_native.c: In function ‘snd_pcm_drain’:
sound/core/pcm_native.c:1413: warning: ‘drec’ may be used uninitialized in this function
sound/core/pcm_native.c:1411: warning: ‘num_drecs’ may be used uninitialized in this function

Signed-off-by: Jaswinder Singh Rajput <jaswinderrajput at gmail.com>
---
 sound/core/pcm_native.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 59e5fbe..8284dc1 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -1433,6 +1433,9 @@ static int snd_pcm_drain(struct snd_pcm_substream *substream,
 	} else if (substream->f_flags & O_NONBLOCK)
 		nonblock = 1;
 
+	drec = &drec_tmp;
+	num_drecs = 0;
+
 	if (nonblock)
 		goto lock; /* no need to allocate waitqueues */
 
@@ -1445,11 +1448,9 @@ static int snd_pcm_drain(struct snd_pcm_substream *substream,
 			snd_power_unlock(card);
 			return -ENOMEM;
 		}
-	} else
-		drec = &drec_tmp;
+	}
 
 	/* count only playback streams */
-	num_drecs = 0;
 	snd_pcm_group_for_each_entry(s, substream) {
 		runtime = s->runtime;
 		if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
-- 
1.6.4.2




More information about the Alsa-devel mailing list