computing-offload/generic_vdpa/qemu/hw-scsi-vhost-scsi-don-t-double-close-vhostfd-on-err.patch
jiangdongxu 79c4324644 add generic_vdpa basecode
Change-Id: I2d302dda68298877c65c99147f5bf22186a59aac
2024-09-19 17:19:46 +08:00

50 lines
1.6 KiB
Diff

From 69f5f16cee63b0d07ee612b59a0d125780c13bdb Mon Sep 17 00:00:00 2001
From: boringandboring <wangjinlei_yewu@cmss.chinamobile.com>
Date: Fri, 8 Dec 2023 09:13:42 +0800
Subject: [PATCH] hw/scsi/vhost-scsi: don't double close vhostfd on error
cherry picked from 539ba1acacb11a0f27a7e7ff7e2a7c1294e0a1ea
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>
Signed-off-by: boringandboring <wangjinlei_yewu@cmss.chinamobile.com>
---
hw/scsi/vhost-scsi.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/hw/scsi/vhost-scsi.c b/hw/scsi/vhost-scsi.c
index b0a9c45e43..5536cc8a88 100644
--- a/hw/scsi/vhost-scsi.c
+++ b/hw/scsi/vhost-scsi.c
@@ -220,6 +220,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;
}
@@ -240,7 +245,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;
}
--
2.27.0