From nobody Tue Nov 4 18:40:43 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1530608879037275.47590899615955; Tue, 3 Jul 2018 02:07:59 -0700 (PDT) Received: from localhost ([::1]:38985 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faHHt-0004Zs-UF for importer@patchew.org; Tue, 03 Jul 2018 05:07:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:53063) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1faH4Z-0001Rl-42 for qemu-devel@nongnu.org; Tue, 03 Jul 2018 04:54:09 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1faH4W-0007Ew-B0 for qemu-devel@nongnu.org; Tue, 03 Jul 2018 04:54:07 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:51400 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1faH4W-0007EP-5L for qemu-devel@nongnu.org; Tue, 03 Jul 2018 04:54:04 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B358640267CE; Tue, 3 Jul 2018 08:54:03 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-126.ams2.redhat.com [10.36.116.126]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 86573202704E; Tue, 3 Jul 2018 08:54:03 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id F0B081132BC4; Tue, 3 Jul 2018 10:53:58 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Tue, 3 Jul 2018 10:53:52 +0200 Message-Id: <20180703085358.13941-27-armbru@redhat.com> In-Reply-To: <20180703085358.13941-1-armbru@redhat.com> References: <20180703085358.13941-1-armbru@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 03 Jul 2018 08:54:03 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.6]); Tue, 03 Jul 2018 08:54:03 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'armbru@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v2 26/32] qmp: Simplify monitor_qmp_respond() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mdroth@linux.vnet.ibm.com, stefanha@redhat.com, peterx@redhat.com, dgilbert@redhat.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" monitor_qmp_respond() takes both a response object and an error object. If an error object is non-null, the response object must be null, and the response is built from the error object. Of the two callers, one always passes a null response object, and one a null error object. Move building the response object from the error object to the latter, and drop the error object parameter. Signed-off-by: Markus Armbruster Reviewed-by: Eric Blake --- monitor.c | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/monitor.c b/monitor.c index ba3124514c..876a3a23a7 100644 --- a/monitor.c +++ b/monitor.c @@ -4099,18 +4099,12 @@ static int monitor_can_read(void *opaque) } =20 /* - * 1. This function takes ownership of rsp, err, and id. - * 2. rsp, err, and id may be NULL. - * 3. If err !=3D NULL then rsp must be NULL. + * Emit QMP response @rsp with ID @id to @mon. + * Null @rsp can only happen for commands with QCO_NO_SUCCESS_RESP. + * Nothing is emitted then. */ -static void monitor_qmp_respond(Monitor *mon, QDict *rsp, - Error *err, QObject *id) +static void monitor_qmp_respond(Monitor *mon, QDict *rsp, QObject *id) { - if (err) { - assert(!rsp); - rsp =3D qmp_error_response(err); - } - if (rsp) { if (id) { qdict_put_obj(rsp, "id", qobject_ref(id)); @@ -4118,9 +4112,6 @@ static void monitor_qmp_respond(Monitor *mon, QDict *= rsp, =20 qmp_queue_response(mon, rsp); } - - qobject_unref(id); - qobject_unref(rsp); } =20 static void monitor_qmp_dispatch(Monitor *mon, QObject *req, QObject *id) @@ -4148,8 +4139,8 @@ static void monitor_qmp_dispatch(Monitor *mon, QObjec= t *req, QObject *id) } } =20 - /* Respond if necessary */ - monitor_qmp_respond(mon, rsp, NULL, qobject_ref(id)); + monitor_qmp_respond(mon, rsp, id); + qobject_unref(rsp); } =20 /* @@ -4192,6 +4183,7 @@ static QMPRequest *monitor_qmp_requests_pop_any(void) static void monitor_qmp_bh_dispatcher(void *data) { QMPRequest *req_obj =3D monitor_qmp_requests_pop_any(); + QDict *rsp; =20 if (!req_obj) { return; @@ -4202,7 +4194,9 @@ static void monitor_qmp_bh_dispatcher(void *data) monitor_qmp_dispatch(req_obj->mon, req_obj->req, req_obj->id); } else { assert(req_obj->err); - monitor_qmp_respond(req_obj->mon, NULL, req_obj->err, NULL); + rsp =3D qmp_error_response(req_obj->err); + monitor_qmp_respond(req_obj->mon, rsp, NULL); + qobject_unref(rsp); } =20 if (req_obj->need_resume) { --=20 2.17.1