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 <aichao@kylinos.cn>
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 <tiwai@suse.de>
This commit is contained in:
Takashi Iwai 2026-06-19 17:00:34 +02:00
parent 3213bf9885
commit f199040982

View File

@ -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)