usb: xhci: Avoid Stop Endpoint retry loop if the endpoint seems Running
authorMichal Pecio <michal.pecio@gmail.com>
Tue, 11 Mar 2025 15:45:51 +0000 (17:45 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 11 Mar 2025 16:58:43 +0000 (17:58 +0100)
Nothing prevents a broken HC from claiming that an endpoint is Running
and repeatedly rejecting Stop Endpoint with Context State Error.

Avoid infinite retries and give back cancelled TDs.

No such cases known so far, but HCs have bugs.

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-4-mathias.nyman@linux.intel.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/host/xhci-ring.c

index 303d66df271ea6b81a2bc19c344a525858592391..5d64c297721cd94088725e883f3fba520522c725 100644 (file)
@@ -1264,16 +1264,19 @@ reset_done:
                         * Stopped state, but it will soon change to Running.
                         *
                         * Assume this bug on unexpected Stop Endpoint failures.
-                        * Keep retrying until the EP starts and stops again, on
-                        * chips where this is known to help. Wait for 100ms.
+                        * Keep retrying until the EP starts and stops again.
                         */
-                       if (time_is_before_jiffies(ep->stop_time + msecs_to_jiffies(100)))
-                               break;
                        fallthrough;
                case EP_STATE_RUNNING:
                        /* Race, HW handled stop ep cmd before ep was running */
                        xhci_dbg(xhci, "Stop ep completion ctx error, ctx_state %d\n",
                                        GET_EP_CTX_STATE(ep_ctx));
+                       /*
+                        * Don't retry forever if we guessed wrong or a defective HC never starts
+                        * the EP or says 'Running' but fails the command. We must give back TDs.
+                        */
+                       if (time_is_before_jiffies(ep->stop_time + msecs_to_jiffies(100)))
+                               break;
 
                        command = xhci_alloc_command(xhci, false, GFP_ATOMIC);
                        if (!command) {