Skip to content

Commit

Permalink
ALSA: rawmidi - Fix possible race in open
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
tiwai committed Mar 9, 2009
1 parent fec6c6f commit f9d2028
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions sound/core/rawmidi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit f9d2028

Please sign in to comment.