* [PATCH v1] virtio/vhost-vsock: don't double close vhostfd, remove redundant cleanup
@ 2021-11-29 12:52 Daniil Tatianin
2021-11-29 13:44 ` Stefano Garzarella
0 siblings, 1 reply; 2+ messages in thread
From: Daniil Tatianin @ 2021-11-29 12:52 UTC (permalink / raw)
To: qemu-devel; +Cc: yc-core, mst
In case of an error during initialization in vhost_dev_init, vhostfd is
closed in vhost_dev_cleanup. Remove close from err_virtio as it's both
redundant and causes a double close on vhostfd.
Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
---
hw/virtio/vhost-vsock.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/hw/virtio/vhost-vsock.c b/hw/virtio/vhost-vsock.c
index 478c0c9a87..433d42d897 100644
--- a/hw/virtio/vhost-vsock.c
+++ b/hw/virtio/vhost-vsock.c
@@ -171,6 +171,10 @@ static void vhost_vsock_device_realize(DeviceState *dev, Error **errp)
ret = vhost_dev_init(&vvc->vhost_dev, (void *)(uintptr_t)vhostfd,
VHOST_BACKEND_TYPE_KERNEL, 0, errp);
if (ret < 0) {
+ /*
+ * vhostfd is closed by vhost_dev_cleanup, which is called
+ * by vhost_dev_init on initialization error.
+ */
goto err_virtio;
}
@@ -183,15 +187,10 @@ static void vhost_vsock_device_realize(DeviceState *dev, Error **errp)
return;
err_vhost_dev:
- vhost_dev_cleanup(&vvc->vhost_dev);
/* vhost_dev_cleanup() closes the vhostfd passed to vhost_dev_init() */
- vhostfd = -1;
+ vhost_dev_cleanup(&vvc->vhost_dev);
err_virtio:
vhost_vsock_common_unrealize(vdev);
- if (vhostfd >= 0) {
- close(vhostfd);
- }
- return;
}
static void vhost_vsock_device_unrealize(DeviceState *dev)
--
2.25.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v1] virtio/vhost-vsock: don't double close vhostfd, remove redundant cleanup
2021-11-29 12:52 [PATCH v1] virtio/vhost-vsock: don't double close vhostfd, remove redundant cleanup Daniil Tatianin
@ 2021-11-29 13:44 ` Stefano Garzarella
0 siblings, 0 replies; 2+ messages in thread
From: Stefano Garzarella @ 2021-11-29 13:44 UTC (permalink / raw)
To: Daniil Tatianin; +Cc: qemu-devel, yc-core, mst
On Mon, Nov 29, 2021 at 03:52:04PM +0300, Daniil Tatianin wrote:
>In case of an error during initialization in vhost_dev_init, vhostfd is
>closed in vhost_dev_cleanup. Remove close from err_virtio as it's both
>redundant and causes a double close on vhostfd.
>
>Signed-off-by: Daniil Tatianin <d-tatianin@yandex-team.ru>
>---
> hw/virtio/vhost-vsock.c | 11 +++++------
> 1 file changed, 5 insertions(+), 6 deletions(-)
>
>diff --git a/hw/virtio/vhost-vsock.c b/hw/virtio/vhost-vsock.c
>index 478c0c9a87..433d42d897 100644
>--- a/hw/virtio/vhost-vsock.c
>+++ b/hw/virtio/vhost-vsock.c
>@@ -171,6 +171,10 @@ static void vhost_vsock_device_realize(DeviceState *dev, Error **errp)
> ret = vhost_dev_init(&vvc->vhost_dev, (void *)(uintptr_t)vhostfd,
> VHOST_BACKEND_TYPE_KERNEL, 0, errp);
> if (ret < 0) {
>+ /*
>+ * vhostfd is closed by vhost_dev_cleanup, which is called
>+ * by vhost_dev_init on initialization error.
>+ */
> goto err_virtio;
> }
>
>@@ -183,15 +187,10 @@ static void vhost_vsock_device_realize(DeviceState *dev, Error **errp)
> return;
>
> err_vhost_dev:
>- vhost_dev_cleanup(&vvc->vhost_dev);
> /* vhost_dev_cleanup() closes the vhostfd passed to vhost_dev_init() */
>- vhostfd = -1;
>+ vhost_dev_cleanup(&vvc->vhost_dev);
> err_virtio:
> vhost_vsock_common_unrealize(vdev);
>- if (vhostfd >= 0) {
>- close(vhostfd);
>- }
>- return;
> }
>
> static void vhost_vsock_device_unrealize(DeviceState *dev)
>--
>2.25.1
>
>
Thanks for this patch. It LGTM:
Reviewed-by: Stefano Garzarella <sgarzare@redhat.com>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-11-29 13:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-29 12:52 [PATCH v1] virtio/vhost-vsock: don't double close vhostfd, remove redundant cleanup Daniil Tatianin
2021-11-29 13:44 ` Stefano Garzarella
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).