util/vfio-helpers: Simplify qemu_vfio_dma_map() returning directly
To simplify qemu_vfio_dma_map(): - reduce 'ret' (returned value) scope by returning errno directly, - remove the goto 'out' label. Reviewed-by: Klaus Jensen <k.jensen@samsung.com> Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com> Message-id: 20210902070025.197072-10-philmd@redhat.com Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
453095e98d
commit
5a4f1626e3
@ -748,7 +748,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,
|
int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
|
||||||
bool temporary, uint64_t *iova, Error **errp)
|
bool temporary, uint64_t *iova, Error **errp)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
|
||||||
int index;
|
int index;
|
||||||
IOVAMapping *mapping;
|
IOVAMapping *mapping;
|
||||||
uint64_t iova0;
|
uint64_t iova0;
|
||||||
@ -761,32 +760,31 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
|
|||||||
if (mapping) {
|
if (mapping) {
|
||||||
iova0 = mapping->iova + ((uint8_t *)host - (uint8_t *)mapping->host);
|
iova0 = mapping->iova + ((uint8_t *)host - (uint8_t *)mapping->host);
|
||||||
} else {
|
} else {
|
||||||
|
int ret;
|
||||||
|
|
||||||
if (qemu_vfio_water_mark_reached(s, size, errp)) {
|
if (qemu_vfio_water_mark_reached(s, size, errp)) {
|
||||||
ret = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
if (!temporary) {
|
if (!temporary) {
|
||||||
if (!qemu_vfio_find_fixed_iova(s, size, &iova0, errp)) {
|
if (!qemu_vfio_find_fixed_iova(s, size, &iova0, errp)) {
|
||||||
ret = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mapping = qemu_vfio_add_mapping(s, host, size, index + 1, iova0);
|
mapping = qemu_vfio_add_mapping(s, host, size, index + 1, iova0);
|
||||||
assert(qemu_vfio_verify_mappings(s));
|
assert(qemu_vfio_verify_mappings(s));
|
||||||
ret = qemu_vfio_do_mapping(s, host, size, iova0);
|
ret = qemu_vfio_do_mapping(s, host, size, iova0);
|
||||||
if (ret) {
|
if (ret < 0) {
|
||||||
qemu_vfio_undo_mapping(s, mapping, NULL);
|
qemu_vfio_undo_mapping(s, mapping, NULL);
|
||||||
goto out;
|
return ret;
|
||||||
}
|
}
|
||||||
qemu_vfio_dump_mappings(s);
|
qemu_vfio_dump_mappings(s);
|
||||||
} else {
|
} else {
|
||||||
if (!qemu_vfio_find_temp_iova(s, size, &iova0, errp)) {
|
if (!qemu_vfio_find_temp_iova(s, size, &iova0, errp)) {
|
||||||
ret = -ENOMEM;
|
return -ENOMEM;
|
||||||
goto out;
|
|
||||||
}
|
}
|
||||||
ret = qemu_vfio_do_mapping(s, host, size, iova0);
|
ret = qemu_vfio_do_mapping(s, host, size, iova0);
|
||||||
if (ret) {
|
if (ret < 0) {
|
||||||
goto out;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -794,8 +792,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
|
|||||||
if (iova) {
|
if (iova) {
|
||||||
*iova = iova0;
|
*iova = iova0;
|
||||||
}
|
}
|
||||||
out:
|
return 0;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reset the high watermark and free all "temporary" mappings. */
|
/* Reset the high watermark and free all "temporary" mappings. */
|
||||||
|
Loading…
Reference in New Issue
Block a user