<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">From 2844d8a699952c3d48d6c3a5d957b629d42f8482 Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann &lt;kraxel@redhat.com&gt;
Date: Thu, 23 Jun 2011 12:41:40 -0300
Subject: [RHEL6 qemu-kvm PATCH 065/115] uhci: switch to QTAILQ (cherry picked from commit ddf6583f88e29b2ec47fa81010c80868bfff7c83)

RH-Author: Gerd Hoffmann &lt;kraxel@redhat.com&gt;
Message-id: &lt;1308832951-8995-65-git-send-email-kraxel@redhat.com&gt;
Patchwork-id: 28390
O-Subject: [RHEL-6.2 kvm PATCH 064/115] uhci: switch to QTAILQ (cherry picked from commit ddf6583f88e29b2ec47fa81010c80868bfff7c83)
Bugzilla: 561414 632299 645351 711354
RH-Acked-by: Hans de Goede &lt;hdegoede@redhat.com&gt;
RH-Acked-by: Jes Sorensen &lt;Jes.Sorensen@redhat.com&gt;
RH-Acked-by: Paolo Bonzini &lt;pbonzini@redhat.com&gt;
RH-Acked-by: Kevin Wolf &lt;kwolf@redhat.com&gt;

Conflicts:

	hw/usb-uhci.c

Signed-off-by: Gerd Hoffmann &lt;kraxel@redhat.com&gt;
---
 hw/usb-uhci.c |   63 +++++++++++++-------------------------------------------
 1 files changed, 15 insertions(+), 48 deletions(-)

Signed-off-by: Eduardo Habkost &lt;ehabkost@redhat.com&gt;
---
 hw/usb-uhci.c |   63 +++++++++++++-------------------------------------------
 1 files changed, 15 insertions(+), 48 deletions(-)

diff --git a/hw/usb-uhci.c b/hw/usb-uhci.c
index 8767fd8..bf09c84 100644
--- a/hw/usb-uhci.c
+++ b/hw/usb-uhci.c
@@ -113,7 +113,7 @@ static void dump_data(const uint8_t *data, int len) {}
  */
 typedef struct UHCIAsync {
     USBPacket packet;
-    struct UHCIAsync *next;
+    QTAILQ_ENTRY(UHCIAsync) next;
     uint32_t  td;
     uint32_t  token;
     int8_t    valid;
@@ -143,8 +143,7 @@ typedef struct UHCIState {
     uint32_t pending_int_mask;
 
     /* Active packets */
-    UHCIAsync *async_pending;
-    UHCIAsync *async_pool;
+    QTAILQ_HEAD(,UHCIAsync) async_pending;
     uint8_t num_ports_vmstate;
 } UHCIState;
 
@@ -169,7 +168,6 @@ static UHCIAsync *uhci_async_alloc(UHCIState *s)
     async-&gt;td    = 0;
     async-&gt;token = 0;
     async-&gt;done  = 0;
-    async-&gt;next  = NULL;
 
     return async;
 }
@@ -181,24 +179,12 @@ static void uhci_async_free(UHCIState *s, UHCIAsync *async)
 
 static void uhci_async_link(UHCIState *s, UHCIAsync *async)
 {
-    async-&gt;next = s-&gt;async_pending;
-    s-&gt;async_pending = async;
+    QTAILQ_INSERT_HEAD(&amp;s-&gt;async_pending, async, next);
 }
 
 static void uhci_async_unlink(UHCIState *s, UHCIAsync *async)
 {
-    UHCIAsync *curr = s-&gt;async_pending;
-    UHCIAsync **prev = &amp;s-&gt;async_pending;
-
-    while (curr) {
-	if (curr == async) {
-            *prev = curr-&gt;next;
-            return;
-        }
-
-        prev = &amp;curr-&gt;next;
-        curr = curr-&gt;next;
-    }
+    QTAILQ_REMOVE(&amp;s-&gt;async_pending, async, next);
 }
 
 static void uhci_async_cancel(UHCIState *s, UHCIAsync *async)
@@ -217,11 +203,10 @@ static void uhci_async_cancel(UHCIState *s, UHCIAsync *async)
  */
 static UHCIAsync *uhci_async_validate_begin(UHCIState *s)
 {
-    UHCIAsync *async = s-&gt;async_pending;
+    UHCIAsync *async;
 
-    while (async) {
+    QTAILQ_FOREACH(async, &amp;s-&gt;async_pending, next) {
         async-&gt;valid--;
-        async = async-&gt;next;
     }
     return NULL;
 }
@@ -231,47 +216,30 @@ static UHCIAsync *uhci_async_validate_begin(UHCIState *s)
  */
 static void uhci_async_validate_end(UHCIState *s)
 {
-    UHCIAsync *curr = s-&gt;async_pending;
-    UHCIAsync **prev = &amp;s-&gt;async_pending;
-    UHCIAsync *next;
+    UHCIAsync *curr, *n;
 
-    while (curr) {
+    QTAILQ_FOREACH_SAFE(curr, &amp;s-&gt;async_pending, next, n) {
         if (curr-&gt;valid &gt; 0) {
-            prev = &amp;curr-&gt;next;
-            curr = curr-&gt;next;
             continue;
         }
-
-        next = curr-&gt;next;
-
-        /* Unlink */
-        *prev = next;
-
+        uhci_async_unlink(s, curr);
         uhci_async_cancel(s, curr);
-
-        curr = next;
     }
 }
 
 static void uhci_async_cancel_all(UHCIState *s)
 {
-    UHCIAsync *curr = s-&gt;async_pending;
-    UHCIAsync *next;
-
-    while (curr) {
-        next = curr-&gt;next;
+    UHCIAsync *curr, *n;
 
+    QTAILQ_FOREACH_SAFE(curr, &amp;s-&gt;async_pending, next, n) {
+        uhci_async_unlink(s, curr);
         uhci_async_cancel(s, curr);
-
-        curr = next;
     }
-
-    s-&gt;async_pending = NULL;
 }
 
 static UHCIAsync *uhci_async_find_td(UHCIState *s, uint32_t addr, uint32_t token)
 {
-    UHCIAsync *async = s-&gt;async_pending;
+    UHCIAsync *async;
     UHCIAsync *match = NULL;
     int count = 0;
 
@@ -288,7 +256,7 @@ static UHCIAsync *uhci_async_find_td(UHCIState *s, uint32_t addr, uint32_t token
      * If we ever do we'd want to optimize this algorithm.
      */
 
-    while (async) {
+    QTAILQ_FOREACH(async, &amp;s-&gt;async_pending, next) {
         if (async-&gt;token == token) {
             /* Good match */
             match = async;
@@ -298,8 +266,6 @@ static UHCIAsync *uhci_async_find_td(UHCIState *s, uint32_t addr, uint32_t token
                 break;
             }
         }
-
-        async = async-&gt;next;
         count++;
     }
 
@@ -1095,6 +1061,7 @@ static int usb_uhci_common_initfn(UHCIState *s)
     }
     s-&gt;frame_timer = qemu_new_timer(vm_clock, uhci_frame_timer, s);
     s-&gt;num_ports_vmstate = NB_PORTS;
+    QTAILQ_INIT(&amp;s-&gt;async_pending);
 
     qemu_register_reset(uhci_reset, s);
 
-- 
1.7.3.2

</pre></body></html>