mirror of
https://github.com/torvalds/linux.git
synced 2026-06-09 23:23:53 +02:00
ALSA: usb-audio: Fix mutex deadlock at disconnection
commit 10e44239f6 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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
3289669090
commit
2ce3809e34
|
|
@ -555,9 +555,11 @@ static void snd_usb_audio_disconnect(struct usb_device *dev,
|
|||
return;
|
||||
|
||||
card = chip->card;
|
||||
mutex_lock(®ister_mutex);
|
||||
down_write(&chip->shutdown_rwsem);
|
||||
chip->shutdown = 1;
|
||||
up_write(&chip->shutdown_rwsem);
|
||||
|
||||
mutex_lock(®ister_mutex);
|
||||
chip->num_interfaces--;
|
||||
if (chip->num_interfaces <= 0) {
|
||||
snd_card_disconnect(card);
|
||||
|
|
@ -574,11 +576,9 @@ static void snd_usb_audio_disconnect(struct usb_device *dev,
|
|||
snd_usb_mixer_disconnect(p);
|
||||
}
|
||||
usb_chip[chip->index] = NULL;
|
||||
up_write(&chip->shutdown_rwsem);
|
||||
mutex_unlock(®ister_mutex);
|
||||
snd_card_free_when_closed(card);
|
||||
} else {
|
||||
up_write(&chip->shutdown_rwsem);
|
||||
mutex_unlock(®ister_mutex);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user