* [Qemu-devel] [PATCH] vhost-user-scsi: Call virtio_scsi_common_unrealize() when device realize failed
@ 2019-07-17 9:47 Paolo Bonzini
0 siblings, 0 replies; only message in thread
From: Paolo Bonzini @ 2019-07-17 9:47 UTC (permalink / raw)
To: qemu-devel; +Cc: Xie Yongji
From: Xie Yongji <xieyongji@baidu.com>
This avoids memory leak when device hotplug is failed.
Signed-off-by: Xie Yongji <xieyongji@baidu.com>
Message-Id: <20190717004606.12444-2-xieyongji@baidu.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
hw/scsi/vhost-user-scsi.c | 16 ++++++++++++----
1 file changed, 12 insertions(+), 4 deletions(-)
diff --git a/hw/scsi/vhost-user-scsi.c b/hw/scsi/vhost-user-scsi.c
index a0b69fbc0f..665939df19 100644
--- a/hw/scsi/vhost-user-scsi.c
+++ b/hw/scsi/vhost-user-scsi.c
@@ -87,7 +87,7 @@ static void vhost_user_scsi_realize(DeviceState *dev, Error **errp)
}
if (!vhost_user_init(&s->vhost_user, &vs->conf.chardev, errp)) {
- return;
+ goto free_virtio;
}
vsc->dev.nvqs = 2 + vs->conf.num_queues;
@@ -101,15 +101,23 @@ static void vhost_user_scsi_realize(DeviceState *dev, Error **errp)
if (ret < 0) {
error_setg(errp, "vhost-user-scsi: vhost initialization failed: %s",
strerror(-ret));
- vhost_user_cleanup(&s->vhost_user);
- g_free(vqs);
- return;
+ goto free_vhost;
}
/* Channel and lun both are 0 for bootable vhost-user-scsi disk */
vsc->channel = 0;
vsc->lun = 0;
vsc->target = vs->conf.boot_tpgt;
+
+ return;
+
+free_vhost:
+ vhost_user_cleanup(&s->vhost_user);
+ g_free(vqs);
+free_virtio:
+ err = NULL;
+ virtio_scsi_common_unrealize(dev, &err);
+ error_propagate(errp, err);
}
static void vhost_user_scsi_unrealize(DeviceState *dev, Error **errp)
--
2.21.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2019-07-17 9:48 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-17 9:47 [Qemu-devel] [PATCH] vhost-user-scsi: Call virtio_scsi_common_unrealize() when device realize failed Paolo Bonzini
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).