From d3226035630c6f0805ed26c77011e49565029cb0 Mon Sep 17 00:00:00 2001 From: Markus Armbruster Date: Tue, 17 Mar 2020 12:54:47 +0100 Subject: [PATCH] qapi: Simplify how qmp_dispatch() deals with QCO_NO_SUCCESS_RESP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Markus Armbruster Reviewed-by: Marc-André Lureau Message-Id: <20200317115459.31821-23-armbru@redhat.com> --- qapi/qmp-dispatch.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/qapi/qmp-dispatch.c b/qapi/qmp-dispatch.c index a588072523..550d1fe8d2 100644 --- a/qapi/qmp-dispatch.c +++ b/qapi/qmp-dispatch.c @@ -106,7 +106,7 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *request, QDict *dict = qobject_to(QDict, request); QObject *id = dict ? qdict_get(dict, "id") : NULL; QObject *ret = NULL; - QDict *rsp; + QDict *rsp = NULL; dict = qmp_dispatch_check_obj(request, allow_oob, &err); if (!dict) { @@ -151,31 +151,32 @@ QDict *qmp_dispatch(QmpCommandList *cmds, QObject *request, args = qdict_get_qdict(dict, "arguments"); qobject_ref(args); } - cmd->fn(args, &ret, &err); + qobject_unref(args); if (err) { - ; - } else if (cmd->options & QCO_NO_SUCCESS_RESP) { + goto out; + } + + if (cmd->options & QCO_NO_SUCCESS_RESP) { g_assert(!ret); + return NULL; } else if (!ret) { /* TODO turn into assertion */ ret = QOBJECT(qdict_new()); } - qobject_unref(args); + rsp = qdict_new(); + qdict_put_obj(rsp, "return", ret); out: if (err) { + assert(!rsp); rsp = qmp_error_response(err); - } else if (ret) { - rsp = qdict_new(); - qdict_put_obj(rsp, "return", ret); - } else { - /* Can only happen for commands with QCO_NO_SUCCESS_RESP */ - rsp = NULL; } - if (rsp && id) { + assert(rsp); + + if (id) { qdict_put_obj(rsp, "id", qobject_ref(id)); }