From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39469) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSyHh-0005sj-89 for qemu-devel@nongnu.org; Thu, 28 Jul 2016 23:16:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bSyHb-0002wg-Cy for qemu-devel@nongnu.org; Thu, 28 Jul 2016 23:16:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55086) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSyHb-0002wc-7C for qemu-devel@nongnu.org; Thu, 28 Jul 2016 23:16:19 -0400 Date: Fri, 29 Jul 2016 06:16:15 +0300 From: "Michael S. Tsirkin" Message-ID: <1469762011-7902-21-git-send-email-mst@redhat.com> References: <1469762011-7902-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline In-Reply-To: <1469762011-7902-1-git-send-email-mst@redhat.com> Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PULL 20/41] vhost: fix calling vhost_dev_cleanup() after vhost_dev_init() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Maydell , =?iso-8859-1?Q?Marc-Andr=E9?= Lureau , Ilya Maximets From: Marc-Andr=E9 Lureau vhost_net_init() calls vhost_dev_init() and in case of failure, calls vhost_dev_cleanup() directly. However, the structure is already partially cleaned on error. Calling vhost_dev_cleanup() again will call vhost_virtqueue_cleanup() on already clean queues, and causing potential double-close. Instead, adjust dev->nvqs and simplify vhost_dev_init() code to not call vhost_virtqueue_cleanup() but vhost_dev_cleanup() instead. Signed-off-by: Marc-Andr=E9 Lureau Signed-off-by: Ilya Maximets Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/virtio/vhost.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index 9400b47..e3091d1 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1015,7 +1015,7 @@ int vhost_dev_init(struct vhost_dev *hdev, void *op= aque, VhostBackendType backend_type, uint32_t busyloop_time= out) { uint64_t features; - int i, r; + int i, r, n_initialized_vqs =3D 0; =20 hdev->migration_blocker =3D NULL; =20 @@ -1044,10 +1044,10 @@ int vhost_dev_init(struct vhost_dev *hdev, void *= opaque, goto fail; } =20 - for (i =3D 0; i < hdev->nvqs; ++i) { + for (i =3D 0; i < hdev->nvqs; ++i, ++n_initialized_vqs) { r =3D vhost_virtqueue_init(hdev, hdev->vqs + i, hdev->vq_index += i); if (r < 0) { - goto fail_vq; + goto fail; } } =20 @@ -1104,19 +1104,14 @@ int vhost_dev_init(struct vhost_dev *hdev, void *= opaque, memory_listener_register(&hdev->memory_listener, &address_space_memo= ry); QLIST_INSERT_HEAD(&vhost_devices, hdev, entry); return 0; + fail_busyloop: while (--i >=3D 0) { vhost_virtqueue_set_busyloop_timeout(hdev, hdev->vq_index + i, 0= ); } - i =3D hdev->nvqs; -fail_vq: - while (--i >=3D 0) { - vhost_virtqueue_cleanup(hdev->vqs + i); - } fail: - r =3D -errno; - hdev->vhost_ops->vhost_backend_cleanup(hdev); - QLIST_REMOVE(hdev, entry); + hdev->nvqs =3D n_initialized_vqs; + vhost_dev_cleanup(hdev); return r; } =20 --=20 MST