[PATCH 1/2] ALSA: 6fire: Don't resubmit an active MIDI URB
From: YuanZhe Liu
Date: Mon Nov 23 2026 - 03:49:13 EST
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@xxxxxxxxxxxxx>
Signed-off-by: Bin Yu <byu@xxxxxxxxxxxxx>
Co-developed-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: Cheng Wen <wencheng@xxxxxxxxxxxxx>
Signed-off-by: YuanZhe Liu <25031212351@xxxxxxxxxxxxxxxxx>
---
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