From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43504) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQ9o0-0008K6-Cc for qemu-devel@nongnu.org; Thu, 21 Jul 2016 04:58:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bQ9nw-0007KI-5x for qemu-devel@nongnu.org; Thu, 21 Jul 2016 04:58:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:55702) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bQ9nw-0007KE-09 for qemu-devel@nongnu.org; Thu, 21 Jul 2016 04:58:04 -0400 From: marcandre.lureau@redhat.com Date: Thu, 21 Jul 2016 12:57:22 +0400 Message-Id: <20160721085750.30008-4-marcandre.lureau@redhat.com> In-Reply-To: <20160721085750.30008-1-marcandre.lureau@redhat.com> References: <20160721085750.30008-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 03/31] vhost: don't assume opaque is a fd, use backend cleanup List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: mukawa@igel.co.jp, yuanhan.liu@linux.intel.com, victork@redhat.com, jonshin@cisco.com, mst@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= From: Marc-Andr=C3=A9 Lureau vhost-dev opaque isn't necessarily an fd, it can be a chardev when using vhost-user. Goto fail, so vhost_backend_cleanup() is called to handle backend cleanup appropriately. vhost_set_backend_type() should never fail, use an assert(). Signed-off-by: Marc-Andr=C3=A9 Lureau --- hw/virtio/vhost.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c index ec3abda..429499a 100644 --- a/hw/virtio/vhost.c +++ b/hw/virtio/vhost.c @@ -1019,21 +1019,19 @@ int vhost_dev_init(struct vhost_dev *hdev, void *= opaque, =20 hdev->migration_blocker =3D NULL; =20 - if (vhost_set_backend_type(hdev, backend_type) < 0) { - close((uintptr_t)opaque); - return -1; - } + r =3D vhost_set_backend_type(hdev, backend_type); + assert(r >=3D 0); =20 - if (hdev->vhost_ops->vhost_backend_init(hdev, opaque) < 0) { - close((uintptr_t)opaque); - return -errno; + r =3D hdev->vhost_ops->vhost_backend_init(hdev, opaque); + if (r < 0) { + goto fail; } =20 if (used_memslots > hdev->vhost_ops->vhost_backend_memslots_limit(hd= ev)) { fprintf(stderr, "vhost backend memory slots limit is less" " than current number of present memory slots\n"); - close((uintptr_t)opaque); - return -1; + r =3D -1; + goto fail; } QLIST_INSERT_HEAD(&vhost_devices, hdev, entry); =20 --=20 2.9.0