[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 10/12] block/nvme: Automatically free qemu_memalign() with QEMU_AU
From: |
Kevin Wolf |
Subject: |
[PULL 10/12] block/nvme: Automatically free qemu_memalign() with QEMU_AUTO_VFREE |
Date: |
Tue, 2 Nov 2021 17:05:26 +0100 |
From: Philippe Mathieu-Daudé <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>
Message-Id: <20211006164931.172349-2-philmd@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
block/nvme.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/block/nvme.c b/block/nvme.c
index 1cc7b62bb4..fefcc04abe 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
- [PULL 00/12] Block layer patches, Kevin Wolf, 2021/11/02
- [PULL 01/12] block/file-posix: Fix return value translation for AIO discards, Kevin Wolf, 2021/11/02
- [PULL 02/12] block: Fail gracefully when blockdev-snapshot creates loops, Kevin Wolf, 2021/11/02
- [PULL 04/12] ide: Cap LBA28 capacity announcement to 2^28-1, Kevin Wolf, 2021/11/02
- [PULL 06/12] file-posix: add `aio-max-batch` option, Kevin Wolf, 2021/11/02
- [PULL 05/12] block/export/fuse.c: fix musl build, Kevin Wolf, 2021/11/02
- [PULL 03/12] block/rbd: implement bdrv_co_block_status, Kevin Wolf, 2021/11/02
- [PULL 08/12] linux-aio: add `dev_max_batch` parameter to laio_io_unplug(), Kevin Wolf, 2021/11/02
- [PULL 11/12] block/nvme: Display CQ/SQ pointer in nvme_free_queue_pair(), Kevin Wolf, 2021/11/02
- [PULL 12/12] block/nvme: Extract nvme_free_queue() from nvme_free_queue_pair(), Kevin Wolf, 2021/11/02
- [PULL 10/12] block/nvme: Automatically free qemu_memalign() with QEMU_AUTO_VFREE,
Kevin Wolf <=
- [PULL 09/12] block-backend: Silence clang -m32 compiler warning, Kevin Wolf, 2021/11/02
- [PULL 07/12] linux-aio: add `dev_max_batch` parameter to laio_co_submit(), Kevin Wolf, 2021/11/02
- Re: [PULL 00/12] Block layer patches, Richard Henderson, 2021/11/03