mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ben Hutchings <ben@decadent.org.uk>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: akpm@linux-foundation.org, alan@lxorguk.ukuu.org.uk,
	Takashi Iwai <tiwai@suse.de>,
	Matthieu CASTET <matthieu.castet@parrot.com>
Subject: [ 09/82] ALSA: usb-audio: Use rwsem for disconnect protection
Date: Wed, 14 Nov 2012 05:39:42 +0000	[thread overview]
Message-ID: <20121114053935.090465011@decadent.org.uk> (raw)
In-Reply-To: <20121114053933.726869752@decadent.org.uk>

3.2-stable review patch.  If anyone has any objections, please let me know.

------------------

From: Takashi Iwai <tiwai@suse.de>

commit 34f3c89fda4fba9fe689db22253ca8db2f5e6386 upstream.

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>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Ben Hutchings <ben@decadent.org.uk>
---
 sound/usb/card.c     | 12 ++++++++----
 sound/usb/mixer.c    | 12 ++++++------
 sound/usb/pcm.c      | 12 ++++++------
 sound/usb/usbaudio.h |  2 +-
 4 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/sound/usb/card.c b/sound/usb/card.c
index 0f6dc0d..7003c13 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -336,7 +336,7 @@ static int snd_usb_audio_create(struct usb_device *dev, int idx,
 		return -ENOMEM;
 	}
 
-	mutex_init(&chip->shutdown_mutex);
+	init_rwsem(&chip->shutdown_rwsem);
 	chip->index = idx;
 	chip->dev = dev;
 	chip->card = card;
@@ -556,7 +556,7 @@ static void snd_usb_audio_disconnect(struct usb_device *dev,
 
 	card = chip->card;
 	mutex_lock(&register_mutex);
-	mutex_lock(&chip->shutdown_mutex);
+	down_write(&chip->shutdown_rwsem);
 	chip->shutdown = 1;
 	chip->num_interfaces--;
 	if (chip->num_interfaces <= 0) {
@@ -574,11 +574,11 @@ static void snd_usb_audio_disconnect(struct usb_device *dev,
 			snd_usb_mixer_disconnect(p);
 		}
 		usb_chip[chip->index] = NULL;
-		mutex_unlock(&chip->shutdown_mutex);
+		up_write(&chip->shutdown_rwsem);
 		mutex_unlock(&register_mutex);
 		snd_card_free_when_closed(card);
 	} else {
-		mutex_unlock(&chip->shutdown_mutex);
+		up_write(&chip->shutdown_rwsem);
 		mutex_unlock(&register_mutex);
 	}
 }
@@ -610,16 +610,20 @@ int snd_usb_autoresume(struct snd_usb_audio *chip)
 {
 	int err = -ENODEV;
 
+	down_read(&chip->shutdown_rwsem);
 	if (!chip->shutdown && !chip->probing)
 		err = usb_autopm_get_interface(chip->pm_intf);
+	up_read(&chip->shutdown_rwsem);
 
 	return err;
 }
 
 void snd_usb_autosuspend(struct snd_usb_audio *chip)
 {
+	down_read(&chip->shutdown_rwsem);
 	if (!chip->shutdown && !chip->probing)
 		usb_autopm_put_interface(chip->pm_intf);
+	up_read(&chip->shutdown_rwsem);
 }
 
 static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message)
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index 51a81ef..6730a33 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -292,7 +292,7 @@ static int get_ctl_value_v1(struct usb_mixer_elem_info *cval, int request, int v
 	err = snd_usb_autoresume(cval->mixer->chip);
 	if (err < 0)
 		return -EIO;
-	mutex_lock(&chip->shutdown_mutex);
+	down_read(&chip->shutdown_rwsem);
 	while (timeout-- > 0) {
 		if (chip->shutdown)
 			break;
@@ -310,7 +310,7 @@ static int get_ctl_value_v1(struct usb_mixer_elem_info *cval, int request, int v
 	err = -EINVAL;
 
  out:
-	mutex_unlock(&chip->shutdown_mutex);
+	up_read(&chip->shutdown_rwsem);
 	snd_usb_autosuspend(cval->mixer->chip);
 	return err;
 }
@@ -337,7 +337,7 @@ static int get_ctl_value_v2(struct usb_mixer_elem_info *cval, int request, int v
 	if (ret)
 		goto error;
 
-	mutex_lock(&chip->shutdown_mutex);
+	down_read(&chip->shutdown_rwsem);
 	if (chip->shutdown)
 		ret = -ENODEV;
 	else {
@@ -346,7 +346,7 @@ static int get_ctl_value_v2(struct usb_mixer_elem_info *cval, int request, int v
 			      USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
 			      validx, idx, buf, size);
 	}
-	mutex_unlock(&chip->shutdown_mutex);
+	up_read(&chip->shutdown_rwsem);
 	snd_usb_autosuspend(chip);
 
 	if (ret < 0) {
@@ -453,7 +453,7 @@ int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval,
 	err = snd_usb_autoresume(chip);
 	if (err < 0)
 		return -EIO;
-	mutex_lock(&chip->shutdown_mutex);
+	down_read(&chip->shutdown_rwsem);
 	while (timeout-- > 0) {
 		if (chip->shutdown)
 			break;
@@ -471,7 +471,7 @@ int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval,
 	err = -EINVAL;
 
  out:
-	mutex_unlock(&chip->shutdown_mutex);
+	up_read(&chip->shutdown_rwsem);
 	snd_usb_autosuspend(chip);
 	return err;
 }
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index 9a11fae..983e071 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -376,7 +376,7 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
 		subs->period_bytes != params_period_bytes(hw_params) ||
 		subs->cur_rate != rate;
 
-	mutex_lock(&subs->stream->chip->shutdown_mutex);
+	down_read(&subs->stream->chip->shutdown_rwsem);
 	if (subs->stream->chip->shutdown) {
 		ret = -ENODEV;
 		goto unlock;
@@ -406,7 +406,7 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
 	}
 
 unlock:
-	mutex_unlock(&subs->stream->chip->shutdown_mutex);
+	up_read(&subs->stream->chip->shutdown_rwsem);
 	return ret;
 }
 
@@ -422,9 +422,9 @@ static int snd_usb_hw_free(struct snd_pcm_substream *substream)
 	subs->cur_audiofmt = NULL;
 	subs->cur_rate = 0;
 	subs->period_bytes = 0;
-	mutex_lock(&subs->stream->chip->shutdown_mutex);
+	down_read(&subs->stream->chip->shutdown_rwsem);
 	snd_usb_release_substream_urbs(subs, 0);
-	mutex_unlock(&subs->stream->chip->shutdown_mutex);
+	up_read(&subs->stream->chip->shutdown_rwsem);
 	return snd_pcm_lib_free_vmalloc_buffer(substream);
 }
 
@@ -444,7 +444,7 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream)
 		return -ENXIO;
 	}
 
-	mutex_lock(&subs->stream->chip->shutdown_mutex);
+	down_read(&subs->stream->chip->shutdown_rwsem);
 	if (subs->stream->chip->shutdown) {
 		ret = -ENODEV;
 		goto unlock;
@@ -463,7 +463,7 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream)
 
 	ret = snd_usb_substream_prepare(subs, runtime);
  unlock:
-	mutex_unlock(&subs->stream->chip->shutdown_mutex);
+	up_read(&subs->stream->chip->shutdown_rwsem);
 	return ret;
 }
 
diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h
index 3e2b035..6c805a5 100644
--- a/sound/usb/usbaudio.h
+++ b/sound/usb/usbaudio.h
@@ -36,7 +36,7 @@ struct snd_usb_audio {
 	struct snd_card *card;
 	struct usb_interface *pm_intf;
 	u32 usb_id;
-	struct mutex shutdown_mutex;
+	struct rw_semaphore shutdown_rwsem;
 	unsigned int shutdown:1;
 	unsigned int probing:1;
 	unsigned int autosuspended:1;	



  parent reply	other threads:[~2012-11-14  6:10 UTC|newest]

Thread overview: 96+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-14  5:39 [ 00/82] 3.2.34-stable review Ben Hutchings
2012-11-14  5:39 ` [ 01/82] Bluetooth: Always compile SCO and L2CAP in Bluetooth Core Ben Hutchings
2012-11-14 21:24   ` Gustavo Padovan
2012-11-14 21:30     ` David Miller
2012-11-14 21:38       ` Ben Hutchings
2012-11-15 20:04         ` Ben Hutchings
2012-11-15 20:13           ` David Miller
2012-11-15 21:04             ` Gustavo Padovan
2012-11-15 21:08               ` David Miller
2012-11-15 22:05               ` Joe Perches
2012-11-15 21:07           ` Gustavo Padovan
2012-11-16  2:08             ` Ben Hutchings
2012-11-14  5:39 ` [ 02/82] x86: Remove the ancient and deprecated disable_hlt() and enable_hlt() facility Ben Hutchings
2012-11-14  5:39 ` [ 03/82] drm/nouveau: silence modesetting spam on pre-gf8 chipsets Ben Hutchings
2012-11-14  5:39 ` [ 04/82] drm/nouveau: fix suspend/resume when in headless mode Ben Hutchings
2012-11-14  5:39 ` [ 05/82] drm/nouveau: headless mode by default if pci class != vga display Ben Hutchings
2012-11-14  5:39 ` [ 06/82] nfsd: add get_uint for u32s Ben Hutchings
2012-11-14  5:39 ` [ 07/82] ALSA: PCM: Fix some races at disconnection Ben Hutchings
2012-11-14  5:39 ` [ 08/82] ALSA: usb-audio: Fix " Ben Hutchings
2012-11-14  5:39 ` Ben Hutchings [this message]
2012-11-14  5:39 ` [ 10/82] ALSA: usb-audio: Fix races at disconnection in mixer_quirks.c Ben Hutchings
2012-11-14  5:39 ` [ 11/82] ALSA: Add a reference counter to card instance Ben Hutchings
2012-11-14  5:39 ` [ 12/82] ALSA: Avoid endless sleep after disconnect Ben Hutchings
2012-11-14  5:39 ` [ 13/82] drm/radeon: fix typo in evergreen_mc_resume() Ben Hutchings
2012-11-14  5:39 ` [ 14/82] USB: mos7840: remove unused variable Ben Hutchings
2012-11-14  5:39 ` [ 15/82] rtnetlink: Fix problem with buffer allocation Ben Hutchings
2012-11-14  5:39 ` [ 16/82] rtnetlink: fix rtnl_calcit() and rtnl_dump_ifinfo() Ben Hutchings
2012-11-14  5:39 ` [ 17/82] gpio-timberdale: fix a potential wrapping issue Ben Hutchings
2012-11-14  5:39 ` [ 18/82] cfg80211: fix antenna gain handling Ben Hutchings
2012-11-14  5:39 ` [ 19/82] drm/i915: fix overlay on i830M Ben Hutchings
2012-11-14  5:39 ` [ 20/82] drm/i915: fixup infoframe support for sdvo Ben Hutchings
2012-11-14  5:39 ` [ 21/82] drm/i915: clear the entire sdvo infoframe buffer Ben Hutchings
2012-11-14  5:39 ` [ 22/82] crypto: cryptd - disable softirqs in cryptd_queue_worker to prevent data corruption Ben Hutchings
2012-11-14  5:39 ` [ 23/82] ARM: at91: at91sam9g10: fix SOC type detection Ben Hutchings
2012-11-14  5:39 ` [ 24/82] ARM: at91/i2c: change id to let i2c-gpio work Ben Hutchings
2012-11-14  5:39 ` [ 25/82] mac80211: Only process mesh config header on frames that RA_MATCH Ben Hutchings
2012-11-14  5:39 ` [ 26/82] mac80211: dont inspect Sequence Control field on control frames Ben Hutchings
2012-11-14  5:40 ` [ 27/82] gpiolib: Dont return -EPROBE_DEFER to sysfs, or for invalid gpios Ben Hutchings
2012-11-15 17:52   ` Herton Ronaldo Krzesinski
2012-11-15 20:06     ` Ben Hutchings
2012-11-14  5:40 ` [ 28/82] mac80211: fix SSID copy on IBSS JOIN Ben Hutchings
2012-11-14  5:40 ` [ 29/82] wireless: drop invalid mesh address extension frames Ben Hutchings
2012-11-14  5:40 ` [ 30/82] mac80211: check management frame header length Ben Hutchings
2012-11-14  5:40 ` [ 31/82] mac80211: verify that skb data is present Ben Hutchings
2012-11-14  5:40 ` [ 32/82] mac80211: make sure data is accessible in EAPOL check Ben Hutchings
2012-11-14  5:40 ` [ 33/82] ath9k: fix stale pointers potentially causing access to freed skbs Ben Hutchings
2012-11-14  5:40 ` [ 34/82] floppy: do put_disk on current dr if blk_init_queue fails Ben Hutchings
2012-11-14  5:40 ` [ 35/82] floppy: properly handle failure on add_disk loop Ben Hutchings
2012-11-14  5:40 ` [ 36/82] xen/gntdev: dont leak memory from IOCTL_GNTDEV_MAP_GRANT_REF Ben Hutchings
2012-11-14  5:40 ` [ 37/82] rt2800: validate step value for temperature compensation Ben Hutchings
2012-11-14  5:40 ` [ 38/82] ath9k: Test for TID only in BlockAcks while checking tx status Ben Hutchings
2012-11-14  5:40 ` [ 39/82] module: fix out-by-one error in kallsyms Ben Hutchings
2012-11-14  5:40 ` [ 40/82] Input: tsc40 - remove wrong announcement of pressure support Ben Hutchings
2012-11-14  5:40 ` [ 41/82] HID: microsoft: fix invalid rdesc for 3k kbd Ben Hutchings
2012-11-14  5:40 ` [ 42/82] xen/mmu: Use Xen specific TLB flush instead of the generic one Ben Hutchings
2012-11-14  5:40 ` [ 43/82] NFS: Wait for session recovery to finish before returning Ben Hutchings
2012-11-14  5:40 ` [ 44/82] NFSv4.1: We must release the sequence id when we fail to get a session slot Ben Hutchings
2012-11-14  5:40 ` [ 45/82] NFSv4: nfs4_locku_done must release the sequence id Ben Hutchings
2012-11-14  5:40 ` [ 46/82] NFS: fix bug in legacy DNS resolver Ben Hutchings
2012-11-14  5:40 ` [ 47/82] nfsv3: Make v3 mounts fail with ETIMEDOUTs instead EIO on mountd timeouts Ben Hutchings
2012-11-14  5:40 ` [ 48/82] nfs: Show original device name verbatim in /proc/*/mount{s,info} Ben Hutchings
2012-11-14  5:40 ` [ 49/82] target: Dont return success from module_init() if setup fails Ben Hutchings
2012-11-14  5:40 ` [ 50/82] target: Avoid integer overflow in se_dev_align_max_sectors() Ben Hutchings
2012-11-14  5:40 ` [ 51/82] iscsi-target: Fix missed wakeup race in TX thread Ben Hutchings
2012-11-14  5:40 ` [ 52/82] DRM/Radeon: Fix Load Detection on legacy primary DAC Ben Hutchings
2012-11-14  5:40 ` [ 53/82] cifs: fix potential buffer overrun in cifs.idmap handling code Ben Hutchings
2012-11-14  5:40 ` [ 54/82] ALSA: hda: Cirrus: Fix coefficient index for beep configuration Ben Hutchings
2012-11-14  5:40 ` [ 55/82] ALSA: HDA: Fix digital microphone on CS420x Ben Hutchings
2012-11-14  5:40 ` [ 56/82] ALSA: hda - Force to reset IEC958 status bits for AD codecs Ben Hutchings
2012-11-14  5:40 ` [ 57/82] hwmon: (w83627ehf) Force initial bank selection Ben Hutchings
2012-11-14  5:40 ` [ 58/82] drm: restore open_count if drm_setup fails Ben Hutchings
2012-11-14  5:40 ` [ 59/82] ALSA: hda - Fix empty DAC filling in patch_via.c Ben Hutchings
2012-11-14  5:40 ` [ 60/82] ALSA: hda - Fix invalid connections in VT1802 codec Ben Hutchings
2012-11-14  5:40 ` [ 61/82] ALSA: hda - Add new codec ALC668 and ALC900 (default name ALC1150) Ben Hutchings
2012-11-14  5:40 ` [ 62/82] ALSA: Fix card refcount unbalance Ben Hutchings
2012-11-14  5:40 ` [ 63/82] xfs: fix reading of wrapped log data Ben Hutchings
2012-11-14  5:40 ` [ 64/82] fanotify: fix missing break Ben Hutchings
2012-11-14  5:40 ` [ 65/82] mm: bugfix: set current->reclaim_state to NULL while returning from kswapd() Ben Hutchings
2012-11-14  5:40 ` [ 66/82] drm/vmwgfx: Fix hibernation device reset Ben Hutchings
2012-11-14  5:40 ` [ 67/82] drm/vmwgfx: Fix a case where the code would BUG when trying to pin GMR memory Ben Hutchings
2012-11-14  5:40 ` [ 68/82] sctp: fix call to SCTP_CMD_PROCESS_SACK in sctp_cmd_interpreter() Ben Hutchings
2012-11-14  5:40 ` [ 69/82] netlink: use kfree_rcu() in netlink_release() Ben Hutchings
2012-11-14  5:40 ` [ 70/82] tcp: fix FIONREAD/SIOCINQ Ben Hutchings
2012-11-14  5:40 ` [ 71/82] ipv6: Set default hoplimit as zero Ben Hutchings
2012-11-14  5:40 ` [ 72/82] net: usb: Fix memory leak on Tx data path Ben Hutchings
2012-11-14  5:40 ` [ 73/82] net: fix divide by zero in tcp algorithm illinois Ben Hutchings
2012-11-14  5:40 ` [ 74/82] l2tp: fix oops in l2tp_eth_create() error path Ben Hutchings
2012-11-14  5:40 ` [ 75/82] af-packet: fix oops when socket is not present Ben Hutchings
2012-11-14  5:40 ` [ 76/82] ipv6: send unsolicited neighbour advertisements to all-nodes Ben Hutchings
2012-11-14  5:40 ` [ 77/82] eCryptfs: Copy up POSIX ACL and read-only flags from lower mount Ben Hutchings
2012-11-14  5:40 ` [ 78/82] eCryptfs: check for eCryptfs cipher support at mount Ben Hutchings
2012-11-14  5:40 ` [ 79/82] r8169: allow multicast packets on sub-8168f chipset Ben Hutchings
2012-11-14  5:40 ` [ 80/82] r8169: Fix WoL on RTL8168d/8111d Ben Hutchings
2012-11-14  5:40 ` [ 81/82] r8169: use unlimited DMA burst for TX Ben Hutchings
2012-11-14  5:40 ` [ 82/82] sky2: Fix for interrupt handler Ben Hutchings
2012-11-14  6:13 ` [ 00/82] 3.2.34-stable review Ben Hutchings

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20121114053935.090465011@decadent.org.uk \
    --to=ben@decadent.org.uk \
    --cc=akpm@linux-foundation.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matthieu.castet@parrot.com \
    --cc=stable@vger.kernel.org \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome