From patchwork Wed Feb 6 13:36:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Merwick X-Patchwork-Id: 10799409 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 758F917FB 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 6104929EE5 for ; Wed, 6 Feb 2019 13:38:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5411729E24; 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 E499A29449 for ; Wed, 6 Feb 2019 13:38:51 +0000 (UTC) Received: from localhost ([127.0.0.1]:51099 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grNPf-000531-47 for patchwork-qemu-devel@patchwork.kernel.org; Wed, 06 Feb 2019 08:38:51 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58591) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1grNOB-000512-PM for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:20 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1grNO4-0003lG-Rx for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:19 -0500 Received: from userp2130.oracle.com ([156.151.31.86]:56592) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1grNO4-0003kY-IK for qemu-devel@nongnu.org; Wed, 06 Feb 2019 08:37:12 -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 x16DTd3B151284; Wed, 6 Feb 2019 13:37:09 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id; s=corp-2018-07-02; bh=U4FM1TqfRjtFkbqhGigVstTBtsoYQSOKaWOF1nqHIbE=; b=ZZK9db0tT7V0dlQFhhj9kfyJ0j62NiWlv4WYRiOh88j368psBHe2KDrzk1TkalTLe3EZ 5/DtjpWC2wr1WxBOyzFUIb8v/6VKY5Izf39x99PQImGjptIPywtyP+7og8fXzTcH9duA KIInT07GEBJjKGKqDfFyh6CxExJBJcEJe0u8gFSUXBc8KYxXRdNy8S7Z/+145VOAF6mI O4K6/THufJGAflMksPduBYUqWAfxGRNM0Y2agUNZxZMAJJxZDa0D8eM+7orLcsn8PK1C YvZXu6HDIEBGlZcJVqY8gSsGu61qICMywSjUmpqXSo0vJB0aNksGcO3TcaLn7FXD6IK4 Lw== Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp2130.oracle.com with ESMTP id 2qd9argynp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 06 Feb 2019 13:37:09 +0000 Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id x16Db8PE025223 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 6 Feb 2019 13:37:09 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 x16Db8MF010135; Wed, 6 Feb 2019 13:37:08 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:07 -0800 From: Liam Merwick To: kraxel@redhat.com, qemu-devel@nongnu.org Date: Wed, 6 Feb 2019 13:36:47 +0000 Message-Id: <1549460216-25808-1-git-send-email-liam.merwick@oracle.com> X-Mailer: git-send-email 1.8.3.1 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=816 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 0/9] Dealing with Null devices in 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 This series is in response to feedback from Gerd Hoffman (below) on <1548859022-3969-1-git-send-email-liam.merwick@oracle.com> Instead of checking if usb_ep_get() returns NULL, ensure it never is passed a NULL device. === The usb device emulation (hw/usb/dev-*.c) never ever calls usb_ep_get() with dev == NULL. There are some places in usb host adapter emulation (hw/usb/hcd-*) which might do this. uhci for example has this ... [ ... ] USBDevice *dev = uhci_find_device(s, (td->token >> 8) & 0x7f); USBEndpoint *ep = usb_ep_get(dev, pid, (td->token >> 15) & 0xf); if (ep == NULL) { [ ... ] ... and uhci_find_device can return NULL. So, I'd suggest to check all usb_ep_get() callers, fix them if needed, then remove the 'if (dev== NULL)' check in usb_ep_get() and add the assert() instead. === Passes QEMU 'make check' and kvm-unit-tests Liam Merwick (9): usb: rearrange usb_ep_get() xhci: add asserts to help with static code analysis xhci: check device is not NULL before calling usb_ep_get() ehci: check device is not NULL before calling usb_ep_get() ohci: check device is not NULL before calling usb_ep_get() uhci: check device is not NULL before calling usb_ep_get() usb: check device is not NULL before calling usb_ep_get() usb: add device checks before redirector calls to usb_ep_get() usb: remove unnecessary NULL device check from usb_ep_get() hw/usb/core.c | 6 ++---- hw/usb/hcd-ehci.c | 7 +++++-- hw/usb/hcd-musb.c | 8 ++++---- hw/usb/hcd-ohci.c | 8 ++++++++ hw/usb/hcd-uhci.c | 8 +++++--- hw/usb/hcd-xhci.c | 6 ++++-- hw/usb/redirect.c | 3 ++- 7 files changed, 30 insertions(+), 16 deletions(-)