Skip to content

Commit dfc8835

Browse files
Michal Peciogregkh
authored andcommitted
usb: xhci: Don't change the status of stalled TDs on failed Stop EP
When the device stalls an endpoint, current TD is assigned -EPIPE status and Reset Endpoint is queued. If a Stop Endpoint is pending at the time, it will run before Reset Endpoint and fail due to the stall. Its handler will change TD's status to -EPROTO before Reset Endpoint handler runs and initiates giveback. Check if the stall has already been handled and don't try to do it again. Since xhci_handle_halted_endpoint() performs this check too, not overwriting td->status is the only difference. I haven't seen this case yet, but I have seen a related one where the xHC has already executed Reset Endpoint, EP Context state is now Stopped and EP_HALTED is set. If the xHC took a bit longer to execute Reset Endpoint, said case would become this one. Signed-off-by: Michal Pecio <michal.pecio@gmail.com> Signed-off-by: Mathias Nyman <mathias.nyman@linux.intel.com> Link: https://lore.kernel.org/r/20250311154551.4035726-3-mathias.nyman@linux.intel.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0c74d23 commit dfc8835

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

drivers/usb/host/xhci-ring.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,14 @@ static void xhci_handle_cmd_stop_ep(struct xhci_hcd *xhci, int slot_id,
12201220
*/
12211221
switch (GET_EP_CTX_STATE(ep_ctx)) {
12221222
case EP_STATE_HALTED:
1223-
xhci_dbg(xhci, "Stop ep completion raced with stall, reset ep\n");
1223+
xhci_dbg(xhci, "Stop ep completion raced with stall\n");
1224+
/*
1225+
* If the halt happened before Stop Endpoint failed, its transfer event
1226+
* should have already been handled and Reset Endpoint should be pending.
1227+
*/
1228+
if (ep->ep_state & EP_HALTED)
1229+
goto reset_done;
1230+
12241231
if (ep->ep_state & EP_HAS_STREAMS) {
12251232
reset_type = EP_SOFT_RESET;
12261233
} else {
@@ -1231,8 +1238,11 @@ static void xhci_handle_cmd_stop_ep(struct xhci_hcd *xhci, int slot_id,
12311238
}
12321239
/* reset ep, reset handler cleans up cancelled tds */
12331240
err = xhci_handle_halted_endpoint(xhci, ep, td, reset_type);
1241+
xhci_dbg(xhci, "Stop ep completion resetting ep, status %d\n", err);
12341242
if (err)
12351243
break;
1244+
reset_done:
1245+
/* Reset EP handler will clean up cancelled TDs */
12361246
ep->ep_state &= ~EP_STOP_CMD_PENDING;
12371247
return;
12381248
case EP_STATE_STOPPED:

0 commit comments

Comments
 (0)