mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] ALSA: hda: Check snd_hda_power_pm construct error before executing verb
@ 2026-07-13  2:04 songxiebing
  2026-07-13 10:13 ` Takashi Iwai
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: songxiebing @ 2026-07-13  2:04 UTC (permalink / raw)
  To: tiwai, perex; +Cc: linux-sound, linux-kernel, songxiebing

From: Bob Song <songxiebing@kylinos.cn>

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@kylinos.cn>
---
 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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-07-22 11:26 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-13  2:04 [PATCH] ALSA: hda: Check snd_hda_power_pm construct error before executing verb songxiebing
2026-07-13 10:13 ` Takashi Iwai
2026-07-14  2:13 ` songxiebing
2026-07-14  5:26   ` Takashi Iwai
2026-07-17  2:49 ` [PATCH v2] " songxiebing
2026-07-22 11:26   ` Takashi Iwai
2026-07-17  5:33 ` [PATCH v3] " songxiebing

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®