Skip to contentSkip to conversation

sound: initialize rawmidi substream list

PATCH In review Akinobu Mita 2 participants 2 messages Nov 22, 2006 – Nov 23, 2006 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sound: initialize rawmidi substream list

If snd_rawmidi_new() failed to allocate substreams for input (snd_rawmidi_alloc_substreams() failed to populate a &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT]), it will try to free rawmidi instance by snd_rawmidi_free().

But it will cause oops because snd_rawmidi_free() tries to free both of substreams list but list for output (&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT]) is not initialized yet.

Cc Takashi Iwai <[email protected]>
Cc Jaroslav Kysela <[email protected]>
 sound/core/rawmidi.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
sound/core/rawmidi.c +3 -1
Index: work-fault-inject/sound/core/rawmidi.c
===================================================================
@@ -1379,7 +1379,6 @@ static int snd_rawmidi_alloc_substreams(
 	struct snd_rawmidi_substream *substream;
 	int idx;
 
-	INIT_LIST_HEAD(&stream->substreams);
 	for (idx = 0; idx < count; idx++) {
 		substream = kzalloc(sizeof(*substream), GFP_KERNEL);
 		if (substream == NULL) {
@@ -1434,6 +1433,9 @@ int snd_rawmidi_new(struct snd_card *car
 	rmidi->device = device;
 	mutex_init(&rmidi->open_mutex);
 	init_waitqueue_head(&rmidi->open_wait);
+	INIT_LIST_HEAD(&rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams);
+	INIT_LIST_HEAD(&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams);
+
 	if (id != NULL)
 		strlcpy(rmidi->id, id, sizeof(rmidi->id));
 	if ((err = snd_rawmidi_alloc_substreams(rmidi,
#1 lore raw

At Thu, 23 Nov 2006 03:50:45 +0900,

Quoted 6 lines · Akinobu Mita

If snd_rawmidi_new() failed to allocate substreams for input (snd_rawmidi_alloc_substreams() failed to populate a &rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT]), it will try to free rawmidi instance by snd_rawmidi_free().

Quoted 7 lines

But it will cause oops because snd_rawmidi_free() tries to free both of substreams list but list for output (&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT]) is not initialized yet.

Cc Takashi Iwai <[email protected]>
Cc Jaroslav Kysela <[email protected]>

Thanks, merged to ALSA tree.

Takashi

Quoted 27 lines
 sound/core/rawmidi.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

Index: work-fault-inject/sound/core/rawmidi.c
===================================================================

sound/core/rawmidi.c +3 -1
@@ -1379,7 +1379,6 @@ static int snd_rawmidi_alloc_substreams(
 	struct snd_rawmidi_substream *substream;
 	int idx;
 
-	INIT_LIST_HEAD(&stream->substreams);
 	for (idx = 0; idx < count; idx++) {
 		substream = kzalloc(sizeof(*substream), GFP_KERNEL);
 		if (substream == NULL) {
@@ -1434,6 +1433,9 @@ int snd_rawmidi_new(struct snd_card *car
 	rmidi->device = device;
 	mutex_init(&rmidi->open_mutex);
 	init_waitqueue_head(&rmidi->open_wait);
+	INIT_LIST_HEAD(&rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT].substreams);
+	INIT_LIST_HEAD(&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT].substreams);
+
 	if (id != NULL)
 		strlcpy(rmidi->id, id, sizeof(rmidi->id));
 	if ((err = snd_rawmidi_alloc_substreams(rmidi,