]> git.kernelconcepts.de Git - karo-tx-linux.git/commit
ALSA: usb-audio: Fix mutex deadlock at disconnection
authorTakashi Iwai <tiwai@suse.de>
Tue, 13 Nov 2012 10:22:48 +0000 (11:22 +0100)
committerBen Hutchings <ben@decadent.org.uk>
Fri, 16 Nov 2012 16:47:21 +0000 (16:47 +0000)
commitc585c4e138c4688a1492e7f8f0515eadae653040
tree366d38d50b5e38639432843f203c83a50752bd20
parentbaf6d74e8693f8e71ccd2c47f0e1ee4480c9744f
ALSA: usb-audio: Fix mutex deadlock at disconnection

commit 10e44239f67d0b6fb74006e61a7e883b8075247a upstream.

The recent change for USB-audio disconnection race fixes introduced a
mutex deadlock again.  There is a circular dependency between
chip->shutdown_rwsem and pcm->open_mutex, depicted like below, when a
device is opened during the disconnection operation:

A. snd_usb_audio_disconnect() ->
     card.c::register_mutex ->
       chip->shutdown_rwsem (write) ->
         snd_card_disconnect() ->
           pcm.c::register_mutex ->
             pcm->open_mutex

B. snd_pcm_open() ->
     pcm->open_mutex ->
       snd_usb_pcm_open() ->
         chip->shutdown_rwsem (read)

Since the chip->shutdown_rwsem protection in the case A is required
only for turning on the chip->shutdown flag and it doesn't have to be
taken for the whole operation, we can reduce its window in
snd_usb_audio_disconnect().

Reported-by: Jiri Slaby <jslaby@suse.cz>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
sound/usb/card.c