If we want to add some info to errp (by error_prepend() or error_append_hint()), we must use the ERRP_AUTO_PROPAGATE macro. Otherwise, this info will not be added when errp == &fatal_err (the program will exit prior to the error_append_hint() or error_prepend() call). Fix such cases.
If we want to check error after errp-function call, we need to introduce local_err and than propagate it to errp. Instead, use ERRP_AUTO_PROPAGATE macro, benefits are: 1. No need of explicit error_propagate call 2. No need of explicit local_err variable: use errp directly 3. ERRP_AUTO_PROPAGATE leaves errp as is if it's not NULL or &error_fatel, this means that we don't break error_abort (we'll abort on error_set, not on error_propagate) This commit (together with its neighbors) was generated by for f in $(git grep -l errp \*.[ch]); do \ spatch --sp-file scripts/coccinelle/auto-propagated-errp.cocci \ --macro-file scripts/cocci-macro-file.h --in-place --no-show-diff $f; \ done; then fix a bit of compilation problems: coccinelle for some reason leaves several f() { ... goto out; ... out: } patterns, with "out:" at function end. then ./python/commit-per-subsystem.py MAINTAINERS "$(< auto-msg)" (auto-msg was a file with this commit message) Still, for backporting it may be more comfortable to use only the first command and then do one huge commit. Reported-by: Kevin Wolf <kw...@redhat.com> Reported-by: Greg Kurz <gr...@kaod.org> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsement...@virtuozzo.com> --- memory.c | 63 ++++++++++++++++++++++++-------------------------------- 1 file changed, 27 insertions(+), 36 deletions(-) diff --git a/memory.c b/memory.c index 978da3d3df..b46b5f41e9 100644 --- a/memory.c +++ b/memory.c @@ -1524,17 +1524,16 @@ void memory_region_init_ram_shared_nomigrate(MemoryRegion *mr, bool share, Error **errp) { - Error *err = NULL; + ERRP_AUTO_PROPAGATE(); memory_region_init(mr, owner, name, size); mr->ram = true; mr->terminates = true; mr->destructor = memory_region_destructor_ram; - mr->ram_block = qemu_ram_alloc(size, share, mr, &err); + mr->ram_block = qemu_ram_alloc(size, share, mr, errp); mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; - if (err) { + if (*errp) { mr->size = int128_zero(); object_unparent(OBJECT(mr)); - error_propagate(errp, err); } } @@ -1548,18 +1547,17 @@ void memory_region_init_resizeable_ram(MemoryRegion *mr, void *host), Error **errp) { - Error *err = NULL; + ERRP_AUTO_PROPAGATE(); memory_region_init(mr, owner, name, size); mr->ram = true; mr->terminates = true; mr->destructor = memory_region_destructor_ram; mr->ram_block = qemu_ram_alloc_resizeable(size, max_size, resized, - mr, &err); + mr, errp); mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; - if (err) { + if (*errp) { mr->size = int128_zero(); object_unparent(OBJECT(mr)); - error_propagate(errp, err); } } @@ -1573,18 +1571,17 @@ void memory_region_init_ram_from_file(MemoryRegion *mr, const char *path, Error **errp) { - Error *err = NULL; + ERRP_AUTO_PROPAGATE(); memory_region_init(mr, owner, name, size); mr->ram = true; mr->terminates = true; mr->destructor = memory_region_destructor_ram; mr->align = align; - mr->ram_block = qemu_ram_alloc_from_file(size, mr, ram_flags, path, &err); + mr->ram_block = qemu_ram_alloc_from_file(size, mr, ram_flags, path, errp); mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; - if (err) { + if (*errp) { mr->size = int128_zero(); object_unparent(OBJECT(mr)); - error_propagate(errp, err); } } @@ -1596,19 +1593,18 @@ void memory_region_init_ram_from_fd(MemoryRegion *mr, int fd, Error **errp) { - Error *err = NULL; + ERRP_AUTO_PROPAGATE(); memory_region_init(mr, owner, name, size); mr->ram = true; mr->terminates = true; mr->destructor = memory_region_destructor_ram; mr->ram_block = qemu_ram_alloc_from_fd(size, mr, share ? RAM_SHARED : 0, - fd, &err); + fd, errp); mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; - if (err) { + if (*errp) { mr->size = int128_zero(); object_unparent(OBJECT(mr)); - error_propagate(errp, err); } } #endif @@ -1667,18 +1663,17 @@ void memory_region_init_rom_nomigrate(MemoryRegion *mr, uint64_t size, Error **errp) { - Error *err = NULL; + ERRP_AUTO_PROPAGATE(); memory_region_init(mr, owner, name, size); mr->ram = true; mr->readonly = true; mr->terminates = true; mr->destructor = memory_region_destructor_ram; - mr->ram_block = qemu_ram_alloc(size, false, mr, &err); + mr->ram_block = qemu_ram_alloc(size, false, mr, errp); mr->dirty_log_mask = tcg_enabled() ? (1 << DIRTY_MEMORY_CODE) : 0; - if (err) { + if (*errp) { mr->size = int128_zero(); object_unparent(OBJECT(mr)); - error_propagate(errp, err); } } @@ -1690,7 +1685,7 @@ void memory_region_init_rom_device_nomigrate(MemoryRegion *mr, uint64_t size, Error **errp) { - Error *err = NULL; + ERRP_AUTO_PROPAGATE(); assert(ops); memory_region_init(mr, owner, name, size); mr->ops = ops; @@ -1698,11 +1693,10 @@ void memory_region_init_rom_device_nomigrate(MemoryRegion *mr, mr->terminates = true; mr->rom_device = true; mr->destructor = memory_region_destructor_ram; - mr->ram_block = qemu_ram_alloc(size, false, mr, &err); - if (err) { + mr->ram_block = qemu_ram_alloc(size, false, mr, errp); + if (*errp) { mr->size = int128_zero(); object_unparent(OBJECT(mr)); - error_propagate(errp, err); } } @@ -3162,12 +3156,11 @@ void memory_region_init_ram(MemoryRegion *mr, uint64_t size, Error **errp) { + ERRP_AUTO_PROPAGATE(); DeviceState *owner_dev; - Error *err = NULL; - memory_region_init_ram_nomigrate(mr, owner, name, size, &err); - if (err) { - error_propagate(errp, err); + memory_region_init_ram_nomigrate(mr, owner, name, size, errp); + if (*errp) { return; } /* This will assert if owner is neither NULL nor a DeviceState. @@ -3186,12 +3179,11 @@ void memory_region_init_rom(MemoryRegion *mr, uint64_t size, Error **errp) { + ERRP_AUTO_PROPAGATE(); DeviceState *owner_dev; - Error *err = NULL; - memory_region_init_rom_nomigrate(mr, owner, name, size, &err); - if (err) { - error_propagate(errp, err); + memory_region_init_rom_nomigrate(mr, owner, name, size, errp); + if (*errp) { return; } /* This will assert if owner is neither NULL nor a DeviceState. @@ -3212,13 +3204,12 @@ void memory_region_init_rom_device(MemoryRegion *mr, uint64_t size, Error **errp) { + ERRP_AUTO_PROPAGATE(); DeviceState *owner_dev; - Error *err = NULL; memory_region_init_rom_device_nomigrate(mr, owner, ops, opaque, - name, size, &err); - if (err) { - error_propagate(errp, err); + name, size, errp); + if (*errp) { return; } /* This will assert if owner is neither NULL nor a DeviceState. -- 2.21.0