* [PATCH] ALSA: pcm: Show closed for DISCONNECTED state
@ 2026-06-15 13:26 Ai Chao
2026-06-15 13:51 ` Takashi Iwai
0 siblings, 1 reply; 7+ messages in thread
From: Ai Chao @ 2026-06-15 13:26 UTC (permalink / raw)
To: perex, tiwai, kees; +Cc: linux-sound, linux-kernel, Ai Chao
Show "closed" for DISCONNECTED state allow audio service
to detect USB reset/disconnect and reinitialize the device.
Signed-off-by: Ai Chao <aichao@kylinos.cn>
---
sound/core/pcm.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index bfedf571e021..6ce35492ea56 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -450,6 +450,14 @@ static void snd_pcm_substream_proc_status_read(struct snd_info_entry *entry,
snd_iprintf(buffer, "error %d\n", err);
return;
}
+ /*
+ * Show "closed" for DISCONNECTED state allow audio service
+ * to detect USB reset/disconnect and reinitialize the device.
+ */
+ if (status.state == SNDRV_PCM_STATE_DISCONNECTED) {
+ snd_iprintf(buffer, "closed\n");
+ return;
+ }
snd_iprintf(buffer, "state: %s\n", snd_pcm_state_name(status.state));
snd_iprintf(buffer, "owner_pid : %d\n", pid_vnr(substream->pid));
snd_iprintf(buffer, "trigger_time: %lld.%09lld\n",
--
2.25.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH] ALSA: pcm: Show closed for DISCONNECTED state
2026-06-15 13:26 Ai Chao
@ 2026-06-15 13:51 ` Takashi Iwai
0 siblings, 0 replies; 7+ messages in thread
From: Takashi Iwai @ 2026-06-15 13:51 UTC (permalink / raw)
To: Ai Chao; +Cc: perex, tiwai, kees, linux-sound, linux-kernel
On Mon, 15 Jun 2026 15:26:57 +0200,
Ai Chao wrote:
>
> Show "closed" for DISCONNECTED state allow audio service
> to detect USB reset/disconnect and reinitialize the device.
Hmm, why it must be that? The state is shown as "DISCONNECTED".
IOW, does this matter for which application and how do we have to
imitate as if the file got closed?
thanks,
Takashi
>
> Signed-off-by: Ai Chao <aichao@kylinos.cn>
> ---
> sound/core/pcm.c | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/sound/core/pcm.c b/sound/core/pcm.c
> index bfedf571e021..6ce35492ea56 100644
> --- a/sound/core/pcm.c
> +++ b/sound/core/pcm.c
> @@ -450,6 +450,14 @@ static void snd_pcm_substream_proc_status_read(struct snd_info_entry *entry,
> snd_iprintf(buffer, "error %d\n", err);
> return;
> }
> + /*
> + * Show "closed" for DISCONNECTED state allow audio service
> + * to detect USB reset/disconnect and reinitialize the device.
> + */
> + if (status.state == SNDRV_PCM_STATE_DISCONNECTED) {
> + snd_iprintf(buffer, "closed\n");
> + return;
> + }
> snd_iprintf(buffer, "state: %s\n", snd_pcm_state_name(status.state));
> snd_iprintf(buffer, "owner_pid : %d\n", pid_vnr(substream->pid));
> snd_iprintf(buffer, "trigger_time: %lld.%09lld\n",
> --
> 2.25.1
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ALSA: pcm: Show closed for DISCONNECTED state
2026-06-16 2:06 Ai Chao
@ 2026-06-16 7:24 ` Takashi Iwai
0 siblings, 0 replies; 7+ messages in thread
From: Takashi Iwai @ 2026-06-16 7:24 UTC (permalink / raw)
To: Ai Chao; +Cc: perex, tiwai, kees, linux-sound, linux-kernel
On Tue, 16 Jun 2026 04:06:01 +0200,
Ai Chao wrote:
>
> Hello Takashi
>
> >Hmm, why it must be that? The state is shown as "DISCONNECTED".
> >
> >IOW, does this matter for which application and how do we have to
> >imitate as if the file got closed?
>
> Test Environment: Dual-boot Linux and Android system.
>
> Issue: When a recording app is opened in Linux, the system is switched to Android,
> and then switched back to Linux, the recording app fails to save the recording
> and keeps prompting "generating recording file".
>
> Note: The USB hub resets during the system switching process.
>
> Root Cause Analysis (from App Engineer): The recording app relies on the driver to
> report the IN_CLOSE_WRITE event. Upon receiving this, the audio service
> checks /proc/asound/card0/pcm0*/sub0/status. If the value is not "close", it assumes
> the sound card is occupied and skips loading; if the value is "close", it considers
> the sound card available and loads it normally.
> syslog:
> [ 1140.495952] retire_capture_urb: 17 callbacks suppressed
> [ 1140.583090] usb 1-2.4.2: USB disconnect, device number 53
> [ 1140.583965] usb 1-2.4.2: cannot submit urb (err = -19)
> [ 1140.588816] usb 1-2.4.2: cannot submit urb 0, error -19: no device
> [ 1140.662630] usb 2-4.3: USB disconnect, device number 15
> [ 1140.722584] usb 1-2.3: USB disconnect, device number 51
> [ 1140.722605] usb 1-2.3.2: USB disconnect, device number 52
> [ 1140.805724] usb 2-4.4: USB disconnect, device number 16
> [ 1141.352341] usb 1-2.3.3: USB disconnect, device number 54
> [ 1141.558840] hub 1-2.4:1.0: hub_ext_port_status failed (err = -71)
> [ 1141.613714] usb 1-2.3.5: USB disconnect, device number 55
> [ 1141.757651] usb 1-2.4: USB disconnect, device number 49
> [ 1144.324836] usb 1-2.4: new high-speed USB device number 56 using xhci_hcd
> [ 1144.473047] usb 1-2.4: New USB device found, idVendor=1a40, idProduct=0101, bcdDevice= 1.11
> [ 1144.473065] usb 1-2.4: New USB device strings: Mfr=0, Product=1, SerialNumber=0
> [ 1144.473072] usb 1-2.4: Product: USB 2.0 Hub
> [ 1144.473738] hub 1-2.4:1.0: USB hub found
> [ 1144.473765] hub 1-2.4:1.0: 4 ports detected
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?
Takashi
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ALSA: pcm: Show closed for DISCONNECTED state
2026-06-17 7:19 Re: " Ai Chao
@ 2026-06-17 8:36 ` Jaroslav Kysela
2026-06-17 8:53 ` Takashi Iwai
0 siblings, 1 reply; 7+ messages in thread
From: Jaroslav Kysela @ 2026-06-17 8:36 UTC (permalink / raw)
To: Ai Chao, tiwai, kees; +Cc: linux-sound, linux-kernel
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@perex.cz>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ALSA: pcm: Show closed for DISCONNECTED state
2026-06-17 8:36 ` Jaroslav Kysela
@ 2026-06-17 8:53 ` Takashi Iwai
0 siblings, 0 replies; 7+ messages in thread
From: Takashi Iwai @ 2026-06-17 8:53 UTC (permalink / raw)
To: Jaroslav Kysela; +Cc: Ai Chao, tiwai, kees, linux-sound, linux-kernel
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)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Re: Re: [PATCH] ALSA: pcm: Show closed for DISCONNECTED state
@ 2026-06-19 9:29 Ai Chao
2026-06-19 13:34 ` Takashi Iwai
0 siblings, 1 reply; 7+ messages in thread
From: Ai Chao @ 2026-06-19 9:29 UTC (permalink / raw)
To: perex, tiwai, kees; +Cc: linux-sound, linux-kernel
Hello Takashi
> Right, I suspect that it might be the case.
> Does the change like below help (or worsen) anything?
We tested this solution and verified its feasibility.
Thanks,
Ai Chao
--- 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)
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH] ALSA: pcm: Show closed for DISCONNECTED state
2026-06-19 9:29 Re: Re: [PATCH] ALSA: pcm: Show closed for DISCONNECTED state Ai Chao
@ 2026-06-19 13:34 ` Takashi Iwai
0 siblings, 0 replies; 7+ messages in thread
From: Takashi Iwai @ 2026-06-19 13:34 UTC (permalink / raw)
To: Ai Chao; +Cc: perex, tiwai, kees, linux-sound, linux-kernel
On Fri, 19 Jun 2026 11:29:36 +0200,
Ai Chao wrote:
>
> Hello Takashi
>
> > Right, I suspect that it might be the case.
> > Does the change like below help (or worsen) anything?
>
> We tested this solution and verified its feasibility.
OK, then I'm going to submit a proper patch later.
As it's a bit drastic change and it's already in a merge window for
7.2, I'd postpone the fix for 7.3.
thanks,
Takashi
>
> Thanks,
> Ai Chao
>
> --- 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)
>
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2026-06-19 13:34 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-19 9:29 Re: Re: [PATCH] ALSA: pcm: Show closed for DISCONNECTED state Ai Chao
2026-06-19 13:34 ` Takashi Iwai
-- strict thread matches above, loose matches on Subject: below --
2026-06-17 7:19 Re: " Ai Chao
2026-06-17 8:36 ` Jaroslav Kysela
2026-06-17 8:53 ` Takashi Iwai
2026-06-16 2:06 Ai Chao
2026-06-16 7:24 ` Takashi Iwai
2026-06-15 13:26 Ai Chao
2026-06-15 13:51 ` Takashi Iwai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox