qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[RFC v5 069/126] chardev: introduce ERRP_AUTO_PROPAGATE


From: Vladimir Sementsov-Ogievskiy
Subject: [RFC v5 069/126] chardev: introduce ERRP_AUTO_PROPAGATE
Date: Fri, 11 Oct 2019 19:04:55 +0300

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 <address@hidden>
Reported-by: Greg Kurz <address@hidden>
Signed-off-by: Vladimir Sementsov-Ogievskiy <address@hidden>
---
 chardev/char-socket.c |  7 +++----
 chardev/char.c        | 20 +++++++++-----------
 chardev/spice.c       |  1 +
 3 files changed, 13 insertions(+), 15 deletions(-)

diff --git a/chardev/char-socket.c b/chardev/char-socket.c
index 185fe38dda..75649630d3 100644
--- a/chardev/char-socket.c
+++ b/chardev/char-socket.c
@@ -963,6 +963,7 @@ static void tcp_chr_accept_server_sync(Chardev *chr)
 
 static int tcp_chr_wait_connected(Chardev *chr, Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     SocketChardev *s = SOCKET_CHARDEV(chr);
     const char *opts[] = { "telnet", "tn3270", "websock", "tls-creds" };
     bool optset[] = { s->is_telnet, s->is_tn3270, s->is_websock, s->tls_creds 
};
@@ -1031,13 +1032,11 @@ static int tcp_chr_wait_connected(Chardev *chr, Error 
**errp)
         if (s->is_listen) {
             tcp_chr_accept_server_sync(chr);
         } else {
-            Error *err = NULL;
-            if (tcp_chr_connect_client_sync(chr, &err) < 0) {
+            if (tcp_chr_connect_client_sync(chr, errp) < 0) {
                 if (s->reconnect_time) {
-                    error_free(err);
+                    error_free_errp(errp);
                     g_usleep(s->reconnect_time * 1000ULL * 1000ULL);
                 } else {
-                    error_propagate(errp, err);
                     return -1;
                 }
             }
diff --git a/chardev/char.c b/chardev/char.c
index 7b6b2cb123..49eb5ffe06 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -603,7 +603,7 @@ static const char *chardev_alias_translate(const char *name)
 
 ChardevBackend *qemu_chr_parse_opts(QemuOpts *opts, Error **errp)
 {
-    Error *local_err = NULL;
+    ERRP_AUTO_PROPAGATE();
     const ChardevClass *cc;
     ChardevBackend *backend = NULL;
     const char *name = chardev_alias_translate(qemu_opt_get(opts, "backend"));
@@ -623,9 +623,8 @@ ChardevBackend *qemu_chr_parse_opts(QemuOpts *opts, Error 
**errp)
     backend->type = CHARDEV_BACKEND_KIND_NULL;
 
     if (cc->parse) {
-        cc->parse(opts, backend, &local_err);
-        if (local_err) {
-            error_propagate(errp, local_err);
+        cc->parse(opts, backend, errp);
+        if (*errp) {
             qapi_free_ChardevBackend(backend);
             return NULL;
         }
@@ -949,9 +948,9 @@ Chardev *qemu_chardev_new(const char *id, const char 
*typename,
                           GMainContext *gcontext,
                           Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     Object *obj;
     Chardev *chr = NULL;
-    Error *local_err = NULL;
     bool be_opened = true;
 
     assert(g_str_has_prefix(typename, "chardev-"));
@@ -961,8 +960,8 @@ Chardev *qemu_chardev_new(const char *id, const char 
*typename,
     chr->label = g_strdup(id);
     chr->gcontext = gcontext;
 
-    qemu_char_open(chr, backend, &be_opened, &local_err);
-    if (local_err) {
+    qemu_char_open(chr, backend, &be_opened, errp);
+    if (*errp) {
         goto end;
     }
 
@@ -974,16 +973,15 @@ Chardev *qemu_chardev_new(const char *id, const char 
*typename,
     }
 
     if (id) {
-        object_property_add_child(get_chardevs_root(), id, obj, &local_err);
-        if (local_err) {
+        object_property_add_child(get_chardevs_root(), id, obj, errp);
+        if (*errp) {
             goto end;
         }
         object_unref(obj);
     }
 
 end:
-    if (local_err) {
-        error_propagate(errp, local_err);
+    if (*errp) {
         object_unref(obj);
         return NULL;
     }
diff --git a/chardev/spice.c b/chardev/spice.c
index 241e2b7770..ce2145fb19 100644
--- a/chardev/spice.c
+++ b/chardev/spice.c
@@ -267,6 +267,7 @@ static void qemu_chr_open_spice_vmc(Chardev *chr,
                                     bool *be_opened,
                                     Error **errp)
 {
+    ERRP_AUTO_PROPAGATE();
     ChardevSpiceChannel *spicevmc = backend->u.spicevmc.data;
     const char *type = spicevmc->type;
     const char **psubtype = spice_server_char_device_recognized_subtypes();
-- 
2.21.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]