* [Qemu-devel] [PATCH] nvme: Reset s->nr_queues upon open failure
@ 2018-06-13 7:45 Fam Zheng
2018-06-13 8:16 ` Kevin Wolf
0 siblings, 1 reply; 2+ messages in thread
From: Fam Zheng @ 2018-06-13 7:45 UTC (permalink / raw)
To: qemu-devel; +Cc: Fam Zheng, Kevin Wolf, Max Reitz, qemu-block, qemu-stable
It is wrong to leave this field as 1, as nvme_close() called in the
error handling code in nvme_file_open() will use it and try to free
s->queues again.
Clear the fields to avoid double-free.
Cc: qemu-stable@nongnu.org
Signed-off-by: Fam Zheng <famz@redhat.com>
---
block/nvme.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/block/nvme.c b/block/nvme.c
index 6f71122bf5..7bdeb0ffce 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -666,6 +666,8 @@ fail_queue:
nvme_free_queue_pair(bs, s->queues[0]);
fail:
g_free(s->queues);
+ s->queues = NULL;
+ s->nr_queues = 0;
if (s->regs) {
qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)s->regs, 0, NVME_BAR_SIZE);
}
--
2.17.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [Qemu-devel] [PATCH] nvme: Reset s->nr_queues upon open failure
2018-06-13 7:45 [Qemu-devel] [PATCH] nvme: Reset s->nr_queues upon open failure Fam Zheng
@ 2018-06-13 8:16 ` Kevin Wolf
0 siblings, 0 replies; 2+ messages in thread
From: Kevin Wolf @ 2018-06-13 8:16 UTC (permalink / raw)
To: Fam Zheng; +Cc: qemu-devel, Max Reitz, qemu-block, qemu-stable
Am 13.06.2018 um 09:45 hat Fam Zheng geschrieben:
> It is wrong to leave this field as 1, as nvme_close() called in the
> error handling code in nvme_file_open() will use it and try to free
> s->queues again.
>
> Clear the fields to avoid double-free.
>
> Cc: qemu-stable@nongnu.org
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---
> block/nvme.c | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/block/nvme.c b/block/nvme.c
> index 6f71122bf5..7bdeb0ffce 100644
> --- a/block/nvme.c
> +++ b/block/nvme.c
> @@ -666,6 +666,8 @@ fail_queue:
> nvme_free_queue_pair(bs, s->queues[0]);
> fail:
> g_free(s->queues);
> + s->queues = NULL;
> + s->nr_queues = 0;
> if (s->regs) {
> qemu_vfio_pci_unmap_bar(s->vfio, 0, (void *)s->regs, 0, NVME_BAR_SIZE);
> }
Hm... Basically all the cleanup is duplicated. It's not only
nvme_free_queue_pair(), but also qemu_vfio_pci_unmap_bar() and
qemu_vfio_close(). Are we sure it's intended to call them twice?
Maybe nvme_init() shouldn't clean up any of this and rely on the
later nvme_close() call to do that?
I also notice that the error handling code in nvme_init() has a
g_free(s->queues) and event_notifier_cleanup(&s->irq_notifier), which
nvme_close() doesn't. Are these leaks in nvme_close()?
Kevin
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-06-13 8:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-13 7:45 [Qemu-devel] [PATCH] nvme: Reset s->nr_queues upon open failure Fam Zheng
2018-06-13 8:16 ` Kevin Wolf
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).