From nobody Thu Nov 6 06:16:06 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 1539605715704796.5535818716405; Mon, 15 Oct 2018 05:15:15 -0700 (PDT) Received: from localhost ([::1]:51923 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gC1mE-0003ff-Dl for importer@patchew.org; Mon, 15 Oct 2018 08:15:14 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39664) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gC1RD-0004GX-5z for qemu-devel@nongnu.org; Mon, 15 Oct 2018 07:53:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gC1RB-0002B8-2O for qemu-devel@nongnu.org; Mon, 15 Oct 2018 07:53:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:57268) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gC1R9-00020Z-4x for qemu-devel@nongnu.org; Mon, 15 Oct 2018 07:53:27 -0400 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B0A8F8553D for ; Mon, 15 Oct 2018 11:53:17 +0000 (UTC) Received: from blackfin.pond.sub.org (ovpn-116-50.ams2.redhat.com [10.36.116.50]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7ADCC2B4AE for ; Mon, 15 Oct 2018 11:53:17 +0000 (UTC) Received: by blackfin.pond.sub.org (Postfix, from userid 1000) id 0108B1153BCB; Mon, 15 Oct 2018 13:53:10 +0200 (CEST) From: Markus Armbruster To: qemu-devel@nongnu.org Date: Mon, 15 Oct 2018 13:52:57 +0200 Message-Id: <20181015115309.17089-24-armbru@redhat.com> In-Reply-To: <20181015115309.17089-1-armbru@redhat.com> References: <20181015115309.17089-1-armbru@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Mon, 15 Oct 2018 11:53:17 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH v2 23/35] vl: Clean up error reporting in parse_fw_cfg() 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: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RDMRC_1 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Calling error_report() in a function that takes an Error ** argument is suspicious. parse_fw_cfg() does that, and then fails without setting an error. Its caller main(), via qemu_opts_foreach(), is fine with it, but clean it up anyway. Signed-off-by: Markus Armbruster Reviewed-by: Marc-Andr=C3=A9 Lureau --- vl.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/vl.c b/vl.c index cd8e8a6586..c5bc54f72b 100644 --- a/vl.c +++ b/vl.c @@ -2174,7 +2174,7 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts,= Error **errp) FWCfgState *fw_cfg =3D (FWCfgState *) opaque; =20 if (fw_cfg =3D=3D NULL) { - error_report("fw_cfg device not available"); + error_setg(errp, "fw_cfg device not available"); return -1; } name =3D qemu_opt_get(opts, "name"); @@ -2183,15 +2183,16 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opt= s, Error **errp) =20 /* we need name and either a file or the content string */ if (!(nonempty_str(name) && (nonempty_str(file) || nonempty_str(str)))= ) { - error_report("invalid argument(s)"); + error_setg(errp, "invalid argument(s)"); return -1; } if (nonempty_str(file) && nonempty_str(str)) { - error_report("file and string are mutually exclusive"); + error_setg(errp, "file and string are mutually exclusive"); return -1; } if (strlen(name) > FW_CFG_MAX_FILE_PATH - 1) { - error_report("name too long (max. %d char)", FW_CFG_MAX_FILE_PATH = - 1); + error_setg(errp, "name too long (max. %d char)", + FW_CFG_MAX_FILE_PATH - 1); return -1; } if (strncmp(name, "opt/", 4) !=3D 0) { @@ -2203,7 +2204,7 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts,= Error **errp) buf =3D g_memdup(str, size); } else { if (!g_file_get_contents(file, &buf, &size, NULL)) { - error_report("can't load %s", file); + error_setg(errp, "can't load %s", file); return -1; } } @@ -4476,10 +4477,8 @@ int main(int argc, char **argv, char **envp) hax_sync_vcpus(); } =20 - if (qemu_opts_foreach(qemu_find_opts("fw_cfg"), - parse_fw_cfg, fw_cfg_find(), NULL) !=3D 0) { - exit(1); - } + qemu_opts_foreach(qemu_find_opts("fw_cfg"), + parse_fw_cfg, fw_cfg_find(), &error_fatal); =20 /* init USB devices */ if (machine_usb(current_machine)) { --=20 2.17.1