ALSA: rawmidi: Drop register_mutex in snd_rawmidi_free()
authorTakashi Iwai <tiwai@suse.de>
Tue, 11 Oct 2022 07:01:46 +0000 (09:01 +0200)
committerTakashi Iwai <tiwai@suse.de>
Tue, 11 Oct 2022 07:02:32 +0000 (09:02 +0200)
The register_mutex taken around the dev_unregister callback call in
snd_rawmidi_free() may potentially lead to a mutex deadlock, when OSS
emulation and a hot unplug are involved.

Since the mutex doesn't protect the actual race (as the registration
itself is already protected by another means), let's drop it.

Link: https://lore.kernel.org/r/CAB7eexJP7w1B0mVgDF0dQ+gWor7UdkiwPczmL7pn91xx8xpzOA@mail.gmail.com
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20221011070147.7611-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/core/rawmidi.c

index 6963d5a..d8edb60 100644 (file)
@@ -1899,10 +1899,8 @@ static int snd_rawmidi_free(struct snd_rawmidi *rmidi)
 
        snd_info_free_entry(rmidi->proc_entry);
        rmidi->proc_entry = NULL;
-       mutex_lock(&register_mutex);
        if (rmidi->ops && rmidi->ops->dev_unregister)
                rmidi->ops->dev_unregister(rmidi);
-       mutex_unlock(&register_mutex);
 
        snd_rawmidi_free_substreams(&rmidi->streams[SNDRV_RAWMIDI_STREAM_INPUT]);
        snd_rawmidi_free_substreams(&rmidi->streams[SNDRV_RAWMIDI_STREAM_OUTPUT]);