Linux USB
 help / color / mirror / Atom feed
From: Niklas Neronin <niklas.neronin@linux.intel.com>
To: mathias.nyman@linux.intel.com
Cc: linux-usb@vger.kernel.org,
	Niklas Neronin <niklas.neronin@linux.intel.com>
Subject: [PATCH 5/7] usb: xhci: clear EP_GETTING_NO_STREAMS when freeing streams fails
Date: Tue,  1 Dec 2026 20:41:32 +0100	[thread overview]
Message-ID: <20261201194134.265480-6-niklas.neronin@linux.intel.com> (raw)
In-Reply-To: <20261201194134.265480-1-niklas.neronin@linux.intel.com>

xhci_free_streams() sets EP_GETTING_NO_STREAMS on each endpoint before
issuing the Configure Endpoint command that removes the streams. The
flag is only cleared on success. If the command fails, either because
it can't be queued or because the xHC rejects it, the function returns
with the flag still set.

xhci_urb_enqueue() rejects URBs for endpoints that have
EP_GETTING_NO_STREAMS set, so after a failed free_streams call the
endpoint can't be used until the device is reconfigured or reset.

Clear EP_GETTING_NO_STREAMS on the error path. The streams rings and
EP_HAS_STREAMS are left untouched, so the endpoint stays in its
previous streams state and the caller can retry.

Signed-off-by: Niklas Neronin <niklas.neronin@linux.intel.com>
---
 drivers/usb/host/xhci.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index d2ca031cff70..841ef59b83f6 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -3754,8 +3754,7 @@ static int xhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev,
 
 		ep_index = xhci_get_endpoint_index(&eps[i]->desc);
 		ep_ctx = xhci_get_ep_ctx(xhci, command->in_ctx, ep_index);
-		xhci->devs[udev->slot_id]->eps[ep_index].ep_state |=
-			EP_GETTING_NO_STREAMS;
+		vdev->eps[ep_index].ep_state |= EP_GETTING_NO_STREAMS;
 
 		xhci_endpoint_copy(xhci, command->in_ctx,
 				vdev->out_ctx, ep_index);
@@ -3771,12 +3770,16 @@ static int xhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev,
 	 * which must succeed.
 	 */
 	ret = xhci_configure_endpoint(xhci, udev, command, true);
-
-	/* xHC rejected the configure endpoint command for some reason, so we
-	 * leave the streams rings intact.
-	 */
-	if (ret < 0)
+	if (ret < 0) {
+		/* Configure Endpoint failed for some reason, so leave the streams rings intact. */
+		spin_lock_irqsave(&xhci->lock, flags);
+		for (i = 0; i < num_eps; i++) {
+			ep_index = xhci_get_endpoint_index(&eps[i]->desc);
+			vdev->eps[ep_index].ep_state &= ~EP_GETTING_NO_STREAMS;
+		}
+		spin_unlock_irqrestore(&xhci->lock, flags);
 		return ret;
+	}
 
 	/*
 	 * dma_free_coherent() called by xhci_free_stream_info() may sleep,
-- 
2.50.1


  parent reply	other threads:[~2026-12-01 19:42 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01 19:41 [PATCH 0/7] usb: xhci: command queueing cleanups Niklas Neronin
2026-12-01 19:41 ` [PATCH 1/7] usb: xhci: simplify xhci_get_input_control_ctx() Niklas Neronin
2026-12-01 19:47   ` sashiko-bot
2026-12-01 19:41 ` [PATCH 2/7] usb: xhci: add xhci_queue_set_deq() helper Niklas Neronin
2026-12-01 19:41 ` [PATCH 3/7] usb: xhci: simplify prepare_ring() Niklas Neronin
2026-12-01 19:41 ` [PATCH 4/7] usb: xhci: split Configure Endpoint and Evaluate Context handling Niklas Neronin
2026-12-01 19:41 ` Niklas Neronin [this message]
2026-12-01 19:52   ` [PATCH 5/7] usb: xhci: clear EP_GETTING_NO_STREAMS when freeing streams fails sashiko-bot
2026-12-01 19:41 ` [PATCH 6/7] usb: xhci: remove pre-allocated free streams command Niklas Neronin
2026-12-01 19:41 ` [PATCH 7/7] usb: xhci: remove command ring TRB reservation Niklas Neronin
2026-12-01 19:52 ` [PATCH 0/7] usb: xhci: command queueing cleanups sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261201194134.265480-6-niklas.neronin@linux.intel.com \
    --to=niklas.neronin@linux.intel.com \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox