Re: [PATCH] ALSA: pcm: Show closed for DISCONNECTED state

From: Takashi Iwai

Date: Wed Jun 17 2026 - 04:54:55 EST


On Wed, 17 Jun 2026 10:36:44 +0200,
Jaroslav Kysela wrote:
>
> On 6/17/26 09:19, Ai Chao wrote:
> > Hello Takashi
> >
> >> Thanks, it's a bit clearer. But it still means that it's a cargo fix
> >> only for that specific application. The program should receive an
> >> error for any further syscalls, so that it can close gracefully by
> >> itself. Or it doesn't work as expected?
> >
> > The recording software monitors /proc/asound/card0/pcm0c/sub0/status.
> > When the USB device is suddenly disconnected, the recording software fails
> > to capture audio data from the sound card, with both the hardware pointer
> > and application pointer being 0. The software remains in a pending state,
> > continuously displaying "Generating recording file". If the status file shows
> > "closed" (DISCONNECTED), the audio service detects the status change, reinitializes
> > the device, starts processing the recording file, and either resumes recording or
> > notifies the user.
>
> The PCM API ioctls should return an error in this case (device
> disconnection). Does software communicate with the driver through
> ioctl ? It seems that only mmaped appl/hw pointers are used which is
> not enough to detect the disconnection.

Right, I suspect that it might be the case.
Does the change like below help (or worsen) anything?


Takashi

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