From: "Philippe Mathieu-Daudé" <philmd@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Fam Zheng" <fam@euphon.net>, "Kevin Wolf" <kwolf@redhat.com>,
qemu-block@nongnu.org, "Max Reitz" <mreitz@redhat.com>,
"Hanna Reitz" <hreitz@redhat.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Philippe Mathieu-Daudé" <philmd@redhat.com>
Subject: [PATCH 1/5] block/nvme: Automatically free qemu_memalign() with QEMU_AUTO_VFREE
Date: Wed, 6 Oct 2021 18:49:27 +0200 [thread overview]
Message-ID: <20211006164931.172349-2-philmd@redhat.com> (raw)
In-Reply-To: <20211006164931.172349-1-philmd@redhat.com>
Since commit 4d324c0bf65 ("introduce QEMU_AUTO_VFREE") buffers
allocated by qemu_memalign() can automatically freed when using
the QEMU_AUTO_VFREE macro. Use it to simplify a bit.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
block/nvme.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/block/nvme.c b/block/nvme.c
index 1cc7b62bb4b..fefcc04abe6 100644
--- a/block/nvme.c
+++ b/block/nvme.c
@@ -514,10 +514,10 @@ static bool nvme_identify(BlockDriverState *bs, int namespace, Error **errp)
{
BDRVNVMeState *s = bs->opaque;
bool ret = false;
- union {
+ QEMU_AUTO_VFREE union {
NvmeIdCtrl ctrl;
NvmeIdNs ns;
- } *id;
+ } *id = NULL;
NvmeLBAF *lbaf;
uint16_t oncs;
int r;
@@ -595,7 +595,6 @@ static bool nvme_identify(BlockDriverState *bs, int namespace, Error **errp)
s->blkshift = lbaf->ds;
out:
qemu_vfio_dma_unmap(s->vfio, id);
- qemu_vfree(id);
return ret;
}
@@ -1219,7 +1218,7 @@ static int nvme_co_prw(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
{
BDRVNVMeState *s = bs->opaque;
int r;
- uint8_t *buf = NULL;
+ QEMU_AUTO_VFREE uint8_t *buf = NULL;
QEMUIOVector local_qiov;
size_t len = QEMU_ALIGN_UP(bytes, qemu_real_host_page_size);
assert(QEMU_IS_ALIGNED(offset, s->page_size));
@@ -1246,7 +1245,6 @@ static int nvme_co_prw(BlockDriverState *bs, uint64_t offset, uint64_t bytes,
if (!r && !is_write) {
qemu_iovec_from_buf(qiov, 0, buf, bytes);
}
- qemu_vfree(buf);
return r;
}
@@ -1365,7 +1363,7 @@ static int coroutine_fn nvme_co_pdiscard(BlockDriverState *bs,
BDRVNVMeState *s = bs->opaque;
NVMeQueuePair *ioq = s->queues[INDEX_IO(0)];
NVMeRequest *req;
- NvmeDsmRange *buf;
+ QEMU_AUTO_VFREE NvmeDsmRange *buf = NULL;
QEMUIOVector local_qiov;
int ret;
@@ -1440,7 +1438,6 @@ static int coroutine_fn nvme_co_pdiscard(BlockDriverState *bs,
trace_nvme_dsm_done(s, offset, bytes, ret);
out:
qemu_iovec_destroy(&local_qiov);
- qemu_vfree(buf);
return ret;
}
--
2.31.1
next prev parent reply other threads:[~2021-10-06 16:57 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-06 16:49 [PATCH 0/5] block/nvme: Fix a memory leak in nvme_free_queue_pair() Philippe Mathieu-Daudé
2021-10-06 16:49 ` Philippe Mathieu-Daudé [this message]
2021-10-07 13:29 ` [PATCH 1/5] block/nvme: Automatically free qemu_memalign() with QEMU_AUTO_VFREE Stefan Hajnoczi
2021-10-06 16:49 ` [PATCH 2/5] block/nvme: Display CQ/SQ pointer in nvme_free_queue_pair() Philippe Mathieu-Daudé
2021-10-07 13:29 ` Stefan Hajnoczi
2021-10-06 16:49 ` [PATCH 3/5] block/nvme: Extract nvme_free_queue() from nvme_free_queue_pair() Philippe Mathieu-Daudé
2021-10-07 13:29 ` Stefan Hajnoczi
2021-10-06 16:49 ` [PATCH 4/5] block/nvme: Pass BDRVNVMeState* handle to nvme_free_queue_pair() Philippe Mathieu-Daudé
2021-10-07 13:30 ` Stefan Hajnoczi
2021-10-06 16:49 ` [PATCH 5/5] block/nvme: Fix memory leak from nvme_init_queue() Philippe Mathieu-Daudé
2021-10-06 16:58 ` Philippe Mathieu-Daudé
2021-10-07 13:29 ` Stefan Hajnoczi
2021-10-07 13:34 ` Philippe Mathieu-Daudé
2021-11-02 12:33 ` Kevin Wolf
2021-11-02 12:36 ` Philippe Mathieu-Daudé
2021-11-02 14:50 ` Kevin Wolf
2021-11-02 15:17 ` Philippe Mathieu-Daudé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211006164931.172349-2-philmd@redhat.com \
--to=philmd@redhat.com \
--cc=fam@euphon.net \
--cc=hreitz@redhat.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).