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>
This commit is contained in:
parent
fec6c6fec3
commit
f9d202833d
@ -237,15 +237,16 @@ int snd_rawmidi_kernel_open(struct snd_card *card, int device, int subdevice,
|
|||||||
rfile->input = rfile->output = NULL;
|
rfile->input = rfile->output = NULL;
|
||||||
mutex_lock(®ister_mutex);
|
mutex_lock(®ister_mutex);
|
||||||
rmidi = snd_rawmidi_search(card, device);
|
rmidi = snd_rawmidi_search(card, device);
|
||||||
mutex_unlock(®ister_mutex);
|
|
||||||
if (rmidi == NULL) {
|
if (rmidi == NULL) {
|
||||||
err = -ENODEV;
|
mutex_unlock(®ister_mutex);
|
||||||
goto __error1;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
if (!try_module_get(rmidi->card->module)) {
|
if (!try_module_get(rmidi->card->module)) {
|
||||||
err = -EFAULT;
|
mutex_unlock(®ister_mutex);
|
||||||
goto __error1;
|
return -ENXIO;
|
||||||
}
|
}
|
||||||
|
mutex_unlock(®ister_mutex);
|
||||||
|
|
||||||
if (!(mode & SNDRV_RAWMIDI_LFLG_NOOPENLOCK))
|
if (!(mode & SNDRV_RAWMIDI_LFLG_NOOPENLOCK))
|
||||||
mutex_lock(&rmidi->open_mutex);
|
mutex_lock(&rmidi->open_mutex);
|
||||||
if (mode & SNDRV_RAWMIDI_LFLG_INPUT) {
|
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);
|
snd_rawmidi_runtime_free(sinput);
|
||||||
if (output != NULL)
|
if (output != NULL)
|
||||||
snd_rawmidi_runtime_free(soutput);
|
snd_rawmidi_runtime_free(soutput);
|
||||||
module_put(rmidi->card->module);
|
|
||||||
if (!(mode & SNDRV_RAWMIDI_LFLG_NOOPENLOCK))
|
if (!(mode & SNDRV_RAWMIDI_LFLG_NOOPENLOCK))
|
||||||
mutex_unlock(&rmidi->open_mutex);
|
mutex_unlock(&rmidi->open_mutex);
|
||||||
__error1:
|
module_put(rmidi->card->module);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user