[PATCH] ALSA: hda: Check snd_hda_power_pm construct error before executing verb
From: songxiebing
Date: Sun Jul 12 2026 - 22:04:46 EST
From: Bob Song <songxiebing@xxxxxxxxxx>
When userspace writes 1 to /sys/bus/pci/devices/XX/remove to remove HDA PCI device,
the codec device enters runtime suspended state early. The snd_hda_power_pm RAII
constructor fails to wake up codec, but the original code ignores pm.err and continues
to execute hda verb commands. After pci driver remove callback completes, devres
automatically iounmap the BAR virtual address bus->remap_addr, resulting in access
to invalid unmapped MMIO address and triggering page fault BUG.
Add error check for snd_hda_power_pm constructor result:
1. Detect pm construction failure when HDA core device is suspended;
2. Print warning log with command and error code for debug;
3. Return early to skip subsequent hardware register access, avoid page fault crash.
Signed-off-by: Bob Song <songxiebing@xxxxxxxxxx>
---
sound/hda/common/codec.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/sound/hda/common/codec.c b/sound/hda/common/codec.c
index ef533770179b..69ddd153509c 100644
--- a/sound/hda/common/codec.c
+++ b/sound/hda/common/codec.c
@@ -39,6 +39,12 @@ static int call_exec_verb(struct hda_bus *bus, struct hda_codec *codec,
int err;
CLASS(snd_hda_power_pm, pm)(codec);
+ if (pm.err < 0 && pm_runtime_status_suspended(bus->core.dev)) {
+ codec_warn(codec,
+ "Failed to send cmd 0x%x ret=[%d], hda control device is suspended\n",
+ cmd, pm.err);
+ return pm.err;
+ }
guard(mutex)(&bus->core.cmd_mutex);
if (flags & HDA_RW_NO_RESPONSE_FALLBACK)
bus->no_response_fallback = 1;
--
2.25.1