ALSA: hda - Fix hang caused by race during suspend.
authorDylan Reid <dgreid@chromium.org>
Fri, 28 Sep 2012 22:57:01 +0000 (15:57 -0700)
committerTakashi Iwai <tiwai@suse.de>
Sat, 6 Oct 2012 14:49:30 +0000 (16:49 +0200)
commitd17344b3547669f5b6ee4fda993d03737a141bd6
tree2f73c0f42b3b8489d6771f070ec9c801b6e2cc5e
parent395d9dd5dd13c6aa3c8c61a31126af98cd1e747d
ALSA: hda - Fix hang caused by race during suspend.

There was a race condition when the system suspends while hda_power_work
is running in the work queue.  If system suspend (snd_hda_suspend)
happens after the work queue releases power_lock but before it calls
hda_call_codec_suspend,  codec_suspend runs with power_on=0, causing the
codec to power up for register reads, and hanging when it calls
cancel_delayed_work_sync from the running work queue.

The call chain from the work queue will look like this:
hda_power_work <<- power_on = 1, unlock, then power_on cleard by suspend
  hda_call_codec_suspend
    hda_set_power_state
      snd_hda_codec_read
        codec_exec_verb
          snd_hda_power_up
    snd_hda_power_save
      __snd_hda_power_up
        cancel_delayed_work_sync <<-- cancelling executing wq

Fix this by waiting for the work queue to finish before starting suspend
if suspend is not happening on the work queue.

Signed-off-by: Dylan Reid <dgreid@chromium.org>
Cc: <stable@vger.kernel.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/hda/hda_codec.c