From: Takashi Iwai Date: Wed, 11 Feb 2009 13:55:59 +0000 (+0100) Subject: ALSA: rawmidi - Fix possible race in open X-Git-Tag: v2.6.30-rc1~676^2~26^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f9d202833d0beac09ef1c6a41305151da4fe5d4c;p=profile%2Fivi%2Fkernel-x86-ivi.git 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 --- diff --git a/sound/core/rawmidi.c b/sound/core/rawmidi.c index 002777b..60f33e9 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(®ister_mutex); rmidi = snd_rawmidi_search(card, device); - mutex_unlock(®ister_mutex); if (rmidi == NULL) { - err = -ENODEV; - goto __error1; + mutex_unlock(®ister_mutex); + return -ENODEV; } if (!try_module_get(rmidi->card->module)) { - err = -EFAULT; - goto __error1; + mutex_unlock(®ister_mutex); + return -ENXIO; } + mutex_unlock(®ister_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; }