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; }