Skip to content

Commit 5a4f162

Browse files
philmdstefanhaRH
authored andcommitted
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 <[email protected]> Signed-off-by: Philippe Mathieu-Daudé <[email protected]> Message-id: [email protected] Signed-off-by: Stefan Hajnoczi <[email protected]>
1 parent 453095e commit 5a4f162

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

util/vfio-helpers.c

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,6 @@ static bool qemu_vfio_water_mark_reached(QEMUVFIOState *s, size_t size,
748748
int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
749749
bool temporary, uint64_t *iova, Error **errp)
750750
{
751-
int ret = 0;
752751
int index;
753752
IOVAMapping *mapping;
754753
uint64_t iova0;
@@ -761,41 +760,39 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
761760
if (mapping) {
762761
iova0 = mapping->iova + ((uint8_t *)host - (uint8_t *)mapping->host);
763762
} else {
763+
int ret;
764+
764765
if (qemu_vfio_water_mark_reached(s, size, errp)) {
765-
ret = -ENOMEM;
766-
goto out;
766+
return -ENOMEM;
767767
}
768768
if (!temporary) {
769769
if (!qemu_vfio_find_fixed_iova(s, size, &iova0, errp)) {
770-
ret = -ENOMEM;
771-
goto out;
770+
return -ENOMEM;
772771
}
773772

774773
mapping = qemu_vfio_add_mapping(s, host, size, index + 1, iova0);
775774
assert(qemu_vfio_verify_mappings(s));
776775
ret = qemu_vfio_do_mapping(s, host, size, iova0);
777-
if (ret) {
776+
if (ret < 0) {
778777
qemu_vfio_undo_mapping(s, mapping, NULL);
779-
goto out;
778+
return ret;
780779
}
781780
qemu_vfio_dump_mappings(s);
782781
} else {
783782
if (!qemu_vfio_find_temp_iova(s, size, &iova0, errp)) {
784-
ret = -ENOMEM;
785-
goto out;
783+
return -ENOMEM;
786784
}
787785
ret = qemu_vfio_do_mapping(s, host, size, iova0);
788-
if (ret) {
789-
goto out;
786+
if (ret < 0) {
787+
return ret;
790788
}
791789
}
792790
}
793791
trace_qemu_vfio_dma_mapped(s, host, iova0, size);
794792
if (iova) {
795793
*iova = iova0;
796794
}
797-
out:
798-
return ret;
795+
return 0;
799796
}
800797

801798
/* Reset the high watermark and free all "temporary" mappings. */

0 commit comments

Comments
 (0)