summaryrefslogtreecommitdiffstats
path: root/sound/core/rawmidi.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2009-02-11 14:55:59 +0100
committerTakashi Iwai <tiwai@suse.de>2009-03-09 15:17:21 +0100
commitf9d202833d0beac09ef1c6a41305151da4fe5d4c (patch)
tree4bd6b75853a5bad34fb17d95afa33b1e3f4997bb /sound/core/rawmidi.c
parentfec6c6fec3e20637bee5d276fb61dd8b49a3f9cc (diff)
ALSA: rawmidi - Fix possible race in open
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>
Diffstat (limited to 'sound/core/rawmidi.c')
-rw-r--r--sound/core/rawmidi.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c
index 002777ba336..60f33e9412a 100644
--- a/sound/core/rawmidi.c
+++ b/sound/core/rawmidi.c
@@ -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;
}