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 e3fe3988d7
"error: Document Error
API usage rules" for rationale).
Suggested-by: Klaus Jensen <k.jensen@samsung.com>
Reviewed-by: Klaus Jensen <k.jensen@samsung.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-id: 20210902070025.197072-9-philmd@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
parent
71e3038c15
commit
453095e98d
@ -677,8 +677,8 @@ static bool qemu_vfio_verify_mappings(QEMUVFIOState *s)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static bool qemu_vfio_find_fixed_iova(QEMUVFIOState *s, size_t size,
|
||||||
qemu_vfio_find_fixed_iova(QEMUVFIOState *s, size_t size, uint64_t *iova)
|
uint64_t *iova, Error **errp)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -693,14 +693,16 @@ qemu_vfio_find_fixed_iova(QEMUVFIOState *s, size_t size, uint64_t *iova)
|
|||||||
s->usable_iova_ranges[i].end - s->low_water_mark + 1 == 0) {
|
s->usable_iova_ranges[i].end - s->low_water_mark + 1 == 0) {
|
||||||
*iova = s->low_water_mark;
|
*iova = s->low_water_mark;
|
||||||
s->low_water_mark += size;
|
s->low_water_mark += size;
|
||||||
return 0;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -ENOMEM;
|
error_setg(errp, "fixed iova range not found");
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static bool qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t size,
|
||||||
qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t size, uint64_t *iova)
|
uint64_t *iova, Error **errp)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -715,10 +717,12 @@ qemu_vfio_find_temp_iova(QEMUVFIOState *s, size_t size, uint64_t *iova)
|
|||||||
s->high_water_mark - s->usable_iova_ranges[i].start + 1 == 0) {
|
s->high_water_mark - s->usable_iova_ranges[i].start + 1 == 0) {
|
||||||
*iova = s->high_water_mark - size;
|
*iova = s->high_water_mark - size;
|
||||||
s->high_water_mark = *iova;
|
s->high_water_mark = *iova;
|
||||||
return 0;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -ENOMEM;
|
error_setg(errp, "temporary iova range not found");
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -762,7 +766,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
|
|||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
if (!temporary) {
|
if (!temporary) {
|
||||||
if (qemu_vfio_find_fixed_iova(s, size, &iova0)) {
|
if (!qemu_vfio_find_fixed_iova(s, size, &iova0, errp)) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
@ -776,7 +780,7 @@ int qemu_vfio_dma_map(QEMUVFIOState *s, void *host, size_t size,
|
|||||||
}
|
}
|
||||||
qemu_vfio_dump_mappings(s);
|
qemu_vfio_dump_mappings(s);
|
||||||
} else {
|
} else {
|
||||||
if (qemu_vfio_find_temp_iova(s, size, &iova0)) {
|
if (!qemu_vfio_find_temp_iova(s, size, &iova0, errp)) {
|
||||||
ret = -ENOMEM;
|
ret = -ENOMEM;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user