Skip to content

Commit 45ba215

Browse files
aleksander0mgregkh
authored andcommitted
xhci: fix reporting of 0-sized URBs in control endpoint
When a control transfer has a short data stage, the xHCI controller generates two transfer events: a COMP_SHORT_TX event that specifies the untransferred amount, and a COMP_SUCCESS event. But when the data stage is not short, only the COMP_SUCCESS event occurs. Therefore, xhci-hcd must set urb->actual_length to urb->transfer_buffer_length while processing the COMP_SUCCESS event, unless urb->actual_length was set already by a previous COMP_SHORT_TX event. The driver checks this by seeing whether urb->actual_length == 0, but this alone is the wrong test, as it is entirely possible for a short transfer to have an urb->actual_length = 0. This patch changes the xhci driver to rely on a new td->urb_length_set flag, which is set to true when a COMP_SHORT_TX event is received and the URB length updated at that stage. This fixes a bug which affected the HSO plugin, which relies on URBs with urb->actual_length == 0 to halt re-submitting the RX URB in the control endpoint. Cc: <[email protected]> Signed-off-by: Aleksander Morgado <[email protected]> Signed-off-by: Mathias Nyman <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent d3d5389 commit 45ba215

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

drivers/usb/host/xhci-ring.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,7 +1946,7 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td,
19461946
if (event_trb != ep_ring->dequeue) {
19471947
/* The event was for the status stage */
19481948
if (event_trb == td->last_trb) {
1949-
if (td->urb->actual_length != 0) {
1949+
if (td->urb_length_set) {
19501950
/* Don't overwrite a previously set error code
19511951
*/
19521952
if ((*status == -EINPROGRESS || *status == 0) &&
@@ -1960,7 +1960,13 @@ static int process_ctrl_td(struct xhci_hcd *xhci, struct xhci_td *td,
19601960
td->urb->transfer_buffer_length;
19611961
}
19621962
} else {
1963-
/* Maybe the event was for the data stage? */
1963+
/*
1964+
* Maybe the event was for the data stage? If so, update
1965+
* already the actual_length of the URB and flag it as
1966+
* set, so that it is not overwritten in the event for
1967+
* the last TRB.
1968+
*/
1969+
td->urb_length_set = true;
19641970
td->urb->actual_length =
19651971
td->urb->transfer_buffer_length -
19661972
EVENT_TRB_LEN(le32_to_cpu(event->transfer_len));

drivers/usb/host/xhci.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
/*
23
* xHCI host controller driver
34
*
@@ -1291,6 +1292,8 @@ struct xhci_td {
12911292
struct xhci_segment *start_seg;
12921293
union xhci_trb *first_trb;
12931294
union xhci_trb *last_trb;
1295+
/* actual_length of the URB has already been set */
1296+
bool urb_length_set;
12941297
};
12951298

12961299
/* xHCI command default timeout value */

0 commit comments

Comments
 (0)