qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH v3 07/16] vhost-user: start and end the va_list


From: marcandre . lureau
Subject: [Qemu-devel] [PATCH v3 07/16] vhost-user: start and end the va_list
Date: Thu, 6 Aug 2015 14:40:43 +0200

From: Marc-André Lureau <address@hidden>

Use a common start and exit branch to open and cleanup the va_list.

Signed-off-by: Marc-André Lureau <address@hidden>
---
 hw/virtio/vhost-user.c | 32 ++++++++++++++++++++------------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c
index 8b6d7e7..21ecbcd 100644
--- a/hw/virtio/vhost-user.c
+++ b/hw/virtio/vhost-user.c
@@ -198,11 +198,13 @@ static int vhost_user_call(struct vhost_dev *dev,
     struct vhost_vring_file *file = 0;
     int need_reply = 0;
     int fds[VHOST_MEMORY_MAX_NREGIONS];
-    int i, fd;
+    int i, fd, ret = 0;
     size_t fd_num = 0;
+    va_list ap;
 
     assert(dev->vhost_ops->backend_type == VHOST_BACKEND_TYPE_USER);
 
+    va_start(ap, arg);
     msg_request = vhost_user_request_translate(request);
     msg.request = msg_request;
     msg.flags = VHOST_USER_VERSION;
@@ -247,7 +249,8 @@ static int vhost_user_call(struct vhost_dev *dev,
         if (!fd_num) {
             error_report("Failed initializing vhost-user memory map, "
                     "consider using -object memory-backend-file share=on");
-            return -1;
+            ret = -1;
+            goto end;
         }
 
         msg.size = sizeof(m.memory.nregions);
@@ -291,48 +294,53 @@ static int vhost_user_call(struct vhost_dev *dev,
         break;
     default:
         error_report("vhost-user trying to send unhandled ioctl");
-        return -1;
-        break;
+        ret = -1;
+        goto end;
     }
 
     if (vhost_user_write(dev, &msg, fds, fd_num) < 0) {
-        return 0;
+        goto end;
     }
 
     if (need_reply) {
         if (vhost_user_read(dev, &msg) < 0) {
-            return 0;
+            goto end;
         }
 
         if (msg_request != msg.request) {
             error_report("Received unexpected msg type."
                     " Expected %d received %d", msg_request, msg.request);
-            return -1;
+            ret = -1;
+            goto end;
         }
 
         switch (msg_request) {
         case VHOST_USER_GET_FEATURES:
             if (msg.size != sizeof(m.u64)) {
                 error_report("Received bad msg size.");
-                return -1;
+                ret = -1;
+                goto end;
             }
             *((__u64 *) arg) = msg.u64;
             break;
         case VHOST_USER_GET_VRING_BASE:
             if (msg.size != sizeof(m.state)) {
                 error_report("Received bad msg size.");
-                return -1;
+                ret = -1;
+                goto end;
             }
             memcpy(arg, &msg.state, sizeof(struct vhost_vring_state));
             break;
         default:
             error_report("Received unexpected msg type.");
-            return -1;
-            break;
+            ret = -1;
+            goto end;
         }
     }
 
-    return 0;
+end:
+    va_end(ap);
+    return ret;
 }
 
 static int vhost_user_init(struct vhost_dev *dev, void *opaque)
-- 
2.4.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]