From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39389) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSyHJ-0005ZB-Vm for qemu-devel@nongnu.org; Thu, 28 Jul 2016 23:16:02 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bSyHF-0002rY-EB for qemu-devel@nongnu.org; Thu, 28 Jul 2016 23:16:01 -0400 Received: from mx1.redhat.com ([209.132.183.28]:40366) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bSyHF-0002rU-69 for qemu-devel@nongnu.org; Thu, 28 Jul 2016 23:15:57 -0400 Date: Fri, 29 Jul 2016 06:15:54 +0300 From: "Michael S. Tsirkin" Message-ID: <1469762011-7902-15-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 14/41] 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: Peter Maydell , =?iso-8859-1?Q?Marc-Andr=E9?= Lureau From: Marc-Andr=E9 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=E9 Lureau Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- 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 MST