Skip to content

Commit 22e2287

Browse files
dgreidgregkh
authored andcommitted
ALSA: hda - Fix hang caused by race during suspend.
commit d17344b upstream. 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> Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 93bfa6e commit 22e2287

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

sound/pci/hda/hda_codec.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3580,7 +3580,7 @@ static inline void hda_exec_init_verbs(struct hda_codec *codec) {}
35803580
/*
35813581
* call suspend and power-down; used both from PM and power-save
35823582
*/
3583-
static void hda_call_codec_suspend(struct hda_codec *codec)
3583+
static void hda_call_codec_suspend(struct hda_codec *codec, bool in_wq)
35843584
{
35853585
if (codec->patch_ops.suspend)
35863586
codec->patch_ops.suspend(codec);
@@ -3589,7 +3589,9 @@ static void hda_call_codec_suspend(struct hda_codec *codec)
35893589
codec->afg ? codec->afg : codec->mfg,
35903590
AC_PWRST_D3);
35913591
#ifdef CONFIG_SND_HDA_POWER_SAVE
3592-
cancel_delayed_work(&codec->power_work);
3592+
/* Cancel delayed work if we aren't currently running from it. */
3593+
if (!in_wq)
3594+
cancel_delayed_work_sync(&codec->power_work);
35933595
spin_lock(&codec->power_lock);
35943596
snd_hda_update_power_acct(codec);
35953597
trace_hda_power_down(codec);
@@ -4410,7 +4412,7 @@ static void hda_power_work(struct work_struct *work)
44104412
}
44114413
spin_unlock(&codec->power_lock);
44124414

4413-
hda_call_codec_suspend(codec);
4415+
hda_call_codec_suspend(codec, true);
44144416
if (bus->ops.pm_notify)
44154417
bus->ops.pm_notify(bus);
44164418
}
@@ -5076,7 +5078,7 @@ int snd_hda_suspend(struct hda_bus *bus)
50765078

50775079
list_for_each_entry(codec, &bus->codec_list, list) {
50785080
if (hda_codec_is_power_on(codec))
5079-
hda_call_codec_suspend(codec);
5081+
hda_call_codec_suspend(codec, false);
50805082
}
50815083
return 0;
50825084
}

0 commit comments

Comments
 (0)