ALSA: hda: Handle the jack polling always via a work
authorTakashi Iwai <tiwai@suse.de>
Mon, 23 Jun 2025 13:14:32 +0000 (15:14 +0200)
committerTakashi Iwai <tiwai@suse.de>
Mon, 23 Jun 2025 15:21:16 +0000 (17:21 +0200)
commit5f7e54b23e4d253eff3b10b12d6fa92d28d7dddc
treef9620e5fb7b2430ac620e568f3d389c6158311a4
parent507cd1216a6d70da6b230c806862c065632c713f
ALSA: hda: Handle the jack polling always via a work

We used to call directly hda_jackpoll_work() from a couple of places
for updating the jack and notify to user-space, but this makes rather
the code flow fragile.  Namely, because of those direct calls,
hda_jackpoll_work() uses snd_hda_power_up_pm() and *_down_pm() calls
instead of the standard snd_hda_power_up() and *_down() calls.  The
latter pair assures the runtime PM resume sync, so it can avoid the
race against the PM callbacks gracefully, while the former pair may
continue if called concurrently, hence it may race (by design).

In this patch, we change the call pattern of hda_jackpoll_work(); now
all callers are replaced with the standard snd_hda_jack_report_sync()
and the additional schedule_delayed_work().

Since hda_jackpoll_work() is called only from the associated work,
it's always outside the PM code path, and we can safely use
snd_hda_power_up() and *_down() there instead.  This allows us to
remove the racy check of power-state in hda_jackpoll_work(), as well
as the tricky cancel_delayed_work() and rescheduling at
hda_codec_runtime_suspend().

Reported-by: Joakim Zhang <joakim.zhang@cixtech.com>
Closes: https://lore.kernel.org/20250619020844.2974160-1-joakim.zhang@cixtech.com
Tested-by: Joakim Zhang <joakim.zhang@cixtech.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20250623131437.10670-4-tiwai@suse.de
sound/pci/hda/hda_codec.c