From f199040982eac619bf9b3231af284dbf2e74f179 Mon Sep 17 00:00:00 2001 From: Takashi Iwai Date: Fri, 19 Jun 2026 17:00:34 +0200 Subject: [PATCH] ALSA: pcm: Notify disconnected state at mmap data fault, too 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 Link: https://lore.kernel.org/20260615132657.2097213-1-aichao@kylinos.cn> Link: https://patch.msgid.link/20260619150035.1560937-1-tiwai@suse.de Signed-off-by: Takashi Iwai --- 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)