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> --- ui/input-barrier.c | 7 +++---- ui/input.c | 14 ++++++-------- ui/vnc.c | 19 ++++++++----------- 3 files changed, 17 insertions(+), 23 deletions(-) diff --git a/ui/input-barrier.c b/ui/input-barrier.c index a2c961f285..cce1cf35c3 100644 --- a/ui/input-barrier.c +++ b/ui/input-barrier.c @@ -492,8 +492,8 @@ static gboolean input_barrier_event(QIOChannel *ioc G_GNUC_UNUSED, static void input_barrier_complete(UserCreatable *uc, Error **errp) { + ERRP_AUTO_PROPAGATE(); InputBarrier *ib = INPUT_BARRIER(uc); - Error *local_err = NULL; if (!ib->name) { error_setg(errp, QERR_MISSING_PARAMETER, "name"); @@ -509,9 +509,8 @@ static void input_barrier_complete(UserCreatable *uc, Error **errp) ib->sioc = qio_channel_socket_new(); qio_channel_set_name(QIO_CHANNEL(ib->sioc), "barrier-client"); - qio_channel_socket_connect_sync(ib->sioc, &ib->saddr, &local_err); - if (local_err) { - error_propagate(errp, local_err); + qio_channel_socket_connect_sync(ib->sioc, &ib->saddr, errp); + if (*errp) { return; } diff --git a/ui/input.c b/ui/input.c index 4791b089c7..bea1745a33 100644 --- a/ui/input.c +++ b/ui/input.c @@ -87,12 +87,11 @@ void qemu_input_handler_bind(QemuInputHandlerState *s, const char *device_id, int head, Error **errp) { + ERRP_AUTO_PROPAGATE(); QemuConsole *con; - Error *err = NULL; - con = qemu_console_lookup_by_device_name(device_id, head, &err); - if (err) { - error_propagate(errp, err); + con = qemu_console_lookup_by_device_name(device_id, head, errp); + if (*errp) { return; } @@ -128,18 +127,17 @@ void qmp_input_send_event(bool has_device, const char *device, bool has_head, int64_t head, InputEventList *events, Error **errp) { + ERRP_AUTO_PROPAGATE(); InputEventList *e; QemuConsole *con; - Error *err = NULL; con = NULL; if (has_device) { if (!has_head) { head = 0; } - con = qemu_console_lookup_by_device_name(device, head, &err); - if (err) { - error_propagate(errp, err); + con = qemu_console_lookup_by_device_name(device, head, errp); + if (*errp) { return; } } diff --git a/ui/vnc.c b/ui/vnc.c index 4100d6e404..0354d30168 100644 --- a/ui/vnc.c +++ b/ui/vnc.c @@ -3795,6 +3795,7 @@ static int vnc_display_listen(VncDisplay *vd, void vnc_display_open(const char *id, Error **errp) { + ERRP_AUTO_PROPAGATE(); VncDisplay *vd = vnc_display_find(id); QemuOpts *opts = qemu_opts_find(&qemu_vnc_opts, id); SocketAddress **saddr = NULL, **wsaddr = NULL; @@ -4008,11 +4009,9 @@ void vnc_display_open(const char *id, Error **errp) device_id = qemu_opt_get(opts, "display"); if (device_id) { int head = qemu_opt_get_number(opts, "head", 0); - Error *err = NULL; - con = qemu_console_lookup_by_device_name(device_id, head, &err); - if (err) { - error_propagate(errp, err); + con = qemu_console_lookup_by_device_name(device_id, head, errp); + if (*errp) { goto fail; } } else { @@ -4106,18 +4105,16 @@ QemuOpts *vnc_parse(const char *str, Error **errp) int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp) { - Error *local_err = NULL; + ERRP_AUTO_PROPAGATE(); char *id = (char *)qemu_opts_id(opts); assert(id); - vnc_display_init(id, &local_err); - if (local_err) { - error_propagate(errp, local_err); + vnc_display_init(id, errp); + if (*errp) { return -1; } - vnc_display_open(id, &local_err); - if (local_err != NULL) { - error_propagate(errp, local_err); + vnc_display_open(id, errp); + if (*errp) { return -1; } return 0; -- 2.21.0