[V2 1/2] ACRN: DM: Refine the vhost_vsock_deinit function


Long Liu
 

In deinit function close the vhost_vsock fd and free the vhost_vsock
struct no matter the above logic.

Signed-off-by: Liu Long <long.liu@...>
---
devicemodel/hw/pci/virtio/vhost_vsock.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/devicemodel/hw/pci/virtio/vhost_vsock.c b/devicemodel/hw/pci/virtio/vhost_vsock.c
index e2aa06acd..922258be4 100644
--- a/devicemodel/hw/pci/virtio/vhost_vsock.c
+++ b/devicemodel/hw/pci/virtio/vhost_vsock.c
@@ -208,25 +208,21 @@ fail:
return NULL;
}

-static int
+static void
vhost_vsock_deinit(struct vhost_vsock *vhost_vsock)
{
int rc;

rc = vhost_vsock_stop(vhost_vsock);
- if (rc < 0) {
+ if (rc < 0)
pr_err("vhost_dev_stop is failed.\n");
- return -1;
- }

rc = vhost_dev_deinit(&vhost_vsock->vdev);
- if (rc < 0) {
+ if (rc < 0)
pr_err("vhost_dev_deinit is failed.\n");
- return -1;
- }
+
close(vhost_vsock->vhost_fd);
free(vhost_vsock);
- return 0;
}

static void
@@ -323,10 +319,9 @@ virtio_vhost_vsock_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
if (dev->arg) {
vsock = (struct virtio_vsock *) dev->arg;

- if (vsock->vhost_vsock) {
+ if (vsock->vhost_vsock)
vhost_vsock_deinit(vsock->vhost_vsock);
- }
- pr_dbg("%s: done\n", __func__);
+ pr_dbg("%s: done\n", __func__);
} else
pr_err("%s: NULL.\n", __func__);
}
--
2.25.1


Yu Wang
 

On Tue, Jun 14, 2022 at 10:14:25AM +0800, Liu Long wrote:
In deinit function close the vhost_vsock fd and free the vhost_vsock
struct no matter the above logic.
Title: dm: vsock: fix the memory leakage bug

Fix the memory leakage issue caused by incomplete deinit flow.

Acked-by: Wang, Yu1 <yu1.wang@...>


Signed-off-by: Liu Long <long.liu@...>
---
devicemodel/hw/pci/virtio/vhost_vsock.c | 17 ++++++-----------
1 file changed, 6 insertions(+), 11 deletions(-)

diff --git a/devicemodel/hw/pci/virtio/vhost_vsock.c b/devicemodel/hw/pci/virtio/vhost_vsock.c
index e2aa06acd..922258be4 100644
--- a/devicemodel/hw/pci/virtio/vhost_vsock.c
+++ b/devicemodel/hw/pci/virtio/vhost_vsock.c
@@ -208,25 +208,21 @@ fail:
return NULL;
}

-static int
+static void
vhost_vsock_deinit(struct vhost_vsock *vhost_vsock)
{
int rc;

rc = vhost_vsock_stop(vhost_vsock);
- if (rc < 0) {
+ if (rc < 0)
pr_err("vhost_dev_stop is failed.\n");
- return -1;
- }

rc = vhost_dev_deinit(&vhost_vsock->vdev);
- if (rc < 0) {
+ if (rc < 0)
pr_err("vhost_dev_deinit is failed.\n");
- return -1;
- }
+
close(vhost_vsock->vhost_fd);
free(vhost_vsock);
- return 0;
}

static void
@@ -323,10 +319,9 @@ virtio_vhost_vsock_deinit(struct vmctx *ctx, struct pci_vdev *dev, char *opts)
if (dev->arg) {
vsock = (struct virtio_vsock *) dev->arg;

- if (vsock->vhost_vsock) {
+ if (vsock->vhost_vsock)
vhost_vsock_deinit(vsock->vhost_vsock);
- }
- pr_dbg("%s: done\n", __func__);
+ pr_dbg("%s: done\n", __func__);
} else
pr_err("%s: NULL.\n", __func__);
}
--
2.25.1