From patchwork Tue Feb 15 12:33:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mathias Nyman X-Patchwork-Id: 12746997 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3E95C433F5 for ; Tue, 15 Feb 2022 12:32:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237348AbiBOMcV (ORCPT ); Tue, 15 Feb 2022 07:32:21 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:38854 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230356AbiBOMcV (ORCPT ); Tue, 15 Feb 2022 07:32:21 -0500 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9DBBA107D33; Tue, 15 Feb 2022 04:32:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1644928331; x=1676464331; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=EM5eCCQn4Q/NVsLKS9eCO+fnF0DKH0tg68IuQmF81NU=; b=EBOCtmKnCvFWwAKntHcI/IzIkuBhZikTYxSBGgIirjM58IhGrmSVt/Rt 1Dvi/O+bnHmC9IXjRH11y2XVP9x4QBW7VvEDpAtUPRW1apd483C66qGCZ DAzSGrAFN87fQxIicuI1f8LKNr7ISPThGZZlWehs/j4ydKE53bCDyDf48 eO+mzTSEx5g/Z1fwkyD3d3/6TlFsu4Vg39Ngjl5sONVuw3Wkn5gE4UE55 pR2U+cGgGhLB25DYyuR7d3rqauie7rwZkib9NvB9ojY2Pao48nl37dV1X 5k/WcDvRIczaXQRPHYZ7fAWWxIuqnGqOB2zsRUSkcB0kDJkeBczCYWqWl A==; X-IronPort-AV: E=McAfee;i="6200,9189,10258"; a="250082443" X-IronPort-AV: E=Sophos;i="5.88,370,1635231600"; d="scan'208";a="250082443" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Feb 2022 04:32:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.88,370,1635231600"; d="scan'208";a="703641765" Received: from mattu-haswell.fi.intel.com ([10.237.72.199]) by orsmga005.jf.intel.com with ESMTP; 15 Feb 2022 04:32:09 -0800 From: Mathias Nyman To: Cc: , Hongyu Xie , stable@vger.kernel.org, Mathias Nyman Subject: [PATCH 2/2] xhci: Prevent futile URB re-submissions due to incorrect return value. Date: Tue, 15 Feb 2022 14:33:20 +0200 Message-Id: <20220215123320.1253947-3-mathias.nyman@linux.intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220215123320.1253947-1-mathias.nyman@linux.intel.com> References: <20220215123320.1253947-1-mathias.nyman@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Hongyu Xie The -ENODEV return value from xhci_check_args() is incorrectly changed to -EINVAL in a couple places before propagated further. xhci_check_args() returns 4 types of value, -ENODEV, -EINVAL, 1 and 0. xhci_urb_enqueue and xhci_check_streams_endpoint return -EINVAL if the return value of xhci_check_args <= 0. This causes problems for example r8152_submit_rx, calling usb_submit_urb in drivers/net/usb/r8152.c. r8152_submit_rx will never get -ENODEV after submiting an urb when xHC is halted because xhci_urb_enqueue returns -EINVAL in the very beginning. [commit message and header edit -Mathias] Fixes: 203a86613fb3 ("xhci: Avoid NULL pointer deref when host dies.") Cc: stable@vger.kernel.org Signed-off-by: Hongyu Xie Signed-off-by: Mathias Nyman --- drivers/usb/host/xhci.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c index 04ec2de158bf..2d378543bc3a 100644 --- a/drivers/usb/host/xhci.c +++ b/drivers/usb/host/xhci.c @@ -1611,9 +1611,12 @@ static int xhci_urb_enqueue(struct usb_hcd *hcd, struct urb *urb, gfp_t mem_flag struct urb_priv *urb_priv; int num_tds; - if (!urb || xhci_check_args(hcd, urb->dev, urb->ep, - true, true, __func__) <= 0) + if (!urb) return -EINVAL; + ret = xhci_check_args(hcd, urb->dev, urb->ep, + true, true, __func__); + if (ret <= 0) + return ret ? ret : -EINVAL; slot_id = urb->dev->slot_id; ep_index = xhci_get_endpoint_index(&urb->ep->desc); @@ -3330,7 +3333,7 @@ static int xhci_check_streams_endpoint(struct xhci_hcd *xhci, return -EINVAL; ret = xhci_check_args(xhci_to_hcd(xhci), udev, ep, 1, true, __func__); if (ret <= 0) - return -EINVAL; + return ret ? ret : -EINVAL; if (usb_ss_max_streams(&ep->ss_ep_comp) == 0) { xhci_warn(xhci, "WARN: SuperSpeed Endpoint Companion" " descriptor for ep 0x%x does not support streams\n",