aboutsummaryrefslogtreecommitdiffstats
path: root/sound/usb/card.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2012-10-15 06:16:02 -0400
committerTakashi Iwai <tiwai@suse.de>2012-10-30 06:07:00 -0400
commit34f3c89fda4fba9fe689db22253ca8db2f5e6386 (patch)
tree213e1b6e6ceaee42dc4f9ec74307794dc7a83b20 /sound/usb/card.c
parent978520b75f0a1ce82b17e1e8186417250de6d545 (diff)
ALSA: usb-audio: Use rwsem for disconnect protection
Replace mutex with rwsem for codec->shutdown protection so that concurrent accesses are allowed. Also add the protection to snd_usb_autosuspend() and snd_usb_autoresume(), too. Reported-by: Matthieu CASTET <matthieu.castet@parrot.com> Cc: <stable@vger.kernel.org> Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/usb/card.c')
-rw-r--r--sound/usb/card.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/sound/usb/card.c b/sound/usb/card.c
index 561bb74fd364..282f0fc9fed1 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -339,7 +339,7 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
339 } 339 }
340 340
341 mutex_init(&chip->mutex); 341 mutex_init(&chip->mutex);
342 mutex_init(&chip->shutdown_mutex); 342 init_rwsem(&chip->shutdown_rwsem);
343 chip->index = idx; 343 chip->index = idx;
344 chip->dev = dev; 344 chip->dev = dev;
345 chip->card = card; 345 chip->card = card;
@@ -560,7 +560,7 @@ static void snd_usb_audio_disconnect(struct usb_device *dev,
560 560
561 card = chip->card; 561 card = chip->card;
562 mutex_lock(&register_mutex); 562 mutex_lock(&register_mutex);
563 mutex_lock(&chip->shutdown_mutex); 563 down_write(&chip->shutdown_rwsem);
564 chip->shutdown = 1; 564 chip->shutdown = 1;
565 chip->num_interfaces--; 565 chip->num_interfaces--;
566 if (chip->num_interfaces <= 0) { 566 if (chip->num_interfaces <= 0) {
@@ -582,11 +582,11 @@ static void snd_usb_audio_disconnect(struct usb_device *dev,
582 snd_usb_mixer_disconnect(p); 582 snd_usb_mixer_disconnect(p);
583 } 583 }
584 usb_chip[chip->index] = NULL; 584 usb_chip[chip->index] = NULL;
585 mutex_unlock(&chip->shutdown_mutex); 585 up_write(&chip->shutdown_rwsem);
586 mutex_unlock(&register_mutex); 586 mutex_unlock(&register_mutex);
587 snd_card_free_when_closed(card); 587 snd_card_free_when_closed(card);
588 } else { 588 } else {
589 mutex_unlock(&chip->shutdown_mutex); 589 up_write(&chip->shutdown_rwsem);
590 mutex_unlock(&register_mutex); 590 mutex_unlock(&register_mutex);
591 } 591 }
592} 592}
@@ -618,16 +618,20 @@ int snd_usb_autoresume(struct snd_usb_audio *chip)
618{ 618{
619 int err = -ENODEV; 619 int err = -ENODEV;
620 620
621 down_read(&chip->shutdown_rwsem);
621 if (!chip->shutdown && !chip->probing) 622 if (!chip->shutdown && !chip->probing)
622 err = usb_autopm_get_interface(chip->pm_intf); 623 err = usb_autopm_get_interface(chip->pm_intf);
624 up_read(&chip->shutdown_rwsem);
623 625
624 return err; 626 return err;
625} 627}
626 628
627void snd_usb_autosuspend(struct snd_usb_audio *chip) 629void snd_usb_autosuspend(struct snd_usb_audio *chip)
628{ 630{
631 down_read(&chip->shutdown_rwsem);
629 if (!chip->shutdown && !chip->probing) 632 if (!chip->shutdown && !chip->probing)
630 usb_autopm_put_interface(chip->pm_intf); 633 usb_autopm_put_interface(chip->pm_intf);
634 up_read(&chip->shutdown_rwsem);
631} 635}
632 636
633static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message) 637static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message)