mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sound: initialize rawmidi substream list
@ 2006-11-22 18:50 Akinobu Mita
  2006-11-23 11:06 ` Takashi Iwai
  0 siblings, 1 reply; 2+ messages in thread
From: Akinobu Mita @ 2006-11-22 18:50 UTC (permalink / raw)
  To: linux-kernel; +Cc: Takashi Iwai, Jaroslav Kysela

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 <tiwai@suse.de>
Cc: Jaroslav Kysela <perex@suse.cz>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>

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

Index: work-fault-inject/sound/core/rawmidi.c
===================================================================
--- work-fault-inject.orig/sound/core/rawmidi.c
+++ 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,

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] sound: initialize rawmidi substream list
  2006-11-22 18:50 [PATCH] sound: initialize rawmidi substream list Akinobu Mita
@ 2006-11-23 11:06 ` Takashi Iwai
  0 siblings, 0 replies; 2+ messages in thread
From: Takashi Iwai @ 2006-11-23 11:06 UTC (permalink / raw)
  To: Akinobu Mita; +Cc: linux-kernel, Jaroslav Kysela

At Thu, 23 Nov 2006 03:50:45 +0900,
Akinobu Mita wrote:
> 
> 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 <tiwai@suse.de>
> Cc: Jaroslav Kysela <perex@suse.cz>
> Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>

Thanks, merged to ALSA tree.


Takashi

> 
>  sound/core/rawmidi.c |    4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> Index: work-fault-inject/sound/core/rawmidi.c
> ===================================================================
> --- work-fault-inject.orig/sound/core/rawmidi.c
> +++ 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,
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2006-11-23 11:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-22 18:50 [PATCH] sound: initialize rawmidi substream list Akinobu Mita
2006-11-23 11:06 ` Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®