summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDaniil Tatianin <d-tatianin@yandex-team.ru>2021-11-29 16:23:58 +0300
committerMichael S. Tsirkin <mst@redhat.com>2022-01-07 19:30:13 -0500
commit539ba1acacb11a0f27a7e7ff7e2a7c1294e0a1ea (patch)
tree2393aa35d2ab6de8449d6f51e949d270c2d247fd
parentb259772afc29ef6af4e911d8e695dd7e2ed31066 (diff)
downloadfocaccia-qemu-539ba1acacb11a0f27a7e7ff7e2a7c1294e0a1ea.tar.gz
focaccia-qemu-539ba1acacb11a0f27a7e7ff7e2a7c1294e0a1ea.zip
hw/scsi/vhost-scsi: don't double close vhostfd on error
vhost_dev_init calls vhost_dev_cleanup on error, which closes vhostfd,
don't double close it.

Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
Message-Id: <20211129132358.1110372-2-d-tatianin@yandex-team.ru>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
-rw-r--r--hw/scsi/vhost-scsi.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c
index efb3e14d9e..778f43e4c1 100644
--- a/hw/scsi/vhost-scsi.c
+++ b/hw/scsi/vhost-scsi.c
@@ -222,6 +222,11 @@ static void vhost_scsi_realize(DeviceState *dev, Error **errp)
     ret = vhost_dev_init(&vsc->dev, (void *)(uintptr_t)vhostfd,
                          VHOST_BACKEND_TYPE_KERNEL, 0, errp);
     if (ret < 0) {
+        /*
+         * vhost_dev_init calls vhost_dev_cleanup on error, which closes
+         * vhostfd, don't double close it.
+         */
+        vhostfd = -1;
         goto free_vqs;
     }
 
@@ -242,7 +247,9 @@ static void vhost_scsi_realize(DeviceState *dev, Error **errp)
     error_free(vsc->migration_blocker);
     virtio_scsi_common_unrealize(dev);
  close_fd:
-    close(vhostfd);
+    if (vhostfd >= 0) {
+        close(vhostfd);
+    }
     return;
 }