]> pilppa.com Git - linux-2.6-omap-h63xx.git/commitdiff
ALSA: rawmidi - Fix possible race in open
authorTakashi Iwai <tiwai@suse.de>
Wed, 11 Feb 2009 13:55:59 +0000 (14:55 +0100)
committerTakashi Iwai <tiwai@suse.de>
Mon, 9 Mar 2009 14:17:21 +0000 (15:17 +0100)
The module refcount should be handled in the register_mutex to avoid
possible races with module unloading.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/rawmidi.c

index 002777ba336aea636cd0a5c54d54934c87867bd8..60f33e9412ad3daa57da67990ab8acfc7bf2867d 100644 (file)
@@ -237,15 +237,16 @@ int snd_rawmidi_kernel_open(struct snd_card *card, int device, int subdevice,
                rfile->input = rfile->output = NULL;
        mutex_lock(&register_mutex);
        rmidi = snd_rawmidi_search(card, device);
-       mutex_unlock(&register_mutex);
        if (rmidi == NULL) {
-               err = -ENODEV;
-               goto __error1;
+               mutex_unlock(&register_mutex);
+               return -ENODEV;
        }
        if (!try_module_get(rmidi->card->module)) {
-               err = -EFAULT;
-               goto __error1;
+               mutex_unlock(&register_mutex);
+               return -ENXIO;
        }
+       mutex_unlock(&register_mutex);
+
        if (!(mode & SNDRV_RAWMIDI_LFLG_NOOPENLOCK))
                mutex_lock(&rmidi->open_mutex);
        if (mode & SNDRV_RAWMIDI_LFLG_INPUT) {
@@ -370,10 +371,9 @@ int snd_rawmidi_kernel_open(struct snd_card *card, int device, int subdevice,
                snd_rawmidi_runtime_free(sinput);
        if (output != NULL)
                snd_rawmidi_runtime_free(soutput);
-       module_put(rmidi->card->module);
        if (!(mode & SNDRV_RAWMIDI_LFLG_NOOPENLOCK))
                mutex_unlock(&rmidi->open_mutex);
-      __error1:
+       module_put(rmidi->card->module);
        return err;
 }