Skip to contentSkip to conversation

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

PATCH New Takashi Iwai 1 participant 1 message Jun 19 Sound

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 sound/core/pcm_native.c | 2 ++
 1 file changed, 2 insertions(+)
sound/core/pcm_native.c +2 -0
index 7dc0060617f1..d4e04b5088c5 100644
@@ -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)
Signature · 1 line
2.54.0