linux-stable/sound
Takashi Iwai 47ab154593 ALSA: usb-audio: Avoid nested autoresume calls
After the recent fix of runtime PM for USB-audio driver, we got a
lockdep warning like:

  =============================================
  [ INFO: possible recursive locking detected ]
  4.2.0-rc8+ #61 Not tainted
  ---------------------------------------------
  pulseaudio/980 is trying to acquire lock:
   (&chip->shutdown_rwsem){.+.+.+}, at: [<ffffffffa0355dac>] snd_usb_autoresume+0x1d/0x52 [snd_usb_audio]
  but task is already holding lock:
   (&chip->shutdown_rwsem){.+.+.+}, at: [<ffffffffa0355dac>] snd_usb_autoresume+0x1d/0x52 [snd_usb_audio]

This comes from snd_usb_autoresume() invoking down_read() and it's
used in a nested way.  Although it's basically safe, per se (as these
are read locks), it's better to reduce such spurious warnings.

The read lock is needed to guarantee the execution of "shutdown"
(cleanup at disconnection) task after all concurrent tasks are
finished.  This can be implemented in another better way.

Also, the current check of chip->in_pm isn't good enough for
protecting the racy execution of multiple auto-resumes.

This patch rewrites the logic of snd_usb_autoresume() & co; namely,
- The recursive call of autopm is avoided by the new refcount,
  chip->active.  The chip->in_pm flag is removed accordingly.
- Instead of rwsem, another refcount, chip->usage_count, is introduced
  for tracking the period to delay the shutdown procedure.  At
  the last clear of this refcount, wake_up() to the shutdown waiter is
  called.
- The shutdown flag is replaced with shutdown atomic count; this is
  for reducing the lock.
- Two new helpers are introduced to simplify the management of these
  refcounts; snd_usb_lock_shutdown() increases the usage_count, checks
  the shutdown state, and does autoresume.  snd_usb_unlock_shutdown()
  does the opposite.  Most of mixer and other codes just need this,
  and simply returns an error if it receives an error from lock.

Fixes: 9003ebb13f ('ALSA: usb-audio: Fix runtime PM unbalance')
Reported-and-tested-by: Alexnader Kuleshov <kuleshovmail@gmail.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2015-08-26 15:38:25 +02:00
..
aoa ALSA: aoa-soundbus: Switch to dev_pm_ops 2015-08-05 16:47:47 +02:00
arm ALSA: Deletion of checks before the function call "iounmap" 2015-01-04 15:13:45 +01:00
atmel ALSA: sound/atmel/ac97c.c: remove unused variable 2015-05-20 06:18:25 +02:00
core ASoC: Fixes for v4.2 2015-07-24 20:08:13 +02:00
drivers sound updates for 4.2-rc1 2015-06-25 17:15:18 -07:00
firewire Merge branch 'for-linus' into for-next 2015-08-11 09:40:16 +02:00
hda ALSA: hda - Fix widget sysfs tree corruption after refresh 2015-08-26 07:43:47 +02:00
i2c ALSA: ak4xxx-adda: Drop unnecessary ifdef CONFIG_PROC_FS 2015-05-29 07:51:23 +02:00
isa ALSA: gus: use swap() in snd_ics_put_double() 2015-06-12 20:46:29 +02:00
mips ALSA: mips: let SND_SGI_O2 select SND_PCM 2015-06-15 13:21:58 +02:00
oss sound: oss/sb_audio: use swap() in sb_audio_close() 2015-06-12 20:46:29 +02:00
parisc ALSA: Include linux/io.h instead of asm/io.h 2015-01-28 16:49:33 +01:00
pci ALSA: hda - Remove superfluous pcm NULL check 2015-08-26 14:21:14 +02:00
pcmcia
ppc ALSA: ppc: Add missing inclusion of linux/module.h 2015-08-25 14:13:36 +02:00
sh ALSA: Include linux/io.h instead of asm/io.h 2015-01-28 16:49:33 +01:00
soc ASoC: Disable topology support for v4.2 2015-08-19 18:31:54 +02:00
sparc ALSA: sparc: Add missing kfree in error path 2015-07-17 22:29:43 +02:00
spi
synth ALSA: emux: Fix/cleanup old ifdef CONFIG_PROC_FS 2015-05-29 07:58:11 +02:00
usb ALSA: usb-audio: Avoid nested autoresume calls 2015-08-26 15:38:25 +02:00
ac97_bus.c ALSA: ac97: Switch to dev_pm_ops 2015-08-21 19:27:23 +02:00
Kconfig ALSA: hda - Make snd_hda_bus_type public 2015-03-23 13:15:51 +01:00
last.c
Makefile ALSA: hda - Make snd_hda_bus_type public 2015-03-23 13:15:51 +01:00
sound_core.c
sound_firmware.c sound: sound_firmware: Fix invalid use of vfs_read() 2015-05-26 13:48:58 +02:00