misc: Simplify qemu_prealloc_mem() calls

Since qemu_prealloc_mem() returns whether or not an error
occured, we don't need to check the @errp pointer. Remove
local_err uses when we can return directly.

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Manos Pitsidianakis <manos.pitsidianakis@linaro.org>
Reviewed-by: Gavin Shan <gshan@redhat.com>
Message-Id: <20231120213301.24349-20-philmd@linaro.org>
This commit is contained in:
Philippe Mathieu-Daudé 2023-11-20 15:32:57 +01:00
parent b622ee98bf
commit 9c878ad6fb
2 changed files with 9 additions and 19 deletions

View File

@ -219,7 +219,6 @@ static bool host_memory_backend_get_prealloc(Object *obj, Error **errp)
static void host_memory_backend_set_prealloc(Object *obj, bool value, static void host_memory_backend_set_prealloc(Object *obj, bool value,
Error **errp) Error **errp)
{ {
Error *local_err = NULL;
HostMemoryBackend *backend = MEMORY_BACKEND(obj); HostMemoryBackend *backend = MEMORY_BACKEND(obj);
if (!backend->reserve && value) { if (!backend->reserve && value) {
@ -237,10 +236,8 @@ static void host_memory_backend_set_prealloc(Object *obj, bool value,
void *ptr = memory_region_get_ram_ptr(&backend->mr); void *ptr = memory_region_get_ram_ptr(&backend->mr);
uint64_t sz = memory_region_size(&backend->mr); uint64_t sz = memory_region_size(&backend->mr);
qemu_prealloc_mem(fd, ptr, sz, backend->prealloc_threads, if (!qemu_prealloc_mem(fd, ptr, sz, backend->prealloc_threads,
backend->prealloc_context, &local_err); backend->prealloc_context, errp)) {
if (local_err) {
error_propagate(errp, local_err);
return; return;
} }
backend->prealloc = true; backend->prealloc = true;
@ -398,16 +395,11 @@ host_memory_backend_memory_complete(UserCreatable *uc, Error **errp)
* This is necessary to guarantee memory is allocated with * This is necessary to guarantee memory is allocated with
* specified NUMA policy in place. * specified NUMA policy in place.
*/ */
if (backend->prealloc) { if (backend->prealloc && !qemu_prealloc_mem(memory_region_get_fd(&backend->mr),
Error *local_err = NULL; ptr, sz,
backend->prealloc_threads,
qemu_prealloc_mem(memory_region_get_fd(&backend->mr), ptr, sz, backend->prealloc_context, errp)) {
backend->prealloc_threads, return;
backend->prealloc_context, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return;
}
} }
} }

View File

@ -605,8 +605,7 @@ static int virtio_mem_set_block_state(VirtIOMEM *vmem, uint64_t start_gpa,
int fd = memory_region_get_fd(&vmem->memdev->mr); int fd = memory_region_get_fd(&vmem->memdev->mr);
Error *local_err = NULL; Error *local_err = NULL;
qemu_prealloc_mem(fd, area, size, 1, NULL, &local_err); if (!qemu_prealloc_mem(fd, area, size, 1, NULL, &local_err)) {
if (local_err) {
static bool warned; static bool warned;
/* /*
@ -1249,8 +1248,7 @@ static int virtio_mem_prealloc_range_cb(VirtIOMEM *vmem, void *arg,
int fd = memory_region_get_fd(&vmem->memdev->mr); int fd = memory_region_get_fd(&vmem->memdev->mr);
Error *local_err = NULL; Error *local_err = NULL;
qemu_prealloc_mem(fd, area, size, 1, NULL, &local_err); if (!qemu_prealloc_mem(fd, area, size, 1, NULL, &local_err)) {
if (local_err) {
error_report_err(local_err); error_report_err(local_err);
return -ENOMEM; return -ENOMEM;
} }