From patchwork Wed Feb 6 13:36:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Merwick X-Patchwork-Id: 10799407 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 29EFB746 for ; Wed, 6 Feb 2019 13:38:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15926297CF for ; Wed, 6 Feb 2019 13:38:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0440F295E5; Wed, 6 Feb 2019 13:38:52 +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 BFDBF2A8E3 for ; Wed, 6 Feb 2019 13:38:47 +0000 (UTC) Received: from localhost ([127.0.0.1]:51105 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grNPa-00068i-T6 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Feb 2019 08:38:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58577) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grNO9-00050T-JF for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grNO8-0003m3-Ti for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:17 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:56764) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grNO8-0003lm-LI for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:16 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x16DT0Au150716; Wed, 6 Feb 2019 13:37:15 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=D5Pgzct5jAQOq5pVf2BGEwiQEtgXEBqNu9FKbcbQBD0=; b=kaFcsQADo71mwtq0y0+LrO3JxKA/dx6s450A9THLmqLI8/Wpak+PCFUanLV9LiwTRhyD 5SGHQfntddsef7f8vP+ORSBqEj9ontLEw7f4F3LE61MG4JYD4NxfjpPx+Hu4kWmeiSlr zCmyXBt30N1XjeqfUF0ix2peF5PutwJrkBWVW3TjCrwL1Z9P4yHtvH3Xqqfkh7nPY+Ef IjbM5wb3zYYCzMI8V0NVRFyrhDAVMoY+H6DeyyfV6vaJapePSBLitOQ7XbEyJMRsygUt QbYcuimNHkPSTUDUyS46meZyKheKkKmwASdfYcSr/91x7lsyzsgUo9y5Ze3p0D+iExge wg== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2qd9argyps-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Feb 2019 13:37:15 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x16Db9su013189 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Feb 2019 13:37:10 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x16Db9lA010149; Wed, 6 Feb 2019 13:37:09 GMT Received: from ol7.nl.oracle.com (/10.175.12.46) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Feb 2019 05:37:09 -0800 From: Liam Merwick To: kraxel@redhat.com, qemu-devel@nongnu.org Date: Wed, 6 Feb 2019 13:36:48 +0000 Message-Id: <1549460216-25808-2-git-send-email-liam.merwick@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1549460216-25808-1-git-send-email-liam.merwick@oracle.com> References: <1549460216-25808-1-git-send-email-liam.merwick@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9158 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=909 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902060107 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [PATCH v2 1/9] 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: 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 before returning an entry indexed by the endpoint 'ep'. Signed-off-by: Liam Merwick Reviewed-by: Darren Kenny Reviewed-by: Mark Kanda Reviewed-by: Ameya More --- hw/usb/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/usb/core.c b/hw/usb/core.c index 241ae66b1505..bfb7ae67bbf0 100644 --- a/hw/usb/core.c +++ b/hw/usb/core.c @@ -720,12 +720,12 @@ 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; return eps + ep - 1; } From patchwork Wed Feb 6 13:36:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Merwick X-Patchwork-Id: 10799415 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 80EEA17FB for ; Wed, 6 Feb 2019 13:41:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 710882A964 for ; Wed, 6 Feb 2019 13:41:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6560D2AAB4; Wed, 6 Feb 2019 13:41:29 +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 16D682AAB9 for ; Wed, 6 Feb 2019 13:41:29 +0000 (UTC) Received: from localhost ([127.0.0.1]:51159 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grNSC-0008UR-AG for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Feb 2019 08:41:28 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58611) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grNOJ-00057I-FW for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:29 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grNOD-0003nJ-QV for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:25 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:56810) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grNOB-0003mb-Px for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:20 -0500 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x16DTd3C151284; Wed, 6 Feb 2019 13:37:17 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=1Vjx4RlbPgDrl6VCVQV1AXrD7AXK0eoz1KMa/bITw84=; b=0jUaQ1PjvTh4Sf0xzmrxJ2Gx1NKzEaGaiKFjFWtmx5IABukk+idTwDcPBUeIlGSJRVLt donk5hTH7Vx6CVmeMHg8/dSKcuxPmjFC7gyRF1ce5ED2NKZV+PlfMSnHuKDxuZ1tlfA/ X83BuDTowHL1D2X9zdLvLKY+IkcRS5h1ThJ9UgNwsMJ18ho6qP7Kq+DXGivVL6/fBH72 qk6qZ28ZQRFPDZRasBGdNJl1LROiip8PGqsGd7ETl/hZpqKPWpPOKnKtRXvBQAsSCNCf 0AmajCC3rXHztx1/QIEoMRGWasWOwz9uWYBZRk467KPbwSM4EWfeYBnFKWS7af6YSb8H yw== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2130.oracle.com with ESMTP id 2qd9argypv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Feb 2019 13:37:17 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x16DbB1n008913 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Feb 2019 13:37:11 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x16DbB51005882; Wed, 6 Feb 2019 13:37:11 GMT Received: from ol7.nl.oracle.com (/10.175.12.46) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Feb 2019 05:37:10 -0800 From: Liam Merwick To: kraxel@redhat.com, qemu-devel@nongnu.org Date: Wed, 6 Feb 2019 13:36:49 +0000 Message-Id: <1549460216-25808-3-git-send-email-liam.merwick@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1549460216-25808-1-git-send-email-liam.merwick@oracle.com> References: <1549460216-25808-1-git-send-email-liam.merwick@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9158 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=518 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902060107 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.86 Subject: [Qemu-devel] [PATCH v2 2/9] xhci: add asserts to help with static code analysis 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: 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 Most callers of xhci_port_update() and xhci_wakeup() pass in a pointer to an array entry and can never be NULL but add two defensive asserts to protect against future changes (e.g. adding a new port speed, etc.) adding a path through xhci_lookup_port() that could result in the return of a NULL XHCIPort. Signed-off-by: Liam Merwick --- hw/usb/hcd-xhci.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 19c64f7ff421..99b83aaa9ed5 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -2607,6 +2607,7 @@ static void xhci_port_update(XHCIPort *port, int is_detach) { uint32_t pls = PLS_RX_DETECT; + assert(port); port->portsc = PORTSC_PP; if (!is_detach && xhci_port_have_device(port)) { port->portsc |= PORTSC_CCS; @@ -3215,6 +3216,7 @@ static void xhci_wakeup(USBPort *usbport) XHCIState *xhci = usbport->opaque; XHCIPort *port = xhci_lookup_port(xhci, usbport); + assert(port); if (get_field(port->portsc, PORTSC_PLS) != PLS_U3) { return; } From patchwork Wed Feb 6 13:36:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Merwick X-Patchwork-Id: 10799411 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 2878C746 for ; Wed, 6 Feb 2019 13:39:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1502A2A241 for ; Wed, 6 Feb 2019 13:39:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 054082A24F; Wed, 6 Feb 2019 13:39:03 +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 AE4DA2A241 for ; Wed, 6 Feb 2019 13:39:02 +0000 (UTC) Received: from localhost ([127.0.0.1]:51109 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grNPp-0006Oy-Sz for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Feb 2019 08:39:02 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58624) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grNOL-00057b-Gr for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:30 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grNOI-0003nt-6P for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:27 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:36368) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grNOD-0003mm-Kn for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:23 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x16DSr1w155809; Wed, 6 Feb 2019 13:37:19 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=ebaw/Pj9ptXiUQzQm4QDhfz8TNTHjaIF5oSmli+E5bU=; b=cILW3WtSgSm7lp2sCOzD/JDLtoh4WAdNcPNGuTI/MTeDzn5FVdqXAG3fBFN/m1aSy4XW +pFaJ+A87T/Y/j5e9gDRIh7bjk2msstb3dNpjX77MsydP0PM4yZ/LxN01trYccZ9BZY0 QSkEf5oASahWaearPpcZqvvKmGyw2XO/e/0o189xqK6SUwUmT23Dm85CTvkqn2W5j3tB 1s2/gkqSLg9+JPTZhtpcqqwfO620ChRsIfbpj/klOkGqyd4vz+azsfTSq4DTDa6DXO5A ayybxciSsJDI7yvVjihH4kuHCsu1mgdpNDA3oDQwijDKx79frqyG6D003tBXzd4r05LV 4w== Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp2120.oracle.com with ESMTP id 2qd98n9067-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Feb 2019 13:37:19 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by aserv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x16DbCAL005427 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Feb 2019 13:37:13 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x16DbCKF015992; Wed, 6 Feb 2019 13:37:12 GMT Received: from ol7.nl.oracle.com (/10.175.12.46) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Feb 2019 05:37:11 -0800 From: Liam Merwick To: kraxel@redhat.com, qemu-devel@nongnu.org Date: Wed, 6 Feb 2019 13:36:50 +0000 Message-Id: <1549460216-25808-4-git-send-email-liam.merwick@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1549460216-25808-1-git-send-email-liam.merwick@oracle.com> References: <1549460216-25808-1-git-send-email-liam.merwick@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9158 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=817 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902060107 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [PATCH v2 3/9] xhci: check device is not NULL before calling 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: 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 Signed-off-by: Liam Merwick --- hw/usb/hcd-xhci.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 99b83aaa9ed5..ec28bee31963 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -3276,10 +3276,10 @@ static USBEndpoint *xhci_epid_to_usbep(XHCIEPContext *epctx) return NULL; } uport = epctx->xhci->slots[epctx->slotid - 1].uport; - token = (epctx->epid & 1) ? USB_TOKEN_IN : USB_TOKEN_OUT; - if (!uport) { + if (!uport || !uport->dev) { return NULL; } + token = (epctx->epid & 1) ? USB_TOKEN_IN : USB_TOKEN_OUT; return usb_ep_get(uport->dev, token, epctx->epid >> 1); } From patchwork Wed Feb 6 13:36:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Merwick X-Patchwork-Id: 10799413 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 AB123746 for ; Wed, 6 Feb 2019 13:41:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9BD312AAE7 for ; Wed, 6 Feb 2019 13:41:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 904D12AAED; Wed, 6 Feb 2019 13:41:28 +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 378A32AAE7 for ; Wed, 6 Feb 2019 13:41:28 +0000 (UTC) Received: from localhost ([127.0.0.1]:51149 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grNSB-0007Yl-G3 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Feb 2019 08:41:27 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58631) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grNOR-0005D9-Bv for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grNOJ-0003oH-Mr for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:30 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:50344) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grNOH-0003n3-AE for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:26 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x16DTPQD157955; Wed, 6 Feb 2019 13:37:20 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=929WhikmEFojGu7ULPe103/vR0zRRpTnzP2LC5DT2aI=; b=HzTkIU31/vIaaywr/uRJaVsLRyVXHR9n+tyshO46L/DaPIGN0m4nuZ24NNQ6ND9WTUFF 2C/9jzzcgfNeL2LWSqgL/vS8V0SeM7r4KMb67RQBsXrFO3oL7et6NsKHB6Ofa1TMD5a9 YL/uPIKhlQWsonN8eVEGPlQbF4nU1EaUJ/d1Qb206Gwk4qbmO7ctGnpUsw2bTqvAOf+0 lgvCQtFKMWMZidjR8vOkoOq95NRFWXFMjg/9aIvoOLCOXUOOgzJc5QBJAQEFDyMc4Ttr Sxu74DocSEi2V2MHlH/VmWBc+wfcP4BYMaeNJHEc7NiiHxqkTt3G2xHL99OzgZmjIN5p lw== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2130.oracle.com with ESMTP id 2qd97f0yxa-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Feb 2019 13:37:19 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x16DbEx5009004 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Feb 2019 13:37:14 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x16DbDJA005897; Wed, 6 Feb 2019 13:37:13 GMT Received: from ol7.nl.oracle.com (/10.175.12.46) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Feb 2019 05:37:13 -0800 From: Liam Merwick To: kraxel@redhat.com, qemu-devel@nongnu.org Date: Wed, 6 Feb 2019 13:36:51 +0000 Message-Id: <1549460216-25808-5-git-send-email-liam.merwick@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1549460216-25808-1-git-send-email-liam.merwick@oracle.com> References: <1549460216-25808-1-git-send-email-liam.merwick@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9158 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=948 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902060107 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 Subject: [Qemu-devel] [PATCH v2 4/9] ehci: check device is not NULL before calling 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: 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 In ehci_process_itd(), the call to ehci_find_device() can return NULL if it doesn't find a device matching 'devaddr' so explicitly check the return value before passing it to usb_ep_get(). Signed-off-by: Liam Merwick --- hw/usb/hcd-ehci.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c index 9b132cb0d392..62dab0592fa2 100644 --- a/hw/usb/hcd-ehci.c +++ b/hw/usb/hcd-ehci.c @@ -1439,9 +1439,12 @@ static int ehci_process_itd(EHCIState *ehci, qemu_sglist_add(&ehci->isgl, ptr1 + off, len); } - pid = dir ? USB_TOKEN_IN : USB_TOKEN_OUT; - dev = ehci_find_device(ehci, devaddr); + if (dev == NULL) { + ehci_trace_guest_bug(ehci, "no device found"); + return -1; + } + pid = dir ? USB_TOKEN_IN : USB_TOKEN_OUT; ep = usb_ep_get(dev, pid, endp); if (ep && ep->type == USB_ENDPOINT_XFER_ISOC) { usb_packet_setup(&ehci->ipacket, pid, ep, 0, addr, false, From patchwork Wed Feb 6 13:36:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Merwick X-Patchwork-Id: 10799405 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 286FE746 for ; Wed, 6 Feb 2019 13:38:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15C522A78E for ; Wed, 6 Feb 2019 13:38:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 07F8C2AA67; Wed, 6 Feb 2019 13:38:48 +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 A5A632A78E for ; Wed, 6 Feb 2019 13:38:47 +0000 (UTC) Received: from localhost ([127.0.0.1]:51103 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grNPa-00068T-IW for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Feb 2019 08:38:46 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58582) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grNO9-00050V-Up for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grNO9-0003mC-5x for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:17 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:36234) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grNO8-0003lu-U2 for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:17 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x16DT71e156253; Wed, 6 Feb 2019 13:37:15 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=o8ZZlli88zb2Sa8EglO/SMGjhk80TkIILafR3YqD6jY=; b=BLcTAmh1NcwDl0iCiXK1/AOl0PdR5iJ9U+XT970M0Ca+vJc1v9PxHYEUHR6ItAOO3mBX lU5U0X4VRZhQm4NWFI3RFXjGd4ZNNyOzR9KXmKEobvbYDrh/WFH9etBX5JoZcOyMdVaL r0l0jbSO1/rC3nkD7fsXdy1vBXMTnqmypQJpwvWTbEaRUZsI8si8R79ivO9r/zqrZZTM Z2yTt1UkDtoO1ozB05HbkHIfFvBxxTpNFJoHyj0Eve1DM9wi816L6aG0Ggo4JfQAwfIM zgMLPnPoy1lB+ZW/X8aIgRnzA0sapKJqq4LvBirlLT+RCmWab+6XLZMDie7zBfIVLaJ0 GQ== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2qd98n905p-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Feb 2019 13:37:15 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x16DbF5p013376 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Feb 2019 13:37:15 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x16DbFOe005904; Wed, 6 Feb 2019 13:37:15 GMT Received: from ol7.nl.oracle.com (/10.175.12.46) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Feb 2019 05:37:14 -0800 From: Liam Merwick To: kraxel@redhat.com, qemu-devel@nongnu.org Date: Wed, 6 Feb 2019 13:36:52 +0000 Message-Id: <1549460216-25808-6-git-send-email-liam.merwick@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1549460216-25808-1-git-send-email-liam.merwick@oracle.com> References: <1549460216-25808-1-git-send-email-liam.merwick@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9158 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=855 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902060107 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [PATCH v2 5/9] ohci: check device is not NULL before calling 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: 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 A call to ohci_find_device() can return NULL if it doesn't find a device matching 'addr' so for the two callers, explicitly check the return value before passing it to usb_ep_get(). Signed-off-by: Liam Merwick --- hw/usb/hcd-ohci.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hw/usb/hcd-ohci.c b/hw/usb/hcd-ohci.c index c34cf5b73a3a..196a9f72002d 100644 --- a/hw/usb/hcd-ohci.c +++ b/hw/usb/hcd-ohci.c @@ -848,6 +848,10 @@ static int ohci_service_iso_td(OHCIState *ohci, struct ohci_ed *ed, bool int_req = relative_frame_number == frame_count && OHCI_BM(iso_td.flags, TD_DI) == 0; dev = ohci_find_device(ohci, OHCI_BM(ed->flags, ED_FA)); + if (dev == NULL) { + trace_usb_ohci_td_dev_error(); + return 1; + } ep = usb_ep_get(dev, pid, OHCI_BM(ed->flags, ED_EN)); usb_packet_setup(&ohci->usb_packet, pid, ep, 0, addr, false, int_req); usb_packet_addbuf(&ohci->usb_packet, ohci->usb_buf, len); @@ -1071,6 +1075,10 @@ static int ohci_service_td(OHCIState *ohci, struct ohci_ed *ed) return 1; } dev = ohci_find_device(ohci, OHCI_BM(ed->flags, ED_FA)); + if (dev == NULL) { + trace_usb_ohci_td_dev_error(); + return 1; + } ep = usb_ep_get(dev, pid, OHCI_BM(ed->flags, ED_EN)); usb_packet_setup(&ohci->usb_packet, pid, ep, 0, addr, !flag_r, OHCI_BM(td.flags, TD_DI) == 0); From patchwork Wed Feb 6 13:36:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Merwick X-Patchwork-Id: 10799423 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 B1310746 for ; Wed, 6 Feb 2019 13:43:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A16672AA26 for ; Wed, 6 Feb 2019 13:43:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 94E332AA3E; Wed, 6 Feb 2019 13:43:48 +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 4A5BD2AA26 for ; Wed, 6 Feb 2019 13:43:48 +0000 (UTC) Received: from localhost ([127.0.0.1]:51174 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grNUR-00010g-Er for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Feb 2019 08:43:47 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58686) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grNOi-0005SO-Id for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grNOd-0003rL-8f for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:49 -0500 Received: from aserp2130.oracle.com ([141.146.126.79]:50384) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grNOZ-0003nP-FV for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:44 -0500 Received: from pps.filterd (aserp2130.oracle.com [127.0.0.1]) by aserp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x16DSwiv157719; Wed, 6 Feb 2019 13:37:21 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=+cOezIxr/acrXymAoip0fheaswuQKNRdBnFzaABHVCM=; b=Xsrv9eMu8yRWs+sO5DPXOGLADu4sZ4Ppe/V/1hgyGpszRQDUhoFLFNpHbnfnp0Wk7p8Z CUw6pCOTqmoI31jesMD57CaENv+S9Q1V54icjoMoHOGdZUuOYsvsM0419rjlGbC5x7iH gqdGtOGzyLwiAtP76SD6oHxjjxAfiZ1FvtvXw86boUgU0x1mM0nDcM6ZtD8LuUWbPztq 1lGtzwNiRNCOLx3ThSyzib0URjTxrlA0lH5mQk55EnjQOwTWQk5gs5QepfENjp4xwXjw I0k/WSO8sEzrUqztDE0mifLqZ8q6JZ4xXfix5NAdWVPMJUyVGb6D/aFkrGJ3BpisUWie 3A== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by aserp2130.oracle.com with ESMTP id 2qd97f0yxf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Feb 2019 13:37:21 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x16DbG9J009083 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Feb 2019 13:37:16 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x16DbGC0004675; Wed, 6 Feb 2019 13:37:16 GMT Received: from ol7.nl.oracle.com (/10.175.12.46) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Feb 2019 05:37:15 -0800 From: Liam Merwick To: kraxel@redhat.com, qemu-devel@nongnu.org Date: Wed, 6 Feb 2019 13:36:53 +0000 Message-Id: <1549460216-25808-7-git-send-email-liam.merwick@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1549460216-25808-1-git-send-email-liam.merwick@oracle.com> References: <1549460216-25808-1-git-send-email-liam.merwick@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9158 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=948 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902060107 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 141.146.126.79 Subject: [Qemu-devel] [PATCH v2 6/9] uhci: check device is not NULL before calling 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: 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 In uhci_handle_td(), the call to ehci_find_device() can return NULL if it doesn't find a device matching 'addr' so explicitly check the return value before passing it to usb_ep_get(). Signed-off-by: Liam Merwick --- hw/usb/hcd-uhci.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hw/usb/hcd-uhci.c b/hw/usb/hcd-uhci.c index e694b62086d3..09df29ff9c16 100644 --- a/hw/usb/hcd-uhci.c +++ b/hw/usb/hcd-uhci.c @@ -858,13 +858,15 @@ static int uhci_handle_td(UHCIState *s, UHCIQueue *q, uint32_t qh_addr, /* Allocate new packet */ if (q == NULL) { - USBDevice *dev = uhci_find_device(s, (td->token >> 8) & 0x7f); - USBEndpoint *ep = usb_ep_get(dev, pid, (td->token >> 15) & 0xf); + USBDevice *dev; + USBEndpoint *ep; - if (ep == NULL) { + dev = uhci_find_device(s, (td->token >> 8) & 0x7f); + if (dev == NULL) { return uhci_handle_td_error(s, td, td_addr, USB_RET_NODEV, int_mask); } + ep = usb_ep_get(dev, pid, (td->token >> 15) & 0xf); q = uhci_queue_new(s, qh_addr, td, ep); } async = uhci_async_alloc(q, td_addr); From patchwork Wed Feb 6 13:36:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Merwick X-Patchwork-Id: 10799421 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 32E5517FB for ; Wed, 6 Feb 2019 13:43:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 22D8A2AA26 for ; Wed, 6 Feb 2019 13:43:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 166282AA30; Wed, 6 Feb 2019 13:43:45 +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 3CD8E2A964 for ; Wed, 6 Feb 2019 13:43:44 +0000 (UTC) Received: from localhost ([127.0.0.1]:51170 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grNUN-0000xl-BI for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Feb 2019 08:43:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58687) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grNOi-0005SP-Im for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grNOd-0003rM-8c for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:49 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:36556) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grNOZ-0003nf-8X for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:44 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x16DSvs9155867; Wed, 6 Feb 2019 13:37:24 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=usqO3XwgA5gAFlG1R7udBZbzu/JePWdIEr/oU4ZH1GI=; b=5SYzcoG7GT3QJraJu3qhDeNmfIuoXkevmwWmgI9gSMrhiFumqKNbeoH+TaZZZZMMYGQA 032u526T4bFGuH1ndUNrxPmArbbZ0E6R0Tr0aHwmOu4zQ4KwD/1xVmAG9ymguvtBTocr i9Lo4f7Bfwe1AcpBMJMj1cmuSFJ7w2LHGRVtqVoupRof2dKI2iHv98hNt7hnSwtHCm7q vrtz7W1XoowtJd+j1BNoMnlT5oPLl1w8Y8jjSTLEiompn0uUp6mE1e1VfXK3W3DtXdt9 p+vUnQVDH02sR6s48mK5Oryq9tuJEkMgcx/hgSbdIy1DQzSqA4lfbiyyHcD0yJX0851X /A== Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp2120.oracle.com with ESMTP id 2qd98n907b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Feb 2019 13:37:24 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x16DbI7f009123 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Feb 2019 13:37:18 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id x16DbHDL005998; Wed, 6 Feb 2019 13:37:17 GMT Received: from ol7.nl.oracle.com (/10.175.12.46) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Feb 2019 05:37:17 -0800 From: Liam Merwick To: kraxel@redhat.com, qemu-devel@nongnu.org Date: Wed, 6 Feb 2019 13:36:54 +0000 Message-Id: <1549460216-25808-8-git-send-email-liam.merwick@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1549460216-25808-1-git-send-email-liam.merwick@oracle.com> References: <1549460216-25808-1-git-send-email-liam.merwick@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9158 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=937 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902060107 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [PATCH v2 7/9] usb: check device is not NULL before calling 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: 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 In musb_packet(), the call to usb_find_device() can return NULL if it doesn't find a device matching 'addr' so explicitly check the return value before passing it to usb_ep_get(). This then allows the subsequent calculation of 'id' to be streamlined. Signed-off-by: Liam Merwick --- hw/usb/hcd-musb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/usb/hcd-musb.c b/hw/usb/hcd-musb.c index d70a91a58ce2..85d779655498 100644 --- a/hw/usb/hcd-musb.c +++ b/hw/usb/hcd-musb.c @@ -628,11 +628,11 @@ static void musb_packet(MUSBState *s, MUSBEndPoint *ep, /* A wild guess on the FADDR semantics... */ dev = usb_find_device(&s->port, ep->faddr[idx]); - uep = usb_ep_get(dev, pid, ep->type[idx] & 0xf); - id = pid; - if (uep) { - id |= (dev->addr << 16) | (uep->nr << 8); + if (dev == NULL) { + return; } + uep = usb_ep_get(dev, pid, ep->type[idx] & 0xf); + id = pid | (dev->addr << 16) | (uep->nr << 8); usb_packet_setup(&ep->packey[dir].p, pid, uep, 0, id, false, true); usb_packet_addbuf(&ep->packey[dir].p, ep->buf[idx], len); ep->packey[dir].ep = ep; From patchwork Wed Feb 6 13:36:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Merwick X-Patchwork-Id: 10799417 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 E46471390 for ; Wed, 6 Feb 2019 13:41:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CFE502AA67 for ; Wed, 6 Feb 2019 13:41:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE6BB2AB07; Wed, 6 Feb 2019 13:41:34 +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 AAB3E2AAB4 for ; Wed, 6 Feb 2019 13:41:33 +0000 (UTC) Received: from localhost ([127.0.0.1]:51161 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grNSH-00006j-0S for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Feb 2019 08:41:33 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58651) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grNOY-0005Ju-AV for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grNOT-0003pc-Jf for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:41 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:36392) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grNOM-0003n1-2k for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:33 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x16DStZb155844; Wed, 6 Feb 2019 13:37:20 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=V0RYFo899M+FNTzloOapiTQH2u1qfsJZWH7cMZgmxIw=; b=bu/HjUKHGNjZ6qD2oCSnzPTFIODDZPx2qTizLOlEf4Iz5jEnSY4EArJsCbHR4a0rDVbJ pgPj/WaSP5x7LfYfQMn01DUQyHV84mkpArzavi0/5jKWIPBoezu055ZLW3WsJM/PU/Z/ bTskIVoee735uJp5B+I6S5JtpEcBA0BLyOZ4dn4vusB2GzSEEKzIR0tUhSzGkSMGtqGv wPqR4/JLSnm5nRb6zJGocpw31O5Gz3VtMqxoiWPDQPvKB7NjOxTaHly8hXLfQuq5auMB kKPTWOsUiifCH7nZ5Zw7+TbTIvWz7UxRhxA8c+e303LvzOziBBgomdIux8LhCYQNq/D+ WA== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2120.oracle.com with ESMTP id 2qd98n906j-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Feb 2019 13:37:19 +0000 Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id x16DbJtN013479 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Feb 2019 13:37:19 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x16DbJS5004697; Wed, 6 Feb 2019 13:37:19 GMT Received: from ol7.nl.oracle.com (/10.175.12.46) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Feb 2019 05:37:18 -0800 From: Liam Merwick To: kraxel@redhat.com, qemu-devel@nongnu.org Date: Wed, 6 Feb 2019 13:36:55 +0000 Message-Id: <1549460216-25808-9-git-send-email-liam.merwick@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1549460216-25808-1-git-send-email-liam.merwick@oracle.com> References: <1549460216-25808-1-git-send-email-liam.merwick@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9158 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=969 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902060107 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [PATCH v2 8/9] usb: add device checks before redirector calls to 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: 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 Add an assert and an explicit check before the two callers to usb_ep_get() in the USB redirector code to ensure the device passed in is not NULL. Signed-off-by: Liam Merwick --- hw/usb/redirect.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c index 18a42d19380e..7cb6b120d4f0 100644 --- a/hw/usb/redirect.c +++ b/hw/usb/redirect.c @@ -1728,6 +1728,7 @@ static void usbredir_ep_info(void *priv, USBRedirDevice *dev = priv; int i; + assert(dev != NULL); for (i = 0; i < MAX_ENDPOINTS; i++) { dev->endpoint[i].type = ep_info->type[i]; dev->endpoint[i].interval = ep_info->interval[i]; @@ -2125,7 +2126,7 @@ static int usbredir_post_load(void *priv, int version_id) { USBRedirDevice *dev = priv; - if (dev->parser == NULL) { + if (dev == NULL || dev->parser == NULL) { return 0; } From patchwork Wed Feb 6 13:36:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Merwick X-Patchwork-Id: 10799419 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 E9017746 for ; Wed, 6 Feb 2019 13:43:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CB07C2AA26 for ; Wed, 6 Feb 2019 13:43:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BC7A32AA47; Wed, 6 Feb 2019 13:43:44 +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 57BB82AA26 for ; Wed, 6 Feb 2019 13:43:44 +0000 (UTC) Received: from localhost ([127.0.0.1]:51168 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grNUN-0000xe-Ik for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Feb 2019 08:43:43 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58723) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grNOl-0005Uu-1w for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grNOg-0003sJ-97 for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:54 -0500 Received: from userp2120.oracle.com ([156.151.31.85]:36450) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grNOd-0003nD-9H for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:47 -0500 Received: from pps.filterd (userp2120.oracle.com [127.0.0.1]) by userp2120.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x16DTWuY156395; Wed, 6 Feb 2019 13:37:21 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=tE23AFN35BmibHukrgyis8lru1bp1Uague0Zfo9njVI=; b=QdphtUDhqO3i8FtMI+E0sTwDTU/Kj2YkV5Gn9r1DR2/HrpjN4LLpLTLbR9OY7t57PSfR ZhEimWC3BKXwnlmkZFJRV+Sdi0UZ5Jwd0knEE70zr1gJlib0iabAmAuNp3/m01ueOGAe oo6zqllVEhA5m0dEX7urkp+uOigXlFqwYZ3tKxMyqkkikdB7SevZYkm8O7r0BpVJyClr z3heXpbK14L9FZ1767C31qFFLziuxSWbjzZ61WLQy9/vJFyp7FVEYL+Xu8bP47stbmdJ PCv4LnetyhwPTu7rz3T74+Jk+3SvCi3mOZbDZosHgs7FXqVAcwZkXtShPZKmRjWUtXg9 Tg== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2120.oracle.com with ESMTP id 2qd98n906u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Feb 2019 13:37:20 +0000 Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x16DbK3p025697 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Feb 2019 13:37:20 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x16DbK4P016034; Wed, 6 Feb 2019 13:37:20 GMT Received: from ol7.nl.oracle.com (/10.175.12.46) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 06 Feb 2019 05:37:19 -0800 From: Liam Merwick To: kraxel@redhat.com, qemu-devel@nongnu.org Date: Wed, 6 Feb 2019 13:36:56 +0000 Message-Id: <1549460216-25808-10-git-send-email-liam.merwick@oracle.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1549460216-25808-1-git-send-email-liam.merwick@oracle.com> References: <1549460216-25808-1-git-send-email-liam.merwick@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=9158 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=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1810050000 definitions=main-1902060107 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] X-Received-From: 156.151.31.85 Subject: [Qemu-devel] [PATCH v2 9/9] usb: remove unnecessary NULL device check from 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: 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 No caller of usb_ep_get() calls it with a NULL device (previous commits have addressed the few remaining cases which didn't explicitly check). Replace check for 'dev == NULL' with an assert instead. Signed-off-by: Liam Merwick --- hw/usb/core.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/hw/usb/core.c b/hw/usb/core.c index bfb7ae67bbf0..8fbd9c7d573b 100644 --- a/hw/usb/core.c +++ b/hw/usb/core.c @@ -717,9 +717,7 @@ struct USBEndpoint *usb_ep_get(USBDevice *dev, int pid, int ep) { struct USBEndpoint *eps; - if (dev == NULL) { - return NULL; - } + assert(dev != NULL); if (ep == 0) { return &dev->ep_ctl; }