Received: from eggs.gnu.org ([2001:4830:134:3::10]:46758) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZNKU0-0002Db-68 for qemu-devel@nongnu.org; Thu, 06 Aug 2015 08:41:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZNKTz-0008Oz-A7 for qemu-devel@nongnu.org; Thu, 06 Aug 2015 08:41:16 -0400 Received: from mail-qg0-x231.google.com ([2607:f8b0:400d:c04::231]:35790) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZNKTz-0008Ov-6W for qemu-devel@nongnu.org; Thu, 06 Aug 2015 08:41:15 -0400 Received: by qgj62 with SMTP id 62so26258753qgj.2 for ; Thu, 06 Aug 2015 05:41:14 -0700 (PDT) Sender: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= From: marcandre.lureau@redhat.com Date: Thu, 6 Aug 2015 14:40:43 +0200 Message-Id: <1438864852-4939-8-git-send-email-marcandre.lureau@redhat.com> In-Reply-To: <1438864852-4939-1-git-send-email-marcandre.lureau@redhat.com> References: <1438864852-4939-1-git-send-email-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [Qemu-devel] [PATCH v3 07/16] vhost-user: start and end the va_list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: haifeng.lin@huawei.com, mst@redhat.com, thibaut.collet@6wind.com, jasowang@redhat.com, pbonzini@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= From: Marc-André Lureau Use a common start and exit branch to open and cleanup the va_list. Signed-off-by: Marc-André Lureau --- 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