Skip to content

Commit 453095e

Browse files
philmdstefanhaRH
authored andcommitted
util/vfio-helpers: Use error_setg in qemu_vfio_find_[fixed/temp]_iova
Both qemu_vfio_find_fixed_iova() and qemu_vfio_find_temp_iova() return an errno which is unused (or overwritten). Have them propagate eventual errors to callers, returning a boolean (which is what the Error API recommends, see commit e3fe398 "error: Document Error API usage rules" for rationale). Suggested-by: Klaus Jensen <[email protected]> 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 71e3038 commit 453095e

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

util/vfio-helpers.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -677,8 +677,8 @@ static bool qemu_vfio_verify_mappings(QEMUVFIOState *s)
677677
return true;
678678
}
679679

680-
static int
681-
qemu_vfio_find_fixed_iova(QEMUVFIOState *s, size_t size, uint64_t *iova)
680+
static bool qemu_vfio_find_fixed_iova(QEMUVFIOState *s, size_t size,
681+
uint64_t *iova, Error **errp)
682682
{
683683
int i;
684684

@@ -693,14 +693,16 @@ qemu_vfio_find_fixed_iova(QEMUVFIOState *s, size_t size, uint64_t *iova)
693693
s->usable_iova_ranges[i].end - s->low_water_mark + 1 == 0) {
694694
*iova = s->low_water_mark;
695695
s->low_water_mark += size;
696-
return 0;
696+
return true;
697697
}
698698
}
699-
return -ENOMEM;
699+
error_setg(errp, "fixed iova range not found");
700+
701+
return false;
700702
}
701703

702-
static int
703-
qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t size, uint64_t *iova)
704+
static bool qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t size,
705+
uint64_t *iova, Error **errp)
704706
{
705707
int i;
706708

@@ -715,10 +717,12 @@ qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t size, uint64_t *iova)
715717
s->high_water_mark - s->usable_iova_ranges[i].start + 1 == 0) {
716718
*iova = s->high_water_mark - size;
717719
s->high_water_mark = *iova;
718-
return 0;
720+
return true;
719721
}
720722
}
721-
return -ENOMEM;
723+
error_setg(errp, "temporary iova range not found");
724+
725+
return false;
722726
}
723727

724728
/**
@@ -762,7 +766,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
762766
goto out;
763767
}
764768
if (!temporary) {
765-
if (qemu_vfio_find_fixed_iova(s, size, &iova0)) {
769+
if (!qemu_vfio_find_fixed_iova(s, size, &iova0, errp)) {
766770
ret = -ENOMEM;
767771
goto out;
768772
}
@@ -776,7 +780,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
776780
}
777781
qemu_vfio_dump_mappings(s);
778782
} else {
779-
if (qemu_vfio_find_temp_iova(s, size, &iova0)) {
783+
if (!qemu_vfio_find_temp_iova(s, size, &iova0, errp)) {
780784
ret = -ENOMEM;
781785
goto out;
782786
}

0 commit comments

Comments
 (0)