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=1796154123; b=g+kYXHxE3bOsNKbFAikPYVKUseYSQ41flDtqKxUgH1glqDmr47mtGb75IJJumvnRFt2T 7WXEqynFnxJuE4gl6GqFit7p/xt3dcyot7Xrbwa8XqGkgRsXlZbwSD7ZFeOpEXx5v865M jOs3Ixrt1EbwDtTAMLnpoRBOohrodeJPwnxcYPT7DHJkLxafjsaqVz8/+xA88CyaKhzbN OYm6K3TSh8ApnqtuF4qG/iHdNCCH0pTDyQZbe/APYCVjkz97dqkuWVyTKUE/vLGMHW2Uo +KEkol1FIsLFT13OcmFSMwIBvAPmSdDAsfHEAnBYy2vH9orCnv+akNhDByplIxM84HQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796154123; 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=5OGtbslmxV2cDr3m02NIEkpNuA4Qfvdo1Bssp/05mc4=; b=MiZiD4zeXNtlsSqPOJq7H3IQBlwe2GAHyi3LAeZYa6daiGNQ0I7RTMjaOfOFf9fK1li/ A0RwcKsjc9bLe8DsfaqQO3tXfHkVvn2KcFI0wt/2vQzY3fAmErFGHPahZ+1BEGYNPPTeq 5ZZbmnLb2af7HSRlBSZcYj5MVZRfu3riTuTCJ+rhjbnWiX2cT/s+6yYm5sFSvWZtWjtMp 4Ei08LGbkCvKeDOF28mYteAl1jPteKjDchYlFitpCBK6lWjWpORomOAEzfSn/uiYK+6+G aSlVJtfdohJ+0LSrqUA+zbjA9QwGbjPOzX3ZwyatUCF3KRzGjCy8D+MUo70Wiqu116Q== 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="dD9rw/yv"; 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 F1B53606A32C for ; Tue, 1 Dec 2026 19:42:02 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org F1B53606A32C 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=dD9rw/yv DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796154123; x=1827690123; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=5OGtbslmxV2cDr3m02NIEkpNuA4Qfvdo1Bssp/05mc4=; b=dD9rw/yvNYbzePlDwG6KQL0hXFlL2UJHjX9RhBrLwTkYpSXRKjgTBBli lMwzUloM6dFsSL7fJpmyg2LBhEhH+vKq1ThAZ6UtLnjezT2i8bkYft0H9 yW/qVDW1G0okj+W1c5j4zudwtgCJYB/jU3umrXoY/Mx7JzhdNcWKxwPEk wNKpcfF6n3/1zLDyFM/I9wsisZ7Owh8j3lgSuKFFAwzT3267U/bfOCg9H y9RANKfQXvRJTBhrsVuKMYWJKSHWx9jhE7UquMiNgL/jp73LYUwINURSb bacz7iz239cIlhj3WzX90+9YK+WIOghzQQ6KylNdYvwgBIS8rxSCO/LXk Q==; X-CSE-ConnectionGUID: 4DyMbrq7ThCkmS5JjoS0iA== X-CSE-MsgGUID: dsI2tkqHQ+ueRlet0WgSog== X-IronPort-AV: E=McAfee;i="6800,10657,11983"; a="5049031" X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="5049031" Received: from fmviesa009.fm.intel.com ([10.60.135.149]) by orvoesa109.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Dec 2026 11:42:02 -0800 X-CSE-ConnectionGUID: KEVeyiPST2ig36M1mgL63g== X-CSE-MsgGUID: ANWMxyAORKWJeKHV2XQrAQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,245,1787036400"; d="scan'208";a="13702917" Received: from black.igk.intel.com ([10.91.253.5]) by fmviesa009.fm.intel.com with ESMTP; 01 Dec 2026 11:42:01 -0800 Received: by black.igk.intel.com (Postfix, from userid 1058) id BE9AE98; Tue, 01 Dec 2026 20:42:00 +0100 (CET) From: Niklas Neronin To: mathias.nyman@linux.intel.com Cc: linux-usb@vger.kernel.org, Niklas Neronin Subject: [PATCH 1/7] usb: xhci: simplify xhci_get_input_control_ctx() Date: Tue, 1 Dec 2026 20:41:28 +0100 Message-ID: <20261201194134.265480-2-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 xhci_get_input_control_ctx() returns NULL if the container context is not an input context, so every caller carries its own error handling for that case. That case cannot happen at runtime. A container's type is set once at allocation by xhci_alloc_container_ctx() and never changes. Every context passed to this helper is a 'virt_dev' or command 'in_ctx', which is always allocated as XHCI_CTX_TYPE_INPUT. A wrong type can only come from a driver bug, not from hardware or user input. Replace the NULL return with WARN_ON_ONCE() so that misuse produces a backtrace pointing at the bad caller, and remove the error handling from all callers. Signed-off-by: Niklas Neronin --- drivers/usb/host/xhci-mem.c | 7 +--- drivers/usb/host/xhci-ring.c | 6 +-- drivers/usb/host/xhci.c | 79 +----------------------------------- 3 files changed, 5 insertions(+), 87 deletions(-) diff --git a/drivers/usb/host/xhci-mem.c b/drivers/usb/host/xhci-mem.c index 75577f441cdd..3ccc9f7404b7 100644 --- a/drivers/usb/host/xhci-mem.c +++ b/drivers/usb/host/xhci-mem.c @@ -512,12 +512,9 @@ void xhci_free_port_bw_ctx(struct xhci_hcd *xhci, kfree(ctx); } -struct xhci_input_control_ctx *xhci_get_input_control_ctx( - struct xhci_container_ctx *ctx) +struct xhci_input_control_ctx *xhci_get_input_control_ctx(struct xhci_container_ctx *ctx) { - if (ctx->type != XHCI_CTX_TYPE_INPUT) - return NULL; - + WARN_ON_ONCE(ctx->type != XHCI_CTX_TYPE_INPUT); return (struct xhci_input_control_ctx *)ctx->bytes; } diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c index a1fa188680f5..53e1e9a59f14 100644 --- a/drivers/usb/host/xhci-ring.c +++ b/drivers/usb/host/xhci-ring.c @@ -1700,12 +1700,8 @@ static void xhci_handle_cmd_config_ep(struct xhci_hcd *xhci, int slot_id) virt_dev = xhci->devs[slot_id]; if (!virt_dev) return; - ctrl_ctx = xhci_get_input_control_ctx(virt_dev->in_ctx); - if (!ctrl_ctx) { - xhci_warn(xhci, "Could not get input context, bad type.\n"); - return; - } + ctrl_ctx = xhci_get_input_control_ctx(virt_dev->in_ctx); add_flags = le32_to_cpu(ctrl_ctx->add_flags); /* Input ctx add_flags are the endpoint index plus one */ diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index fc1b0a6b0429..9688c5986a40 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -1580,12 +1580,7 @@ static int xhci_check_ep0_maxpacket(struct xhci_hcd *xhci, struct xhci_virt_devi command->in_ctx = vdev->in_ctx; ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); - if (!ctrl_ctx) { - xhci_warn(xhci, "%s: Could not get input context, bad type.\n", - __func__); - ret = -ENOMEM; - break; - } + /* Set up the modified control endpoint 0 */ xhci_endpoint_copy(xhci, vdev->in_ctx, vdev->out_ctx, 0); @@ -1929,12 +1924,6 @@ int xhci_drop_endpoint(struct usb_hcd *hcd, struct usb_device *udev, in_ctx = xhci->devs[udev->slot_id]->in_ctx; out_ctx = xhci->devs[udev->slot_id]->out_ctx; ctrl_ctx = xhci_get_input_control_ctx(in_ctx); - if (!ctrl_ctx) { - xhci_warn(xhci, "%s: Could not get input context, bad type.\n", - __func__); - return 0; - } - ep_index = xhci_get_endpoint_index(&ep->desc); ep_ctx = xhci_get_ep_ctx(xhci, out_ctx, ep_index); /* If the HC already knows the endpoint is disabled, @@ -2019,11 +2008,6 @@ int xhci_add_endpoint(struct usb_hcd *hcd, struct usb_device *udev, virt_dev = xhci->devs[udev->slot_id]; in_ctx = virt_dev->in_ctx; ctrl_ctx = xhci_get_input_control_ctx(in_ctx); - if (!ctrl_ctx) { - xhci_warn(xhci, "%s: Could not get input context, bad type.\n", - __func__); - return 0; - } ep_index = xhci_get_endpoint_index(&ep->desc); /* If this endpoint is already in use, and the upper layers are trying @@ -2091,11 +2075,6 @@ static void xhci_zero_in_ctx(struct xhci_hcd *xhci, struct xhci_virt_device *vir int i; ctrl_ctx = xhci_get_input_control_ctx(virt_dev->in_ctx); - if (!ctrl_ctx) { - xhci_warn(xhci, "%s: Could not get input context, bad type.\n", - __func__); - return; - } /* When a device's add flag and drop flag are zero, any subsequent * configure endpoint command will leave that endpoint's state @@ -2809,11 +2788,6 @@ static int xhci_reserve_bandwidth(struct xhci_hcd *xhci, old_active_eps = virt_dev->tt_info->active_eps; ctrl_ctx = xhci_get_input_control_ctx(in_ctx); - if (!ctrl_ctx) { - xhci_warn(xhci, "%s: Could not get input context, bad type.\n", - __func__); - return -ENOMEM; - } for (i = 0; i < 31; i++) { if (!EP_IS_ADDED(ctrl_ctx, i) && !EP_IS_DROPPED(ctrl_ctx, i)) @@ -2981,12 +2955,6 @@ static int xhci_configure_endpoint(struct xhci_hcd *xhci, virt_dev = xhci->devs[udev->slot_id]; ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); - if (!ctrl_ctx) { - spin_unlock_irqrestore(&xhci->lock, flags); - xhci_warn(xhci, "%s: Could not get input context, bad type.\n", - __func__); - return -ENOMEM; - } if ((xhci->quirks & XHCI_EP_LIMIT_QUIRK) && xhci_reserve_host_resources(xhci, ctrl_ctx)) { @@ -3106,12 +3074,6 @@ int xhci_check_bandwidth(struct usb_hcd *hcd, struct usb_device *udev) /* See section 4.6.6 - A0 = 1; A1 = D0 = D1 = 0 */ ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); - if (!ctrl_ctx) { - xhci_warn(xhci, "%s: Could not get input context, bad type.\n", - __func__); - ret = -ENOMEM; - goto command_cleanup; - } ctrl_ctx->add_flags |= cpu_to_le32(SLOT_FLAG); ctrl_ctx->add_flags &= cpu_to_le32(~EP0_FLAG); ctrl_ctx->drop_flags &= cpu_to_le32(~(SLOT_FLAG | EP0_FLAG)); @@ -3421,13 +3383,6 @@ static void xhci_endpoint_reset(struct usb_hcd *hcd, /* config ep command clears toggle if add and drop ep flags are set */ ctrl_ctx = xhci_get_input_control_ctx(cfg_cmd->in_ctx); - if (!ctrl_ctx) { - spin_unlock_irqrestore(&xhci->lock, flags); - xhci_free_command(xhci, cfg_cmd); - xhci_warn(xhci, "%s: Could not get input context, bad type.\n", - __func__); - goto cleanup; - } xhci_setup_input_ctx_for_config_ep(xhci, cfg_cmd->in_ctx, vdev->out_ctx, ctrl_ctx, ep_flag, ep_flag); @@ -3650,12 +3605,6 @@ static int xhci_alloc_streams(struct usb_hcd *hcd, struct usb_device *udev, return -ENOMEM; ctrl_ctx = xhci_get_input_control_ctx(config_cmd->in_ctx); - if (!ctrl_ctx) { - xhci_warn(xhci, "%s: Could not get input context, bad type.\n", - __func__); - xhci_free_command(xhci, config_cmd); - return -ENOMEM; - } /* Check to make sure all endpoints are not already configured for * streams. While we're at it, find the maximum number of streams that @@ -3812,12 +3761,6 @@ static int xhci_free_streams(struct usb_hcd *hcd, struct usb_device *udev, 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); - if (!ctrl_ctx) { - spin_unlock_irqrestore(&xhci->lock, flags); - xhci_warn(xhci, "%s: Could not get input context, bad type.\n", - __func__); - return -EINVAL; - } for (i = 0; i < num_eps; i++) { struct xhci_ep_ctx *ep_ctx; @@ -4384,12 +4327,7 @@ static int xhci_setup_device(struct usb_hcd *hcd, struct usb_device *udev, slot_ctx = xhci_get_slot_ctx(xhci, virt_dev->in_ctx); ctrl_ctx = xhci_get_input_control_ctx(virt_dev->in_ctx); - if (!ctrl_ctx) { - xhci_warn(xhci, "%s: Could not get input context, bad type.\n", - __func__); - ret = -EINVAL; - goto out; - } + /* * If this is the first Set Address since device plug-in or * virt_device realloaction after a resume with an xHCI power loss, @@ -4570,13 +4508,6 @@ static int __maybe_unused xhci_change_max_exit_latency(struct xhci_hcd *xhci, /* Attempt to issue an Evaluate Context command to change the MEL. */ ctrl_ctx = xhci_get_input_control_ctx(command->in_ctx); - if (!ctrl_ctx) { - spin_unlock_irqrestore(&xhci->lock, flags); - xhci_free_command(xhci, command); - xhci_warn(xhci, "%s: Could not get input context, bad type.\n", - __func__); - return -ENOMEM; - } xhci_slot_copy(xhci, command->in_ctx, virt_dev->out_ctx); spin_unlock_irqrestore(&xhci->lock, flags); @@ -5302,12 +5233,6 @@ int xhci_update_hub_device(struct usb_hcd *hcd, struct usb_device *hdev, return -ENOMEM; ctrl_ctx = xhci_get_input_control_ctx(config_cmd->in_ctx); - if (!ctrl_ctx) { - xhci_warn(xhci, "%s: Could not get input context, bad type.\n", - __func__); - xhci_free_command(xhci, config_cmd); - return -ENOMEM; - } spin_lock_irqsave(&xhci->lock, flags); if (hdev->speed == USB_SPEED_HIGH && -- 2.50.1