Skip to content

Commit d17344b

Browse files
dgreidtiwai
authored andcommitted
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>
1 parent 395d9dd commit d17344b

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
@@ -3612,15 +3612,17 @@ static inline void hda_exec_init_verbs(struct hda_codec *codec) {}
36123612
* call suspend and power-down; used both from PM and power-save
36133613
* this function returns the power state in the end
36143614
*/
3615-
static unsigned int hda_call_codec_suspend(struct hda_codec *codec)
3615+
static unsigned int hda_call_codec_suspend(struct hda_codec *codec, bool in_wq)
36163616
{
36173617
unsigned int state;
36183618

36193619
if (codec->patch_ops.suspend)
36203620
codec->patch_ops.suspend(codec);
36213621
hda_cleanup_all_streams(codec);
36223622
state = hda_set_power_state(codec, AC_PWRST_D3);
3623-
cancel_delayed_work(&codec->power_work);
3623+
/* Cancel delayed work if we aren't currently running from it. */
3624+
if (!in_wq)
3625+
cancel_delayed_work_sync(&codec->power_work);
36243626
spin_lock(&codec->power_lock);
36253627
snd_hda_update_power_acct(codec);
36263628
trace_hda_power_down(codec);
@@ -4478,7 +4480,7 @@ static void hda_power_work(struct work_struct *work)
44784480
}
44794481
spin_unlock(&codec->power_lock);
44804482

4481-
state = hda_call_codec_suspend(codec);
4483+
state = hda_call_codec_suspend(codec, true);
44824484
codec->pm_down_notified = 0;
44834485
if (!bus->power_keep_link_on && (state & AC_PWRST_CLK_STOP_OK)) {
44844486
codec->pm_down_notified = 1;
@@ -5127,7 +5129,7 @@ int snd_hda_suspend(struct hda_bus *bus)
51275129

51285130
list_for_each_entry(codec, &bus->codec_list, list) {
51295131
if (hda_codec_is_power_on(codec))
5130-
hda_call_codec_suspend(codec);
5132+
hda_call_codec_suspend(codec, false);
51315133
}
51325134
return 0;
51335135
}

0 commit comments

Comments
 (0)