diff options
| author | Takashi Iwai <tiwai@suse.de> | 2012-11-13 05:22:48 -0500 |
|---|---|---|
| committer | Takashi Iwai <tiwai@suse.de> | 2012-11-14 09:29:09 -0500 |
| commit | 10e44239f67d0b6fb74006e61a7e883b8075247a (patch) | |
| tree | bddffd5e211ccab10512858dce5b4a6cde74db59 | |
| parent | effded75e24c7941961d473e4f4babed4c52af3c (diff) | |
ALSA: usb-audio: Fix mutex deadlock at disconnection
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>
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
| -rw-r--r-- | sound/usb/card.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/sound/usb/card.c b/sound/usb/card.c index 282f0fc9fed1..dbf7999d18b4 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c | |||
| @@ -559,9 +559,11 @@ static void snd_usb_audio_disconnect(struct usb_device *dev, | |||
| 559 | return; | 559 | return; |
| 560 | 560 | ||
| 561 | card = chip->card; | 561 | card = chip->card; |
| 562 | mutex_lock(®ister_mutex); | ||
| 563 | down_write(&chip->shutdown_rwsem); | 562 | down_write(&chip->shutdown_rwsem); |
| 564 | chip->shutdown = 1; | 563 | chip->shutdown = 1; |
| 564 | up_write(&chip->shutdown_rwsem); | ||
| 565 | |||
| 566 | mutex_lock(®ister_mutex); | ||
| 565 | chip->num_interfaces--; | 567 | chip->num_interfaces--; |
| 566 | if (chip->num_interfaces <= 0) { | 568 | if (chip->num_interfaces <= 0) { |
| 567 | snd_card_disconnect(card); | 569 | snd_card_disconnect(card); |
| @@ -582,11 +584,9 @@ static void snd_usb_audio_disconnect(struct usb_device *dev, | |||
| 582 | snd_usb_mixer_disconnect(p); | 584 | snd_usb_mixer_disconnect(p); |
| 583 | } | 585 | } |
| 584 | usb_chip[chip->index] = NULL; | 586 | usb_chip[chip->index] = NULL; |
| 585 | up_write(&chip->shutdown_rwsem); | ||
| 586 | mutex_unlock(®ister_mutex); | 587 | mutex_unlock(®ister_mutex); |
| 587 | snd_card_free_when_closed(card); | 588 | snd_card_free_when_closed(card); |
| 588 | } else { | 589 | } else { |
| 589 | up_write(&chip->shutdown_rwsem); | ||
| 590 | mutex_unlock(®ister_mutex); | 590 | mutex_unlock(®ister_mutex); |
| 591 | } | 591 | } |
| 592 | } | 592 | } |
