From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:46060) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsZ2p-000786-8Q for qemu-devel@nongnu.org; Tue, 08 Jan 2013 08:16:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TsZ2n-00039X-GA for qemu-devel@nongnu.org; Tue, 08 Jan 2013 08:16:43 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38465) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TsZ2n-00039F-9H for qemu-devel@nongnu.org; Tue, 08 Jan 2013 08:16:41 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r08DGeuF006216 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 8 Jan 2013 08:16:40 -0500 From: Gerd Hoffmann Date: Tue, 8 Jan 2013 14:16:37 +0100 Message-Id: <1357650999-17219-2-git-send-email-kraxel@redhat.com> In-Reply-To: <1357650999-17219-1-git-send-email-kraxel@redhat.com> References: <1357650999-17219-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH 1/3] xhci: create xhci_detach_slot helper function List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-xhci.c | 24 ++++++++++++++++++------ 1 files changed, 18 insertions(+), 6 deletions(-) diff --git a/hw/usb/hcd-xhci.c b/hw/usb/hcd-xhci.c index 9132920..5d4d876 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 = { -- 1.7.1