From patchwork Mon Jan 14 11:50:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerd Hoffmann X-Patchwork-Id: 211772 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id BA0E02C00A2 for ; Mon, 14 Jan 2013 22:51:36 +1100 (EST) Received: from localhost ([::1]:57416 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TuiZi-00023K-2k for incoming@patchwork.ozlabs.org; Mon, 14 Jan 2013 06:51:34 -0500 Received: from eggs.gnu.org ([208.118.235.92]:38477) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TuiYy-0000Go-Ft for qemu-devel@nongnu.org; Mon, 14 Jan 2013 06:50:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TuiYq-0004Dx-JQ for qemu-devel@nongnu.org; Mon, 14 Jan 2013 06:50:48 -0500 Received: from mx1.redhat.com ([209.132.183.28]:25330) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TuiYq-0004Dl-Bn for qemu-devel@nongnu.org; Mon, 14 Jan 2013 06:50:40 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r0EBodlQ022254 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 14 Jan 2013 06:50:39 -0500 Received: from rincewind.home.kraxel.org (ovpn-116-52.ams2.redhat.com [10.36.116.52]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r0EBoJ6p030854; Mon, 14 Jan 2013 06:50:29 -0500 Received: by rincewind.home.kraxel.org (Postfix, from userid 500) id 6953B40BB3; Mon, 14 Jan 2013 12:50:19 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Mon, 14 Jan 2013 12:50:14 +0100 Message-Id: <1358164219-14070-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1358164219-14070-1-git-send-email-kraxel@redhat.com> References: <1358164219-14070-1-git-send-email-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Gerd Hoffmann Subject: [Qemu-devel] [PATCH 1/6] xhci: create xhci_detach_slot helper function X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-xhci.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 92f2eee..3ff8bc1 100644 --- a/hw/usb/hcd-xhci.c +++ b/hw/usb/hcd-xhci.c @@ -2198,6 +2198,23 @@ static unsigned int xhci_get_slot(XHCIState *xhci, XHCIEvent *event, XHCITRB *tr return slotid; } +/* cleanup slot state on usb device detach */ +static void xhci_detach_slot(XHCIState *xhci, USBPort *uport) +{ + int slot; + + for (slot = 0; slot < xhci->numslots; slot++) { + if (xhci->slots[slot].uport == uport) { + break; + } + } + if (slot == xhci->numslots) { + return; + } + + xhci->slots[slot].uport = NULL; +} + static TRBCCode xhci_get_port_bandwidth(XHCIState *xhci, uint64_t pctx) { dma_addr_t ctx; @@ -2971,13 +2988,8 @@ static void xhci_child_detach(USBPort *uport, USBDevice *child) { USBBus *bus = usb_bus_from_device(child); XHCIState *xhci = container_of(bus, XHCIState, bus); - int i; - for (i = 0; i < xhci->numslots; i++) { - if (xhci->slots[i].uport == uport) { - xhci->slots[i].uport = NULL; - } - } + xhci_detach_slot(xhci, uport); } static USBPortOps xhci_uport_ops = {