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

From: Jaroslav Kysela

Date: Wed Jun 17 2026 - 04:45:10 EST


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.

Obtaining the device state through procfs is really a bad habit.

Jaroslav

--
Jaroslav Kysela <perex@xxxxxxxx>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.