* [PATCH 1/2] ALSA: 6fire: Don't resubmit an active MIDI URB
2026-11-23 8:48 [PATCH 0/2] ALSA: 6fire: avoid resubmitting an active URB YuanZhe Liu
@ 2026-11-23 8:48 ` YuanZhe Liu
2026-11-23 8:56 ` sashiko-bot
2026-11-23 8:48 ` [PATCH 2/2] ALSA: 6fire: Don't resubmit an active PCM out URB YuanZhe Liu
1 sibling, 1 reply; 4+ messages in thread
From: YuanZhe Liu @ 2026-11-23 8:48 UTC (permalink / raw)
To: Takashi Iwai
Cc: Jaroslav Kysela, linux-sound, linux-kernel, Bin Yu, Cheng Wen
The MIDI output keeps the transmission state in rt->out and submits
rt->out_urb from the rawmidi trigger callback. Stopping the stream,
for example through the SNDRV_RAWMIDI_IOCTL_DROP ioctl, only clears
rt->out; the URB itself stays queued until the device has accepted the
pending data, which can take a while when the device delays the
transfer.
If the stream is started again before that happens, the trigger callback
passes the still-active URB to usb_submit_urb() a second time. The USB
core rejects it and the new data is not sent:
URB 00000000c6cd6557 submitted while active
WARNING: drivers/usb/core/urb.c:379 at usb_submit_urb
...
usb6fire_midi_out_trigger
snd_rawmidi_kernel_write1
...
usb 1-1: midi out urb submit failed: -16
Track whether the URB is queued separately from the substream that owns
it, and let the completion handler send the data queued by a restart
while the URB is still in flight.
Fixes: c6d43ba816d1 ("ALSA: usb/6fire - Driver for TerraTec DMX 6Fire USB")
Co-developed-by: Bin Yu <byu@xidian.edu.cn>
Signed-off-by: Bin Yu <byu@xidian.edu.cn>
Co-developed-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
---
sound/usb/6fire/midi.c | 21 +++++++++++++++++----
sound/usb/6fire/midi.h | 1 +
2 files changed, 18 insertions(+), 4 deletions(-)
diff --git a/sound/usb/6fire/midi.c b/sound/usb/6fire/midi.c
index 279b449936e7..ae8a0d48eb41 100644
--- a/sound/usb/6fire/midi.c
+++ b/sound/usb/6fire/midi.c
@@ -25,6 +25,7 @@ static void usb6fire_midi_out_handler(struct urb *urb)
int ret;
guard(spinlock_irqsave)(&rt->out_lock);
+ rt->out_urb_active = false;
if (rt->out) {
ret = snd_rawmidi_transmit(rt->out, rt->out_buffer + 4,
@@ -39,6 +40,8 @@ static void usb6fire_midi_out_handler(struct urb *urb)
dev_err(&urb->dev->dev,
"midi out urb submit failed: %d\n",
ret);
+ else
+ rt->out_urb_active = true;
} else /* no more data to transmit */
rt->out = NULL;
}
@@ -74,6 +77,14 @@ static void usb6fire_midi_out_trigger(
if (rt->out) /* we are already transmitting so just return */
return;
+ rt->out = alsa_sub;
+ /*
+ * The urb is still in flight from the previous transmission;
+ * the completion handler sends the queued data instead.
+ */
+ if (rt->out_urb_active)
+ return;
+
ret = snd_rawmidi_transmit(alsa_sub, rt->out_buffer + 4,
MIDI_BUFSIZE - 4);
if (ret > 0) {
@@ -82,13 +93,15 @@ static void usb6fire_midi_out_trigger(
urb->transfer_buffer_length = ret + 4;
ret = usb_submit_urb(urb, GFP_ATOMIC);
- if (ret < 0)
+ if (ret < 0) {
+ rt->out = NULL;
dev_err(&urb->dev->dev,
"midi out urb submit failed: %d\n",
ret);
- else
- rt->out = alsa_sub;
- }
+ } else
+ rt->out_urb_active = true;
+ } else
+ rt->out = NULL;
} else if (rt->out == alsa_sub)
rt->out = NULL;
}
diff --git a/sound/usb/6fire/midi.h b/sound/usb/6fire/midi.h
index 8716ab8a863a..221361442435 100644
--- a/sound/usb/6fire/midi.h
+++ b/sound/usb/6fire/midi.h
@@ -23,6 +23,7 @@ struct midi_runtime {
spinlock_t out_lock;
struct snd_rawmidi_substream *out;
struct urb *out_urb;
+ bool out_urb_active; /* out urb is still queued in the HCD */
u8 out_serial; /* serial number of out packet */
u8 *out_buffer;
int buffer_offset;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH 2/2] ALSA: 6fire: Don't resubmit an active PCM out URB
2026-11-23 8:48 [PATCH 0/2] ALSA: 6fire: avoid resubmitting an active URB YuanZhe Liu
2026-11-23 8:48 ` [PATCH 1/2] ALSA: 6fire: Don't resubmit an active MIDI URB YuanZhe Liu
@ 2026-11-23 8:48 ` YuanZhe Liu
1 sibling, 0 replies; 4+ messages in thread
From: YuanZhe Liu @ 2026-11-23 8:48 UTC (permalink / raw)
To: Takashi Iwai
Cc: Jaroslav Kysela, linux-sound, linux-kernel, Bin Yu, Cheng Wen
usb6fire_pcm_in_urb_handler() refills the playback URB paired with the
capture URB that has just completed and submits it unconditionally,
although the comment right above expects "a free out urb was found".
Both URBs carry the same number of isochronous packets and are rearmed
at the same time, so the playback URB can still be queued when the next
capture completion arrives. The handler then rewrites a transfer buffer
that is still owned by the host controller and submits the active URB
again:
URB 000000003ec29e65 submitted while active
WARNING: drivers/usb/core/urb.c:379 at usb_submit_urb
...
usb6fire_pcm_in_urb_handler
__usb_hcd_giveback_urb
...
The resubmission fails and the playback data of that period is lost.
This is observed when the completion of the playback URB is delayed, for
example by missed isochronous services on the host controller.
Check whether the out URB has completed and skip it for the period
otherwise; the next capture completion retries.
Fixes: c6d43ba816d1 ("ALSA: usb/6fire - Driver for TerraTec DMX 6Fire USB")
Co-developed-by: Bin Yu <byu@xidian.edu.cn>
Signed-off-by: Bin Yu <byu@xidian.edu.cn>
Co-developed-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: Cheng Wen <wencheng@xidian.edu.cn>
Signed-off-by: YuanZhe Liu <25031212351@stu.xidian.edu.cn>
---
sound/usb/6fire/pcm.c | 16 +++++++++++++++-
sound/usb/6fire/pcm.h | 2 ++
2 files changed, 17 insertions(+), 1 deletion(-)
diff --git a/sound/usb/6fire/pcm.c b/sound/usb/6fire/pcm.c
index f5dfb8c3096a..d6ef8ffa97a9 100644
--- a/sound/usb/6fire/pcm.c
+++ b/sound/usb/6fire/pcm.c
@@ -460,6 +460,15 @@ static void usb6fire_pcm_in_urb_handler(struct urb *usb_urb)
if (period_elapsed)
snd_pcm_period_elapsed(sub->instance);
+ /*
+ * The out urb is submitted again from here, but the previous one may
+ * still be queued in the HCD. Its transfer buffer is owned by the
+ * HCD until it completes, so skip it for this period and retry at
+ * the next capture completion.
+ */
+ if (atomic_xchg(&out_urb->active, 1))
+ goto submit_in;
+
/* setup out urb structure */
for (i = 0; i < PCM_N_PACKETS_PER_URB; i++) {
unsigned int frames = 0;
@@ -525,8 +534,11 @@ static void usb6fire_pcm_in_urb_handler(struct urb *usb_urb)
* the frames of an out urb that was not submitted never reach the
* transmitter; the next urb continues the block at the same position
*/
- if (usb_submit_urb(out_urb->instance, GFP_ATOMIC) < 0)
+ if (usb_submit_urb(out_urb->instance, GFP_ATOMIC) < 0) {
rt->spdif_frame = spdif_frame;
+ atomic_set(&out_urb->active, 0);
+ }
+submit_in:
usb_submit_urb(in_urb->instance, GFP_ATOMIC);
}
@@ -535,6 +547,8 @@ static void usb6fire_pcm_out_urb_handler(struct urb *usb_urb)
struct pcm_urb *urb = usb_urb->context;
struct pcm_runtime *rt = urb->chip->pcm;
+ atomic_set(&urb->active, 0);
+
if (rt->stream_state == STREAM_STARTING) {
rt->stream_wait_cond = true;
wake_up(&rt->stream_wait_queue);
diff --git a/sound/usb/6fire/pcm.h b/sound/usb/6fire/pcm.h
index f1b867b9c468..b5d1f5106d2c 100644
--- a/sound/usb/6fire/pcm.h
+++ b/sound/usb/6fire/pcm.h
@@ -28,6 +28,8 @@ struct pcm_urb {
u8 *buffer;
struct pcm_urb *peer;
+
+ atomic_t active; /* urb is queued in the HCD */
};
struct pcm_substream {
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread