Skip to content

Commit 18977c0

Browse files
CassivsGabriellistiwai
authored andcommitted
ALSA: usx2y: Drain pending US-428 pipe-4 output commands
The US-428 pipe-4 output path submits at most one pending p4out entry from the shared-memory ring per input interrupt. If userspace queues more than one command before the interrupt handler runs, later commands remain pending until later input interrupts, even when async pipe-4 URBs are available. Drain pending entries while idle async URBs are available. Copy each command into the existing per-URB async buffer before submission, so the submitted transfer does not depend on a userspace-mapped ring slot remaining unchanged after p4out_sent is advanced. Also update p4out_sent only after usb_submit_urb() succeeds, so a failed submission is not reported as sent. This keeps the shared-memory ABI unchanged and fixes only the local queue-draining behavior. Signed-off-by: Cássio Gabriel <cassiogabrielcontato@gmail.com> Link: https://patch.msgid.link/20260519-alsa-usx2y-p4out-drain-v1-1-8f0a4550bae2@gmail.com Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 0c09413 commit 18977c0

1 file changed

Lines changed: 23 additions & 16 deletions

File tree

sound/usb/usx2y/usbusx2y.c

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ static void i_usx2y_in04_int(struct urb *urb)
180180
struct usx2ydev *usx2y = urb->context;
181181
struct us428ctls_sharedmem *us428ctls = usx2y->us428ctls_sharedmem;
182182
struct us428_p4out *p4out;
183-
int i, j, n, diff, send;
183+
int i, j, n, diff, send, len;
184184

185185
usx2y->in04_int_calls++;
186186

@@ -222,24 +222,31 @@ static void i_usx2y_in04_int(struct urb *urb)
222222
} while (!err && usx2y->us04->submitted < usx2y->us04->len);
223223
}
224224
} else {
225-
if (us428ctls && us428ctls->p4out_last >= 0 && us428ctls->p4out_last < N_US428_P4OUT_BUFS) {
226-
if (us428ctls->p4out_last != us428ctls->p4out_sent) {
227-
send = us428ctls->p4out_sent + 1;
228-
if (send >= N_US428_P4OUT_BUFS)
229-
send = 0;
230-
for (j = 0; j < URBS_ASYNC_SEQ && !err; ++j) {
231-
if (!usx2y->as04.urb[j]->status) {
232-
p4out = us428ctls->p4out + send; // FIXME if more than 1 p4out is new, 1 gets lost.
233-
usb_fill_bulk_urb(usx2y->as04.urb[j], usx2y->dev,
234-
usb_sndbulkpipe(usx2y->dev, 0x04), &p4out->val.vol,
235-
p4out->type == ELT_LIGHT ? sizeof(struct us428_lights) : 5,
236-
i_usx2y_out04_int, usx2y);
237-
err = usb_submit_urb(usx2y->as04.urb[j], GFP_ATOMIC);
225+
while (us428ctls &&
226+
us428ctls->p4out_last >= 0 &&
227+
us428ctls->p4out_last < N_US428_P4OUT_BUFS &&
228+
us428ctls->p4out_last != us428ctls->p4out_sent) {
229+
for (j = 0; j < URBS_ASYNC_SEQ && !err; ++j) {
230+
if (!usx2y->as04.urb[j]->status) {
231+
send = us428ctls->p4out_sent + 1;
232+
if (send >= N_US428_P4OUT_BUFS)
233+
send = 0;
234+
235+
p4out = us428ctls->p4out + send;
236+
len = p4out->type == ELT_LIGHT ?
237+
sizeof(struct us428_lights) : 5;
238+
memcpy(usx2y->as04.urb[j]->transfer_buffer,
239+
&p4out->val.vol, len);
240+
usx2y->as04.urb[j]->transfer_buffer_length = len;
241+
err = usb_submit_urb(usx2y->as04.urb[j], GFP_ATOMIC);
242+
if (!err)
238243
us428ctls->p4out_sent = send;
239-
break;
240-
}
244+
245+
break;
241246
}
242247
}
248+
if (j >= URBS_ASYNC_SEQ || err)
249+
break;
243250
}
244251
}
245252

0 commit comments

Comments
 (0)