diff options
author | Takashi Iwai <tiwai@suse.de> | 2011-02-22 04:21:18 -0500 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2011-02-23 02:15:43 -0500 |
commit | 382225e62bdb8059b7f915b133426425516dd300 (patch) | |
tree | 25f85ecb38145f3ca1547685066b2bf9057e3c72 /sound/usb/card.c | |
parent | 306496761745942d8167e9193a738b559a7fb0b3 (diff) |
ALSA: usb-audio: fix oops due to cleanup race when disconnecting
When a USB audio device is disconnected, snd_usb_audio_disconnect()
kills all audio URBs. At the same time, the application, after being
notified of the disconnection, might close the device, in which case
ALSA calls the .hw_free callback, which should free the URBs too.
Commit de1b8b93a0ba "[ALSA] Fix hang-up at disconnection of usb-audio"
prevented snd_usb_hw_free() from freeing the URBs to avoid a hang that
resulted from this race, but this introduced another race because the
URB callbacks could now be executed after snd_usb_hw_free() has
returned, and try to access already freed data.
Fix the first race by introducing a mutex to serialize the disconnect
callback and all PCM callbacks that manage URBs (hw_free and hw_params).
Reported-and-tested-by: Pierre-Louis Bossart <pierre-louis.bossart@intel.com>
Cc: <stable@kernel.org>
[CL: also serialize hw_params callback]
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/usb/card.c')
-rw-r--r-- | sound/usb/card.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/sound/usb/card.c b/sound/usb/card.c index 800f7cb4f251..c0f8270bc199 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c | |||
@@ -323,6 +323,7 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx, | |||
323 | return -ENOMEM; | 323 | return -ENOMEM; |
324 | } | 324 | } |
325 | 325 | ||
326 | mutex_init(&chip->shutdown_mutex); | ||
326 | chip->index = idx; | 327 | chip->index = idx; |
327 | chip->dev = dev; | 328 | chip->dev = dev; |
328 | chip->card = card; | 329 | chip->card = card; |
@@ -531,6 +532,7 @@ static void snd_usb_audio_disconnect(struct usb_device *dev, void *ptr) | |||
531 | chip = ptr; | 532 | chip = ptr; |
532 | card = chip->card; | 533 | card = chip->card; |
533 | mutex_lock(®ister_mutex); | 534 | mutex_lock(®ister_mutex); |
535 | mutex_lock(&chip->shutdown_mutex); | ||
534 | chip->shutdown = 1; | 536 | chip->shutdown = 1; |
535 | chip->num_interfaces--; | 537 | chip->num_interfaces--; |
536 | if (chip->num_interfaces <= 0) { | 538 | if (chip->num_interfaces <= 0) { |
@@ -548,9 +550,11 @@ static void snd_usb_audio_disconnect(struct usb_device *dev, void *ptr) | |||
548 | snd_usb_mixer_disconnect(p); | 550 | snd_usb_mixer_disconnect(p); |
549 | } | 551 | } |
550 | usb_chip[chip->index] = NULL; | 552 | usb_chip[chip->index] = NULL; |
553 | mutex_unlock(&chip->shutdown_mutex); | ||
551 | mutex_unlock(®ister_mutex); | 554 | mutex_unlock(®ister_mutex); |
552 | snd_card_free_when_closed(card); | 555 | snd_card_free_when_closed(card); |
553 | } else { | 556 | } else { |
557 | mutex_unlock(&chip->shutdown_mutex); | ||
554 | mutex_unlock(®ister_mutex); | 558 | mutex_unlock(®ister_mutex); |
555 | } | 559 | } |
556 | } | 560 | } |