From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.17 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796154130; b=pKctn+ob+i+te+sHYppvF7oFfGFcVj1j8688/Qxa0R9EAO1A2qwY8oVnFnjrccNOthEW K1x8WDM53reul+aDeVBJeU+qghwhKhAMYX/OLnak/nlcmwd9pmakuY1WMqODA1lCYgmxi //bMiwsT5KcIHHioBRqF05Jx2LUIj6ylJpZAXbIeygWsBITRrMCEJkbaJng7yA/cttDlx VyzuXtDK0icRSLmKfldJlqYVNAocRxIFXyd81li6BNPV5QTtGpEFyfbkNWOdlG5IW3OiO +xFikLramqCTSaDM9D4Fkf5HJhMEQEig8X3kPRNKn2uodU/OfXNbrFpxTvSrq9zVeeg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796154130; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Received:From:To:Cc: Subject:Date:Message-ID:X-Mailer:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding; bh=fTtQ1zS8xnHQIdwvnuirlSaof4X16N/bRMRsQERh4mw=; b=eJIsHNEhW7iczbDei+kb6mXBeadk9hpsvHIQHc6FKwoIa5sUL/cDTzZ071Gp8YXvZK29 uixUaKseNJNpOPGRgdW+FlM+LrJsD9/r8953FANTDXVA6rLo65O9DnGezJUcUAUnwRyw/ jsjb8TkFpdxiEwYxBIszEV/ZDV/b4G9gcucVNgtVDkR19d25Aq3Pnhb4UOVk7jMWx8Qph Do8KsjsWCoG8qcgKcqAUeZc305nk5MWUkYYiPoOYz90DQNEq3dXZi/9Gm+F12cBPAyvId 99W7yrM/m1DIJRTGJN6+PGZLtmCk/1INcDdZqf1NEO3ZA58doC0IKjvFrA+4BYv7rKw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.intel.com; spf=pass smtp.mailfrom=linux.intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=CEzmAS9w; arc=none smtp.remote-ip=198.175.65.17 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.17]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AE362606A33A for ; Tue, 1 Dec 2026 19:42:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AE362606A33A Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=CEzmAS9w DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796154130; x=1827690130; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=fTtQ1zS8xnHQIdwvnuirlSaof4X16N/bRMRsQERh4mw=; b=CEzmAS9wLyBf3TTIV3GCPTGzUH3iu393hOVM3JdifpE9GPBqinrfyJ9k Y2PwJAMqC/i/t/aWKsbjXbCF4P/qCEPzMMNv6lxG7Vo7CpbkeqJhJ4so7 gtcgd4F3CTSm8WuX+na8P9Zyfl4f//ZCfPzfuUul7Of8sgwTLU98FfFHz HVCeeN8CaYCT2nR2IQkmcymguC3EiKjKlm7rTm9vrGUQ4NCCSDm84W8Qg HG5nS/cIdul2fOUEUt3E7owSsmJK8WQ18cUACDvfavqzht33WiCxJEvTh M5C51HMeM1UcqP9inMQFd2uVGqNOM9/ei/nLk/Y/LSstMAoI1c3WTixN6 A==; X-CSE-ConnectionGUID: 0fqAQCqcQE6m0n/Tjh1iGQ== X-CSE-MsgGUID: pk7fyX/eQMiry6EpNe+R9g== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="5049048" X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="5049048" Received: from fmviesa001.fm.intel.com ([10.60.135.141]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 11:42:08 -0800 X-CSE-ConnectionGUID: blKI4mV8T0erMbEqwZgZTw== X-CSE-MsgGUID: XoR9ILVrQgyf2ZMOpQJxHg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="13818660" Received: from black.igk.intel.com ([10.91.253.5]) by fmviesa001.fm.intel.com with ESMTP; 01 Dec 2026 11:42:08 -0800 Received: by black.igk.intel.com (Postfix, from userid 1058) id A8B33A1; Tue, 01 Dec 2026 20:42:06 +0100 (CET) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, Niklas Neronin Subject: [PATCH 6/7] usb: xhci: remove pre-allocated free streams command Date: Tue, 1 Dec 2026 20:41:33 +0100 Message-ID: <20261201194134.265480-7-niklas.neronin@linux.intel.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20261201194134.265480-1-niklas.neronin@linux.intel.com> References: <20261201194134.265480-1-niklas.neronin@linux.intel.com> X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Most xHCI commands are allocated immediately before being queued and freed after completion. The free streams path is an exception, keeping a command structure pre-allocated in struct 'xhci_stream_info' solely for later use by xhci_free_streams(). This is a leftover from older command handling. Similar pre-allocated commands have already been removed elsewhere, leaving the free streams command as the only remaining user of this pattern. Allocate the command when xhci_free_streams() is invoked and free it after use. This removes a special case from stream management and makes command lifetime handling consistent with the rest of the driver. As a result, xhci_free_streams() can now fail with -ENOMEM if the command allocation fails. This is the same failure mode as other paths that issue commands, and the function could already fail for other reasons (e.g. command queueing or completion errors), so callers already handle error return. In that case the endpoints are left untouched and keep their streams. Signed-off-by: Niklas Neronin --- drivers/usb/host/xhci-mem.c | 9 --------- drivers/usb/host/xhci.c | 15 +++++++-------- drivers/usb/host/xhci.h | 1 - 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 3ccc9f7404b7..78eb8358ea29 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -645,12 +645,6 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci, if (!stream_info->stream_ctx_array) goto cleanup_ring_array; - /* Allocate everything needed to free the stream rings later */ - stream_info->free_streams_command = - xhci_alloc_command_with_ctx(xhci, true, mem_flags); - if (!stream_info->free_streams_command) - goto cleanup_ctx; - INIT_RADIX_TREE(&stream_info->trb_address_map, GFP_ATOMIC); /* Allocate rings for all the streams that the driver will use, @@ -702,8 +696,6 @@ struct xhci_stream_info *xhci_alloc_stream_info(struct xhci_hcd *xhci, stream_info->stream_rings[cur_stream] = NULL; } } - xhci_free_command(xhci, stream_info->free_streams_command); -cleanup_ctx: xhci_free_stream_ctx(xhci, stream_info->num_stream_ctxs, stream_info->stream_ctx_array, @@ -774,7 +766,6 @@ void xhci_free_stream_info(struct xhci_hcd *xhci, stream_info->stream_rings[cur_stream] = NULL; } } - xhci_free_command(xhci, stream_info->free_streams_command); xhci->cmd_ring_reserved_trbs--; if (stream_info->stream_ctx_array) xhci_free_stream_ctx(xhci, diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 841ef59b83f6..f419b4246c64 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -3732,23 +3732,20 @@ static int xhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev, xhci = hcd_to_xhci(hcd); vdev = xhci->devs[udev->slot_id]; + command = xhci_alloc_command_with_ctx(xhci, true, mem_flags); + if (!command) + return -ENOMEM; + /* Set up a configure endpoint command to remove the streams rings */ spin_lock_irqsave(&xhci->lock, flags); changed_ep_bitmask = xhci_calculate_no_streams_bitmask(xhci, udev, eps, num_eps); if (changed_ep_bitmask == 0) { spin_unlock_irqrestore(&xhci->lock, flags); + xhci_free_command(xhci, command); return -EINVAL; } - /* Use the xhci_command structure from the first endpoint. We may have - * allocated too many, but the driver may call xhci_free_streams() for - * each endpoint it grouped into one call to xhci_alloc_streams(). - */ - ep_index = xhci_get_endpoint_index(&eps[0]->desc); - command = vdev->eps[ep_index].stream_info->free_streams_command; - ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); - for (i = 0; i < num_eps; i++) { struct xhci_ep_ctx *ep_ctx; @@ -3761,6 +3758,7 @@ static int xhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev, xhci_setup_no_streams_ep_input_ctx(ep_ctx, &vdev->eps[ep_index]); } + ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); xhci_setup_input_ctx_for_config_ep(xhci, command->in_ctx, vdev->out_ctx, ctrl_ctx, changed_ep_bitmask, changed_ep_bitmask); @@ -3770,6 +3768,7 @@ static int xhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev, * which must succeed. */ ret = xhci_configure_endpoint(xhci, udev, command, true); + xhci_free_command(xhci, command); if (ret < 0) { /* Configure Endpoint failed for some reason, so leave the streams rings intact. */ spin_lock_irqsave(&xhci->lock, flags); diff --git a/drivers/usb/host/xhci.h b/drivers/usb/host/xhci.h index 852a6b537a60..7c3cb7f3b0aa 100644 --- a/drivers/usb/host/xhci.h +++ b/drivers/usb/host/xhci.h @@ -592,7 +592,6 @@ struct xhci_stream_info { dma_addr_t ctx_array_dma; /* For mapping physical TRB addresses to segments in stream rings */ struct radix_tree_root trb_address_map; - struct xhci_command *free_streams_command; }; #define SMALL_STREAM_ARRAY_SIZE 256 -- 2.50.1