1
0
Fork 0
alistair23-linux/sound
Takashi Iwai 862b2509d1 ALSA: usb-audio: Fix inconsistent card PM state after resume
When a USB-audio interface gets runtime-suspended via auto-pm feature,
the driver suspends all functionality and increment
chip->num_suspended_intf.  Later on, when the system gets suspended to
S3, the driver increments chip->num_suspended_intf again, skips the
device changes, and sets the card power state to
SNDRV_CTL_POWER_D3hot.  In return, when the system gets resumed from
S3, the resume callback decrements chip->num_suspended_intf.  Since
this refcount is still not zero (it's been runtime-suspended), the
whole resume is skipped.  But there is a small pitfall here.

The problem is that the driver doesn't restore the card power state
after this resume call, leaving it as SNDRV_CTL_POWER_D3hot.  So,
even after the system resume finishes, the card instance still appears
as if it were system-suspended, and this confuses many ioctl accesses
that are blocked unexpectedly.

In details, we have two issues behind the scene: one is that the card
power state is changed only when the refcount becomes zero, and
another is that the prior auto-suspend check is kept in a boolean
flag.  Although the latter problem is almost negligible since the
auto-pm feature is imposed only on the primary interface, but this can
be a potential problem on the devices with multiple interfaces.

This patch addresses those issues by the following:

- Replace chip->autosuspended boolean flag with chip->system_suspend
  counter

- At the first system-suspend, chip->num_suspended_intf is recorded to
  chip->system_suspend

- At system-resume, the card power state is restored when the
  chip->num_suspended_intf refcount reaches to chip->system_suspend,
  i.e. the state returns to the auto-suspended

Also, the patch fixes yet another hidden problem by the code
refactoring along with the fixes above: namely, when some resume
procedure failed, the driver left chip->num_suspended_intf that was
already decreased, and it might lead to the refcount unbalance.
In the new code, the refcount decrement is done after the whole resume
procedure, and the problem is avoided as well.

Fixes: 0662292aec ("ALSA: usb-audio: Handle normal and auto-suspend equally")
Reported-and-tested-by: Macpaul Lin <macpaul.lin@mediatek.com>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20200603153709.6293-1-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2020-06-04 16:24:34 +02:00
..
ac97 ALSA: ac97: Constify snd_ac97_bus_ops definitions 2020-01-03 09:24:11 +01:00
aoa ALSA: aoa: More constifications 2020-01-05 16:14:27 +01:00
arm ASoC: arm: use asoc_rtd_to_cpu() / asoc_rtd_to_codec() macro for DAI pointer 2020-03-27 14:44:56 +00:00
atmel ALSA: atmel: Constify snd_ac97_bus_ops definitions 2020-01-03 09:24:12 +01:00
core Merge branch 'for-linus' into for-next 2020-05-28 10:08:50 +02:00
drivers ALSA: portman2x4: Use bitwise instead of arithmetic operator for flags 2020-05-07 09:07:15 +02:00
firewire Merge branch 'for-linus' into for-next 2020-05-28 10:08:50 +02:00
hda ASoC: Updates for v5.8 2020-06-01 20:26:07 +02:00
i2c ALSA: i2c: Constify snd_kcontrol_new items 2020-01-03 09:24:24 +01:00
isa ALSA: es1688: Add the missed snd_card_free() 2020-06-03 11:40:55 +02:00
mips ALSA: sgio2audio: Remove usage of dropped hw_params/hw_free functions 2020-03-06 12:06:41 +01:00
oss .gitignore: add SPDX License Identifier 2020-03-25 11:50:48 +01:00
parisc sound updates for 5.6-rc1 2020-01-28 16:26:57 -08:00
pci ALSA: hda: add sienna_cichlid audio asic id for sienna_cichlid up 2020-06-03 11:39:36 +02:00
pcmcia ALSA: pdaudiocf: More constification 2020-01-05 16:15:13 +01:00
ppc ALSA: sound/ppc: Use bitwise instead of arithmetic operator for flags 2020-05-07 09:06:11 +02:00
sh ALSA: sh: Fix compile warning wrt const 2020-01-05 16:15:14 +01:00
soc ASoC: Updates for v5.8 2020-06-01 20:26:07 +02:00
sparc ALSA: sparc: More constifications 2020-01-05 16:14:56 +01:00
spi ALSA: spi: More constification 2020-01-05 16:15:13 +01:00
synth ALSA: emux: More constifications 2020-01-05 16:14:46 +01:00
usb ALSA: usb-audio: Fix inconsistent card PM state after resume 2020-06-04 16:24:34 +02:00
x86 sound updates for 5.6-rc1 2020-01-28 16:26:57 -08:00
xen ALSA: xen: Drop superfluous ioctl PCM ops 2019-12-11 07:25:35 +01:00
Kconfig treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
Makefile
ac97_bus.c ALSA: ac97: Treat snd_ac97_bus_ops as const 2020-01-03 09:24:08 +01:00
last.c treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156 2019-05-30 11:26:35 -07:00
sound_core.c sound: fix a memory leak bug 2019-08-08 08:18:32 +02:00