From 05e385d2a96325c1f26b874f1b832237229b8c1f Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 21 Nov 2022 09:50:47 +0100 Subject: error: Move ERRP_GUARD() to the beginning of the function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit include/qapi/error.h advises to put ERRP_GUARD() right at the beginning of the function, because only then can it guard the whole function. Clean up the few spots disregarding the advice. Signed-off-by: Markus Armbruster Message-Id: <20221121085054.683122-4-armbru@redhat.com> Reviewed-by: Philippe Mathieu-Daudé --- monitor/qmp-cmds.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'monitor') diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c index 81c8fdadf8..686d562cad 100644 --- a/monitor/qmp-cmds.c +++ b/monitor/qmp-cmds.c @@ -474,9 +474,9 @@ static bool invoke_stats_cb(StatsCallbacks *entry, StatsFilter *filter, StatsRequest *request, Error **errp) { + ERRP_GUARD(); strList *targets = NULL; strList *names = NULL; - ERRP_GUARD(); if (request) { if (request->provider != entry->provider) { @@ -541,9 +541,9 @@ StatsSchemaList *qmp_query_stats_schemas(bool has_provider, StatsProvider provider, Error **errp) { + ERRP_GUARD(); StatsSchemaList *stats_results = NULL; StatsCallbacks *entry; - ERRP_GUARD(); QTAILQ_FOREACH(entry, &stats_callbacks, next) { if (!has_provider || provider == entry->provider) { -- cgit v1.2.3 From 457552fc7d7ff2042e23884ab189ccc216778963 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 21 Nov 2022 09:50:48 +0100 Subject: monitor: Simplify monitor_fd_param()'s error handling Cc: Dr. David Alan Gilbert Signed-off-by: Markus Armbruster Message-Id: <20221121085054.683122-5-armbru@redhat.com> --- monitor/misc.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'monitor') diff --git a/monitor/misc.c b/monitor/misc.c index 205487e2b9..83d7f4ffde 100644 --- a/monitor/misc.c +++ b/monitor/misc.c @@ -1086,6 +1086,7 @@ int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp) } fd = monfd->fd; + assert(fd >= 0); /* caller takes ownership of fd */ QLIST_REMOVE(monfd, next); @@ -1403,23 +1404,16 @@ void monitor_fdset_dup_fd_remove(int dup_fd) int monitor_fd_param(Monitor *mon, const char *fdname, Error **errp) { int fd; - Error *local_err = NULL; if (!qemu_isdigit(fdname[0]) && mon) { - fd = monitor_get_fd(mon, fdname, &local_err); + fd = monitor_get_fd(mon, fdname, errp); } else { fd = qemu_parse_fd(fdname); - if (fd == -1) { - error_setg(&local_err, "Invalid file descriptor number '%s'", + if (fd < 0) { + error_setg(errp, "Invalid file descriptor number '%s'", fdname); } } - if (local_err) { - error_propagate(errp, local_err); - assert(fd == -1); - } else { - assert(fd != -1); - } return fd; } -- cgit v1.2.3 From 50707b391ecb35dfdd8c92615bca92b601dc3cf1 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Mon, 21 Nov 2022 09:50:49 +0100 Subject: monitor: Use ERRP_GUARD() in monitor_init() Cc: Dr. David Alan Gilbert Signed-off-by: Markus Armbruster Message-Id: <20221121085054.683122-6-armbru@redhat.com> --- monitor/monitor.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'monitor') diff --git a/monitor/monitor.c b/monitor/monitor.c index 86949024f6..7ed7bd5342 100644 --- a/monitor/monitor.c +++ b/monitor/monitor.c @@ -711,8 +711,8 @@ void monitor_init_globals_core(void) int monitor_init(MonitorOptions *opts, bool allow_hmp, Error **errp) { + ERRP_GUARD(); Chardev *chr; - Error *local_err = NULL; chr = qemu_chr_find(opts->chardev); if (chr == NULL) { @@ -726,7 +726,7 @@ int monitor_init(MonitorOptions *opts, bool allow_hmp, Error **errp) switch (opts->mode) { case MONITOR_MODE_CONTROL: - monitor_init_qmp(chr, opts->pretty, &local_err); + monitor_init_qmp(chr, opts->pretty, errp); break; case MONITOR_MODE_READLINE: if (!allow_hmp) { @@ -737,17 +737,13 @@ int monitor_init(MonitorOptions *opts, bool allow_hmp, Error **errp) error_setg(errp, "'pretty' is not compatible with HMP monitors"); return -1; } - monitor_init_hmp(chr, true, &local_err); + monitor_init_hmp(chr, true, errp); break; default: g_assert_not_reached(); } - if (local_err) { - error_propagate(errp, local_err); - return -1; - } - return 0; + return *errp ? -1 : 0; } int monitor_init_opts(QemuOpts *opts, Error **errp) -- cgit v1.2.3