ALSA: hda - Fix another race in runtime PM refcounting
authorTakashi Iwai <tiwai@suse.de>
Mon, 13 Apr 2015 09:01:14 +0000 (11:01 +0200)
committerTakashi Iwai <tiwai@suse.de>
Mon, 13 Apr 2015 09:07:20 +0000 (11:07 +0200)
commitc3aeda62878f09da91329693a60a1f08ec97e0b8
tree5b07fb0e0aeddc6cfb5b4b0b5f0151a679e62c4d
parenteacf6e0a238923dfce0626450adcb6d486072f28
ALSA: hda - Fix another race in runtime PM refcounting

Although some races in runtime PM refcount was fixed by the commit
[664c715573c2: ALSA: hda - Work around races of power up/down with
runtime PM], there is still a race in the following case:

CPU0:                   CPU1 :
runtime suspend:
  codec->in_pm = 1
                        snd_hdac_power_up_pm():
                          pm_runtime_get_sync() skipped
suspend finished:
  codec->in_pm = 0
                        snd_hdac_power_down_pm():
                          pm_runtime_put_*() is called!

For avoiding this situation, increment in_pm flag atomically when it's
non-zero, and decrement accordingly, to ensure that in_pm is set
consistently for the whole concurrent operations.

Also, since atomic_inc_not_zero() and atomic_dec_if_positive() are
lengthy inline functions, move snd_hdac_power_up_pm() and _down_pm()
to sound/hda/hdac_device.c as no inline functions.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/sound/hdaudio.h
sound/hda/hdac_device.c