Received: from eggs.gnu.org ([2001:4830:134:3::10]:44708) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9JCK-0005oI-4r for qemu-devel@nongnu.org; Sat, 04 Jun 2016 17:33:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b9JCI-0005iX-5z for qemu-devel@nongnu.org; Sat, 04 Jun 2016 17:33:35 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:33033) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b9JCH-0005iQ-Vz for qemu-devel@nongnu.org; Sat, 04 Jun 2016 17:33:34 -0400 Received: by mail-wm0-x242.google.com with SMTP id a136so7294021wme.0 for ; Sat, 04 Jun 2016 14:33:33 -0700 (PDT) Sender: =?UTF-8?B?TWFyYy1BbmRyw6kgTHVyZWF1?= From: marcandre.lureau@redhat.com Date: Sat, 4 Jun 2016 23:33:12 +0200 Message-Id: <1465076003-26291-4-git-send-email-marcandre.lureau@redhat.com> In-Reply-To: <1465076003-26291-1-git-send-email-marcandre.lureau@redhat.com> References: <1465076003-26291-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] [RFC 03/14] vhost-user: split vhost_user_read() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kraxel@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= From: Marc-André Lureau Split vhost_user_read(), so only header can be read with vhost_user_read_header(). Signed-off-by: Marc-André Lureau --- hw/virtio/vhost-user.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 495e09f..63ffe48 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -112,7 +112,7 @@ static bool ioeventfd_enabled(void) return kvm_enabled() && kvm_eventfds_enabled(); } -static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) +static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *msg) { CharDriverState *chr = dev->opaque; uint8_t *p = (uint8_t *) msg; @@ -122,7 +122,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) if (r != size) { error_report("Failed to read msg header. Read %d instead of %d." " Original request %d.", r, size, msg->request); - goto fail; + return -1; } /* validate received flags */ @@ -130,7 +130,20 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) error_report("Failed to read msg header." " Flags 0x%x instead of 0x%x.", msg->flags, VHOST_USER_REPLY_MASK | VHOST_USER_VERSION); - goto fail; + return -1; + } + + return 0; +} + +static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) +{ + CharDriverState *chr = dev->opaque; + uint8_t *p = (uint8_t *) msg; + int r, size; + + if (vhost_user_read_header(dev, msg) < 0) { + return -1; } /* validate message size is sane */ @@ -138,7 +151,7 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) error_report("Failed to read msg header." " Size %d exceeds the maximum %zu.", msg->size, VHOST_USER_PAYLOAD_SIZE); - goto fail; + return -1; } if (msg->size) { @@ -148,14 +161,11 @@ static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) if (r != size) { error_report("Failed to read msg payload." " Read %d instead of %d.", r, msg->size); - goto fail; + return -1; } } return 0; - -fail: - return -1; } static bool vhost_user_one_time_request(VhostUserRequest request) @@ -458,7 +468,7 @@ static int vhost_user_get_u64(struct vhost_dev *dev, int request, uint64_t *u64) vhost_user_write(dev, &msg, NULL, 0); if (vhost_user_read(dev, &msg) < 0) { - return 0; + return -1; } if (msg.request != request) { -- 2.7.4