From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:33888) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T7S4G-0004D3-Pj for qemu-devel@nongnu.org; Fri, 31 Aug 2012 10:19:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1T7S4F-0000Qt-AR for qemu-devel@nongnu.org; Fri, 31 Aug 2012 10:19:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:21904) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1T7S4F-0000QF-2K for qemu-devel@nongnu.org; Fri, 31 Aug 2012 10:19:27 -0400 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 q7VEJQNm018637 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 31 Aug 2012 10:19:26 -0400 From: Gerd Hoffmann Date: Fri, 31 Aug 2012 16:19:19 +0200 Message-Id: <1346422762-15877-9-git-send-email-kraxel@redhat.com> In-Reply-To: <1346422762-15877-1-git-send-email-kraxel@redhat.com> References: <1346422762-15877-1-git-send-email-kraxel@redhat.com> Subject: [Qemu-devel] [PATCH for-1.2 08/11] ehci: add ehci_cancel_queue() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Gerd Hoffmann Factor out function to cancel all packets of a queue. No behavior change. Signed-off-by: Gerd Hoffmann --- hw/usb/hcd-ehci.c | 30 ++++++++++++++++++++---------- 1 files changed, 20 insertions(+), 10 deletions(-) diff --git a/hw/usb/hcd-ehci.c b/hw/usb/hcd-ehci.c index b6169ce..30e5e8f 100644 --- a/hw/usb/hcd-ehci.c +++ b/hw/usb/hcd-ehci.c @@ -766,15 +766,27 @@ static EHCIQueue *ehci_alloc_queue(EHCIState *ehci, uint32_t addr, int async) return q; } +static void ehci_cancel_queue(EHCIQueue *q) +{ + EHCIPacket *p; + + p = QTAILQ_FIRST(&q->packets); + if (p == NULL) { + return; + } + + trace_usb_ehci_queue_action(q, "cancel"); + do { + ehci_free_packet(p); + } while ((p = QTAILQ_FIRST(&q->packets)) != NULL); +} + static void ehci_free_queue(EHCIQueue *q) { EHCIQueueHead *head = q->async ? &q->ehci->aqueues : &q->ehci->pqueues; - EHCIPacket *p; trace_usb_ehci_queue_action(q, "free"); - while ((p = QTAILQ_FIRST(&q->packets)) != NULL) { - ehci_free_packet(p); - } + ehci_cancel_queue(q); QTAILQ_REMOVE(head, q, next); g_free(q); } @@ -1796,9 +1808,7 @@ static EHCIQueue *ehci_state_fetchqh(EHCIState *ehci, int async) if (q->dev != NULL && q->dev->addr != devaddr) { if (!QTAILQ_EMPTY(&q->packets)) { /* should not happen (guest bug) */ - while ((p = QTAILQ_FIRST(&q->packets)) != NULL) { - ehci_free_packet(p); - } + ehci_cancel_queue(q); } q->dev = NULL; } @@ -1959,10 +1969,10 @@ static int ehci_state_fetchqtd(EHCIQueue *q) ehci_trace_qtd(q, NLPTR_GET(q->qtdaddr), &qtd); p = QTAILQ_FIRST(&q->packets); - while (p != NULL && p->qtdaddr != q->qtdaddr) { + if (p != NULL && p->qtdaddr != q->qtdaddr) { /* should not happen (guest bug) */ - ehci_free_packet(p); - p = QTAILQ_FIRST(&q->packets); + ehci_cancel_queue(q); + p = NULL; } if (p != NULL) { ehci_qh_do_overlay(q); -- 1.7.1