From patchwork Wed Jan 30 14:37:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Merwick X-Patchwork-Id: 10788713 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3CF0C6C2 for ; Wed, 30 Jan 2019 14:40:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2AF822EDCE for ; Wed, 30 Jan 2019 14:40:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1CFC02EDE1; Wed, 30 Jan 2019 14:40:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BC62D2EDCE for ; Wed, 30 Jan 2019 14:40:06 +0000 (UTC) Received: from localhost ([127.0.0.1]:39210 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gor26-0007pP-3r for patchwork-qemu-devel@patchwork.kernel.org; Wed, 30 Jan 2019 09:40:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58005) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gor0w-0006sN-UN for qemu-devel@nongnu.org; Wed, 30 Jan 2019 09:38:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gor0w-0001Je-5z for qemu-devel@nongnu.org; Wed, 30 Jan 2019 09:38:54 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:45582) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gor0v-0001J2-Tw for qemu-devel@nongnu.org; Wed, 30 Jan 2019 09:38:54 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id x0UETU2G036052; Wed, 30 Jan 2019 14:38:52 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=corp-2018-07-02; bh=5U/VMXy7hiNMt0QnqXzwUgw9ySoY7uF5DnqOMSQG4cY=; b=3IwVjd9F+ID3Qw7l6+tcfhR1XzbatllwcScxyJDGraA9iZa83UrNS4TEQWauG/jg2ey2 9vEqK/v19Yw6qzoJ/mx3mmNLpHXEt+HFYpFpzyhqXcahQQjCpOGrALGScn5UM513a/DB ci4WcAiT9dj9+P+fQKp3GFXsppwduFRWRbYRt/l9hQ+b7c54xpE3WjX+Tgx+g2ra6J+j RqKKVtTfHLMwA6YFvs0jwbD7C/lBwkQxeKBFqDWAnR0tovI4LONqrju/+62EfRsMXTZt U6lzDsZtmlxN1p1QR3+kquxsqLsyPiu+ZyaYSvf7vzLsqcwr0pNsO7Xk3jTp4mmCpGPR zQ== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by aserp2130.oracle.com with ESMTP id 2q8d2eb4km-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Jan 2019 14:38:52 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x0UEco05025320 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Jan 2019 14:38:51 GMT Received: from abhmp0013.oracle.com (abhmp0013.oracle.com [141.146.116.19]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x0UEcowa021772; Wed, 30 Jan 2019 14:38:50 GMT Received: from ol7.nl.oracle.com (/10.175.63.178) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 30 Jan 2019 06:38:50 -0800 From: Liam Merwick To: kraxel@redhat.com, qemu-devel@nongnu.org Date: Wed, 30 Jan 2019 14:37:01 +0000 Message-Id: <1548859022-3969-2-git-send-email-liam.merwick@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1548859022-3969-1-git-send-email-liam.merwick@oracle.com> References: <1548859022-3969-1-git-send-email-liam.merwick@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9151 signatures=668682 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=921 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1901300115 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 Subject: [Qemu-devel] [PATCH 1/2] usb: rearrange usb_ep_get() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: ameya.more@oracle.com, Darren.Kenny@oracle.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP There is no need to calculate the 'eps' variable in usb_ep_get() if 'ep' is the control endpoint. Instead the calculation should be done after validating the input and the resulting pointer also validated before returning an entry indexed on the endpoint 'ep'. Signed-off-by: Liam Merwick Reviewed-by: Darren Kenny Reviewed-by: Mark Kanda Reviewed-by: Ameya More --- hw/usb/core.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/usb/core.c b/hw/usb/core.c index 241ae66b1505..1aa0051b2b2d 100644 --- a/hw/usb/core.c +++ b/hw/usb/core.c @@ -720,12 +720,13 @@ struct USBEndpoint *usb_ep_get(USBDevice *dev, int pid, int ep) if (dev == NULL) { return NULL; } - eps = (pid == USB_TOKEN_IN) ? dev->ep_in : dev->ep_out; if (ep == 0) { return &dev->ep_ctl; } assert(pid == USB_TOKEN_IN || pid == USB_TOKEN_OUT); assert(ep > 0 && ep <= USB_MAX_ENDPOINTS); + eps = (pid == USB_TOKEN_IN) ? dev->ep_in : dev->ep_out; + assert(eps != NULL); return eps + ep - 1; }