[PATCH] ALSA: pcm: Notify disconnected state at mmap data fault, too

From: Takashi Iwai

Date: Fri Jun 19 2026 - 11:02:39 EST


When a device gets disconnected, the driver waits until the all opened
file descriptors are closed before releasing the device. Although PCM
core emits an error to any further syscalls (except for close), some
applications don't notice the disconnected state because they mainly
access only via mmap, and it may block the device release
unnecessarily too long.

This patch is an attempt to improve the behavior by adding the
notification of the PCM disconnected state at mmap data faulting.
When the device is disconnected, it now returns VM_FAULT_SIGBUS, so
that the application can notice the invalid PCM state.

Reported-and-tested-by: Ai Chao <aichao@xxxxxxxxxx>
Link: https://lore.kernel.org/20260615132657.2097213-1-aichao@xxxxxxxxxx>
Signed-off-by: Takashi Iwai <tiwai@xxxxxxx>
---
sound/core/pcm_native.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 7dc0060617f1..d4e04b5088c5 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -3907,6 +3907,8 @@ static vm_fault_t snd_pcm_mmap_data_fault(struct vm_fault *vmf)
if (substream == NULL)
return VM_FAULT_SIGBUS;
runtime = substream->runtime;
+ if (runtime->state == SNDRV_PCM_STATE_DISCONNECTED)
+ return VM_FAULT_SIGBUS;
offset = vmf->pgoff << PAGE_SHIFT;
dma_bytes = PAGE_ALIGN(runtime->dma_bytes);
if (offset > dma_bytes - PAGE_SIZE)
--
2.54.0