[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 09/11] util/vfio-helpers: Simplify qemu_vfio_dma_map() returni
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH v2 09/11] util/vfio-helpers: Simplify qemu_vfio_dma_map() returning directly |
Date: |
Thu, 26 Aug 2021 21:50:12 +0200 |
To simplify qemu_vfio_dma_map():
- reduce 'ret' (returned value) scope by returning errno directly,
- remove the goto 'out' label.
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
---
util/vfio-helpers.c | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
diff --git a/util/vfio-helpers.c b/util/vfio-helpers.c
index 7de5081dbd3..48b4384e8c8 100644
--- a/util/vfio-helpers.c
+++ b/util/vfio-helpers.c
@@ -750,7 +750,6 @@ static bool qemu_vfio_water_mark_reached(QEMUVFIOState *s,
size_t size,
int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
bool temporary, uint64_t *iova, Error **errp)
{
- int ret = 0;
int index;
IOVAMapping *mapping;
uint64_t iova0;
@@ -763,32 +762,31 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host,
size_t size,
if (mapping) {
iova0 = mapping->iova + ((uint8_t *)host - (uint8_t *)mapping->host);
} else {
+ int ret;
+
if (qemu_vfio_water_mark_reached(s, size, errp)) {
- ret = -ENOMEM;
- goto out;
+ return -ENOMEM;
}
if (!temporary) {
if (qemu_vfio_find_fixed_iova(s, size, &iova0, errp) < 0) {
- ret = -ENOMEM;
- goto out;
+ return -ENOMEM;
}
mapping = qemu_vfio_add_mapping(s, host, size, index + 1, iova0);
assert(qemu_vfio_verify_mappings(s));
ret = qemu_vfio_do_mapping(s, host, size, iova0);
- if (ret) {
+ if (ret < 0) {
qemu_vfio_undo_mapping(s, mapping, NULL);
- goto out;
+ return ret;
}
qemu_vfio_dump_mappings(s);
} else {
if (qemu_vfio_find_temp_iova(s, size, &iova0, errp)) {
- ret = -ENOMEM;
- goto out;
+ return -ENOMEM;
}
ret = qemu_vfio_do_mapping(s, host, size, iova0);
- if (ret) {
- goto out;
+ if (ret < 0) {
+ return ret;
}
}
}
@@ -796,8 +794,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t
size,
if (iova) {
*iova = iova0;
}
-out:
- return ret;
+ return 0;
}
/* Reset the high watermark and free all "temporary" mappings. */
--
2.31.1
- Re: [PATCH v2 05/11] block/nvme: Have nvme_create_queue_pair() report errors consistently, (continued)
- [PATCH v2 07/11] util/vfio-helpers: Extract qemu_vfio_water_mark_reached(), Philippe Mathieu-Daudé, 2021/08/26
- [PATCH v2 08/11] util/vfio-helpers: Use error_setg in qemu_vfio_find_[fixed/temp]_iova, Philippe Mathieu-Daudé, 2021/08/26
- [PATCH v2 09/11] util/vfio-helpers: Simplify qemu_vfio_dma_map() returning directly,
Philippe Mathieu-Daudé <=
- [PATCH v2 10/11] util/vfio-helpers: Let qemu_vfio_do_mapping() propagate Error, Philippe Mathieu-Daudé, 2021/08/26
- [PATCH v2 11/11] block/nvme: Only report VFIO error on failed retry, Philippe Mathieu-Daudé, 2021/08/26