Received: by 10.223.185.116 with SMTP id b49csp1087151wrg; Fri, 23 Feb 2018 11:41:55 -0800 (PST) X-Google-Smtp-Source: AH8x2275ZMNEh5bBeh+SoAfiydfb9HueBHXEpTaBlT0fnewr26sIX6fySdyHqFGKLl0bVPGBI00P X-Received: by 2002:a17:902:1a4:: with SMTP id b33-v6mr2628803plb.321.1519414915552; Fri, 23 Feb 2018 11:41:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519414915; cv=none; d=google.com; s=arc-20160816; b=Gi2zvbbk53m5xYQTC+F/FCrSZozkt2Fe2oBif3jLkSmiTF+56jrsdjEkbV/dQWX5zu ItG5WhUocIlkew28bLejyj7oWXBU6q5mBfywQ6SCB+Aj4bfNPfRw31LrLrbsVnmODesp e9lzfEbHUVrE+8agO5Vd36blTOXn4JvujwpSz/Z3AmkbZGwRI3Rm64nl+ZzdrxdCZ6W2 06qrVpspOKZ/mhujDJkex49SHwlSybGl237rB7NCFJHf9i8M+RjU8hcJGeIt5h7SWrrN bNMjvd0KxIZGTQiEkZIvQ/95BsoOk9G1izut67ileWQ7y5lBE252BbluOKHbZUdgb5Vf PJxg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=rhwt239xBTQppNtvCDWml0TkhZAhVRCIfQW2br4lxxg=; b=ofvRdn9Kx76elnv0Z1hqkUi5FYKsgU1lTddBqqOAfa3kL7FP/V1PptfYwUrUMPzCVH ZKychco7nzVn8aTUuKs2QKOGD4tcAFefkIUe+JstoMmiwtZSAP3VfTF3V49F9/ugzFlA Zi9bAjZvDlR1TBy+B/QllGXpaKmtNfkYk6IUZ+xwE0cVHUdGUAPrcANkLq9H95GfISrU VTv1ASmoTDSGap41Lblqhr7rv03k0OZ0fNlxPjXP70Uqv87Ry/Cch1hi4pYANsTy7MJj ICCstL0djoHAR1QAnyAEoBzyYXH7m7C/1TRvC57irzCJUBMEHoDSSmsdmW9g8yKPSd7I EGYQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z7si2277040pfg.51.2018.02.23.11.41.41; Fri, 23 Feb 2018 11:41:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933900AbeBWTkl (ORCPT + 99 others); Fri, 23 Feb 2018 14:40:41 -0500 Received: from mail.linuxfoundation.org ([140.211.169.12]:45244 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934513AbeBWStV (ORCPT ); Fri, 23 Feb 2018 13:49:21 -0500 Received: from localhost (LFbn-1-12258-90.w90-92.abo.wanadoo.fr [90.92.71.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 44FF81180; Fri, 23 Feb 2018 18:49:20 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrey Konovalov , Takashi Iwai Subject: [PATCH 4.14 001/159] usb: core: Add a helper function to check the validity of EP type in URB Date: Fri, 23 Feb 2018 19:25:09 +0100 Message-Id: <20180223170743.256398104@linuxfoundation.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180223170743.086611315@linuxfoundation.org> References: <20180223170743.086611315@linuxfoundation.org> User-Agent: quilt/0.65 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Takashi Iwai commit e901b9873876ca30a09253731bd3a6b00c44b5b0 upstream. This patch adds a new helper function to perform a sanity check of the given URB to see whether it contains a valid endpoint. It's a light- weight version of what usb_submit_urb() does, but without the kernel warning followed by the stack trace, just returns an error code. Especially for a driver that doesn't parse the descriptor but fills the URB with the fixed endpoint (e.g. some quirks for non-compliant devices), this kind of check is preferable at the probe phase before actually submitting the urb. Tested-by: Andrey Konovalov Acked-by: Greg Kroah-Hartman Signed-off-by: Takashi Iwai Signed-off-by: Greg Kroah-Hartman --- drivers/usb/core/urb.c | 30 ++++++++++++++++++++++++++---- include/linux/usb.h | 2 ++ 2 files changed, 28 insertions(+), 4 deletions(-) --- a/drivers/usb/core/urb.c +++ b/drivers/usb/core/urb.c @@ -187,6 +187,31 @@ EXPORT_SYMBOL_GPL(usb_unanchor_urb); /*-------------------------------------------------------------------*/ +static const int pipetypes[4] = { + PIPE_CONTROL, PIPE_ISOCHRONOUS, PIPE_BULK, PIPE_INTERRUPT +}; + +/** + * usb_urb_ep_type_check - sanity check of endpoint in the given urb + * @urb: urb to be checked + * + * This performs a light-weight sanity check for the endpoint in the + * given urb. It returns 0 if the urb contains a valid endpoint, otherwise + * a negative error code. + */ +int usb_urb_ep_type_check(const struct urb *urb) +{ + const struct usb_host_endpoint *ep; + + ep = usb_pipe_endpoint(urb->dev, urb->pipe); + if (!ep) + return -EINVAL; + if (usb_pipetype(urb->pipe) != pipetypes[usb_endpoint_type(&ep->desc)]) + return -EINVAL; + return 0; +} +EXPORT_SYMBOL_GPL(usb_urb_ep_type_check); + /** * usb_submit_urb - issue an asynchronous transfer request for an endpoint * @urb: pointer to the urb describing the request @@ -326,9 +351,6 @@ EXPORT_SYMBOL_GPL(usb_unanchor_urb); */ int usb_submit_urb(struct urb *urb, gfp_t mem_flags) { - static int pipetypes[4] = { - PIPE_CONTROL, PIPE_ISOCHRONOUS, PIPE_BULK, PIPE_INTERRUPT - }; int xfertype, max; struct usb_device *dev; struct usb_host_endpoint *ep; @@ -444,7 +466,7 @@ int usb_submit_urb(struct urb *urb, gfp_ */ /* Check that the pipe's type matches the endpoint's type */ - if (usb_pipetype(urb->pipe) != pipetypes[xfertype]) + if (usb_urb_ep_type_check(urb)) dev_WARN(&dev->dev, "BOGUS urb xfer, pipe %x != type %x\n", usb_pipetype(urb->pipe), pipetypes[xfertype]); --- a/include/linux/usb.h +++ b/include/linux/usb.h @@ -1729,6 +1729,8 @@ static inline int usb_urb_dir_out(struct return (urb->transfer_flags & URB_DIR_MASK) == URB_DIR_OUT; } +int usb_urb_ep_type_check(const struct urb *urb); + void *usb_alloc_coherent(struct usb_device *dev, size_t size, gfp_t mem_flags, dma_addr_t *dma); void usb_free_coherent(struct usb_device *dev, size_t size,