Received: from eggs.gnu.org ([209.51.188.92]:58971) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h1J1N-0002Bw-8v for qemu-devel@nongnu.org; Tue, 05 Mar 2019 17:58:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h1J1M-0007yR-E5 for qemu-devel@nongnu.org; Tue, 05 Mar 2019 17:58:49 -0500 Received: from mx1.redhat.com ([209.132.183.28]:33960) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1h1J1M-0007y9-7R for qemu-devel@nongnu.org; Tue, 05 Mar 2019 17:58:48 -0500 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 839D4318A5EC for ; Tue, 5 Mar 2019 22:58:47 +0000 (UTC) From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Tue, 5 Mar 2019 23:57:26 +0100 Message-Id: <20190305225731.15074-8-marcandre.lureau@redhat.com> In-Reply-To: <20190305225731.15074-1-marcandre.lureau@redhat.com> References: <20190305225731.15074-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH v5 07/12] 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, mst@redhat.com Split vhost_user_read(), so only header can be read with vhost_user_read_header(). Signed-off-by: Marc-Andr=C3=A9 Lureau Reviewed-by: Daniel P. Berrang=C3=A9 --- hw/virtio/vhost-user.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/hw/virtio/vhost-user.c b/hw/virtio/vhost-user.c index 3b09c40578..5df73405bc 100644 --- a/hw/virtio/vhost-user.c +++ b/hw/virtio/vhost-user.c @@ -214,7 +214,7 @@ static bool ioeventfd_enabled(void) return !kvm_enabled() || kvm_eventfds_enabled(); } =20 -static int vhost_user_read(struct vhost_dev *dev, VhostUserMsg *msg) +static int vhost_user_read_header(struct vhost_dev *dev, VhostUserMsg *m= sg) { struct vhost_user *u =3D dev->opaque; CharBackend *chr =3D u->user->chr; @@ -225,7 +225,7 @@ static int vhost_user_read(struct vhost_dev *dev, Vho= stUserMsg *msg) if (r !=3D size) { error_report("Failed to read msg header. Read %d instead of %d." " Original request %d.", r, size, msg->hdr.request)= ; - goto fail; + return -1; } =20 /* validate received flags */ @@ -233,7 +233,21 @@ static int vhost_user_read(struct vhost_dev *dev, Vh= ostUserMsg *msg) error_report("Failed to read msg header." " Flags 0x%x instead of 0x%x.", msg->hdr.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) +{ + struct vhost_user *u =3D dev->opaque; + CharBackend *chr =3D u->user->chr; + uint8_t *p =3D (uint8_t *) msg; + int r, size; + + if (vhost_user_read_header(dev, msg) < 0) { + return -1; } =20 /* validate message size is sane */ @@ -241,7 +255,7 @@ static int vhost_user_read(struct vhost_dev *dev, Vho= stUserMsg *msg) error_report("Failed to read msg header." " Size %d exceeds the maximum %zu.", msg->hdr.size, VHOST_USER_PAYLOAD_SIZE); - goto fail; + return -1; } =20 if (msg->hdr.size) { @@ -251,14 +265,11 @@ static int vhost_user_read(struct vhost_dev *dev, V= hostUserMsg *msg) if (r !=3D size) { error_report("Failed to read msg payload." " Read %d instead of %d.", r, msg->hdr.size); - goto fail; + return -1; } } =20 return 0; - -fail: - return -1; } =20 static int process_message_reply(struct vhost_dev *dev, --=20 2.21.0.4.g36eb1cb9cf