CHROMIUM: ALSA: hda - Cancel power work before suspending.
authorDylan Reid <dgreid@chromium.org>
Thu, 23 Aug 2012 21:25:04 +0000 (14:25 -0700)
committerGerrit <chrome-bot@google.com>
Mon, 27 Aug 2012 17:37:26 +0000 (10:37 -0700)
If snd_hda_call_codec_suspend is called from the system suspend path
wait for powersave work to finish.  Without the call to _sync, the
power_work function can hang the workqueue if it has progressed past the
check of the power_on variable before this function sets it to 0.  In
that case the power_work function will call snd_hda_power_up (via it's
own call of hda_call_codec_suspend).  snd_hda_power_up will then call
cancel_delayed_work_sync for the work it is currently executing on.

BUG=chrome-os-partner:13008
TEST=suspend_test.sh from bug.

Change-Id: Ic127eeecdfb8995be5e2c630028f4e3cf5477a2e
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/31285
Reviewed-by: Sonny Rao <sonnyrao@chromium.org>
Commit-Ready: Sonny Rao <sonnyrao@chromium.org>
Tested-by: Sonny Rao <sonnyrao@chromium.org>
sound/pci/hda/hda_codec.c

index 511beaa..5badd36 100644 (file)
@@ -3482,7 +3482,7 @@ static inline void hda_exec_init_verbs(struct hda_codec *codec) {}
 /*
  * call suspend and power-down; used both from PM and power-save
  */
-static void hda_call_codec_suspend(struct hda_codec *codec)
+static void hda_call_codec_suspend(struct hda_codec *codec, bool in_wq)
 {
        if (codec->patch_ops.suspend)
                codec->patch_ops.suspend(codec, PMSG_SUSPEND);
@@ -3491,7 +3491,9 @@ static void hda_call_codec_suspend(struct hda_codec *codec)
                            codec->afg ? codec->afg : codec->mfg,
                            AC_PWRST_D3);
 #ifdef CONFIG_SND_HDA_POWER_SAVE
-       cancel_delayed_work(&codec->power_work);
+       /* Cancel delayed work if we aren't currently running it. */
+       if (!in_wq)
+               cancel_delayed_work_sync(&codec->power_work);
        spin_lock(&codec->power_lock);
        snd_hda_update_power_acct(codec);
        trace_hda_power_down(codec);
@@ -4308,7 +4310,7 @@ static void hda_power_work(struct work_struct *work)
        }
        spin_unlock(&codec->power_lock);
 
-       hda_call_codec_suspend(codec);
+       hda_call_codec_suspend(codec, true);
        if (bus->ops.pm_notify)
                bus->ops.pm_notify(bus);
 }
@@ -5515,7 +5517,7 @@ int snd_hda_suspend(struct hda_bus *bus)
 
        list_for_each_entry(codec, &bus->codec_list, list) {
                if (hda_codec_is_power_on(codec))
-                       hda_call_codec_suspend(codec);
+                       hda_call_codec_suspend(codec, false);
                if (codec->patch_ops.post_suspend)
                        codec->patch_ops.post_suspend(codec);
        }