]> www.infradead.org Git - users/dwmw2/qemu.git/commitdiff
hw/scsi/vhost-scsi: don't double close vhostfd on error
authorDaniil Tatianin <d-tatianin@yandex-team.ru>
Mon, 29 Nov 2021 13:23:58 +0000 (16:23 +0300)
committerMichael S. Tsirkin <mst@redhat.com>
Sat, 8 Jan 2022 00:30:13 +0000 (19:30 -0500)
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>
hw/scsi/vhost-scsi.c

index efb3e14d9ed1178170b230c57d88729f5d5cc2b4..778f43e4c1909e9913e0f267b6b812f669b07156 100644 (file)
@@ -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;
 }