dcavalca / rpms / qemu

Forked from rpms/qemu 11 months ago
Clone

Blame 0025-spice-vmc-two-bugfixes-in-vmc_read.patch

Justin M. Forbes a81953
From c8fa37e075cf59e8b21af9211f6a6348c92ed098 Mon Sep 17 00:00:00 2001
Justin M. Forbes a81953
From: Alon Levy <alevy@redhat.com>
Justin M. Forbes a81953
Date: Mon, 12 Jul 2010 22:48:59 +0300
Justin M. Forbes a81953
Subject: [PATCH 25/39] spice-vmc: two bugfixes in vmc_read
Justin M. Forbes a81953
Justin M. Forbes a81953
 * throttling with no discard means possible recursion, make
Justin M. Forbes a81953
  vmc_read handle that.
Justin M. Forbes a81953
 * zero datapos when data is done (from rhel6 version)
Justin M. Forbes a81953
---
Justin M. Forbes a81953
 hw/spice-vmc.c |   13 ++++++++-----
Justin M. Forbes a81953
 1 files changed, 8 insertions(+), 5 deletions(-)
Justin M. Forbes a81953
Justin M. Forbes a81953
diff --git a/hw/spice-vmc.c b/hw/spice-vmc.c
Justin M. Forbes a81953
index 3f6a2bb..06e30e6 100644
Justin M. Forbes a81953
--- a/hw/spice-vmc.c
Justin M. Forbes a81953
+++ b/hw/spice-vmc.c
Justin M. Forbes a81953
@@ -45,7 +45,7 @@ static int vmc_write(SpiceVDIPortInstance *sin, const uint8_t *buf, int len)
Justin M. Forbes a81953
     ssize_t out;
Justin M. Forbes a81953
Justin M. Forbes a81953
     out = virtio_serial_write(&svc->port, buf, len);
Justin M. Forbes a81953
-    dprintf(svc, 2, "%s: %lu/%d\n", __func__, out, len);
Justin M. Forbes a81953
+    dprintf(svc, 3, "%s: %lu/%d\n", __func__, out, len);
Justin M. Forbes a81953
     return out;
Justin M. Forbes a81953
 }
Justin M. Forbes a81953
Justin M. Forbes a81953
@@ -54,13 +54,16 @@ static int vmc_read(SpiceVDIPortInstance *sin, uint8_t *buf, int len)
Justin M. Forbes a81953
     SpiceVirtualChannel *svc = container_of(sin, SpiceVirtualChannel, sin);
Justin M. Forbes a81953
     int bytes = MIN(len, svc->datalen);
Justin M. Forbes a81953
Justin M. Forbes a81953
-    dprintf(svc, 2, "%s: %d/%zd\n", __func__, bytes, svc->datalen);
Justin M. Forbes a81953
-    if (bytes) {
Justin M. Forbes a81953
+    dprintf(svc, 2, "%s: %p %d/%d/%zd\n", __func__, svc->datapos, len, bytes, svc->datalen);
Justin M. Forbes a81953
+    if (bytes > 0) {
Justin M. Forbes a81953
         memcpy(buf, svc->datapos, bytes);
Justin M. Forbes a81953
         svc->datapos += bytes;
Justin M. Forbes a81953
         svc->datalen -= bytes;
Justin M. Forbes a81953
-        if (0 == svc->datalen) {
Justin M. Forbes a81953
+        assert(svc->datalen >= 0);
Justin M. Forbes a81953
+        if (svc->datalen == 0) {
Justin M. Forbes a81953
+            svc->datapos = 0;
Justin M. Forbes a81953
             virtio_serial_throttle_port(&svc->port, false);
Justin M. Forbes a81953
+            // ^^^ !!! may call vmc_have_data, so don't touch svc after it!
Justin M. Forbes a81953
         }
Justin M. Forbes a81953
     }
Justin M. Forbes a81953
     return bytes;
Justin M. Forbes a81953
@@ -140,7 +143,7 @@ static void vmc_have_data(VirtIOSerialPort *port, const uint8_t *buf, size_t len
Justin M. Forbes a81953
     SpiceVirtualChannel *svc = DO_UPCAST(SpiceVirtualChannel, port, port);
Justin M. Forbes a81953
Justin M. Forbes a81953
     dprintf(svc, 2, "%s: %zd\n", __func__, len);
Justin M. Forbes a81953
-    assert(svc->datapos == 0);
Justin M. Forbes a81953
+    assert(svc->datalen == 0);
Justin M. Forbes a81953
     if (svc->bufsize < len) {
Justin M. Forbes a81953
         svc->bufsize = len;
Justin M. Forbes a81953
         svc->buffer = qemu_realloc(svc->buffer, svc->bufsize);
Justin M. Forbes a81953
-- 
Justin M. Forbes a81953
1.7.2.3
Justin M. Forbes a81953