From nobody Fri Nov 14 18:23:12 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=yandex-team.ru ARC-Seal: i=1; a=rsa-sha256; t=1761656922; cv=none; d=zohomail.com; s=zohoarc; b=gx/7mVRrZCiCGloGExewjXlo7HWOBw6g2IQ4+ZTps4wEyIukxBdww6QjtG66utN+tEl0wsT/mWIX3wtkUW3jrjPBYLzOj12YDFFQ15ikrOgBjBpVHeO8WkpyzB1QUklTiHfYpf+1SiKt4qly1y9/DLXiZ4lMj+X//7IIrquvPZk= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1761656922; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=87rM9PFrFHIqtwWn9a7lbC9w3iiM+mfRmmZFaEhia+s=; b=caiVurh6eWBcbi4OtkCE+6lR2JKJSYR82YVhzKxSmAVbatjKUl9jDT1XmYFElKdSWVaIThbVdneY9gJvOgymVfVZo2OVw+CaTbo+Nnxc07STtYd+3uT3wFQWFsB6uAmIC7b6nTSUQ3Lo0tDle4w+PE4a+ubhds8p+VxfS2Dxg2I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1761656922096279.66985874541786; Tue, 28 Oct 2025 06:08:42 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1vDjQp-0000N9-KC; Tue, 28 Oct 2025 09:08:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vDjQb-0000JT-Q3 for qemu-devel@nongnu.org; Tue, 28 Oct 2025 09:07:58 -0400 Received: from forwardcorp1a.mail.yandex.net ([2a02:6b8:c0e:500:1:45:d181:df01]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1vDjQT-0000v7-DL for qemu-devel@nongnu.org; Tue, 28 Oct 2025 09:07:57 -0400 Received: from mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net [IPv6:2a02:6b8:c2d:7394:0:640:5a8a:0]) by forwardcorp1a.mail.yandex.net (Yandex) with ESMTPS id 177F3C02A2; Tue, 28 Oct 2025 16:07:43 +0300 (MSK) Received: from vsementsov-lin.. (unknown [2a02:6bf:8080:582::1:19]) by mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id d7duxl1L2qM0-znihA1Fe; Tue, 28 Oct 2025 16:07:42 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1761656862; bh=87rM9PFrFHIqtwWn9a7lbC9w3iiM+mfRmmZFaEhia+s=; h=Message-ID:Date:In-Reply-To:Cc:Subject:References:To:From; b=Ma+o84lMocB0H2QH8+L45fh8N/RqXLrCVlj+AfRrSrKhXt4rZxmI2xlTwxCPZiXbK /4UtuwEpVm7CFsZPiue4R84159sxoIJ5LnLkW6RHC10XA1J4gYcPVUheJzg7TiPWyY qP5H0ZfXycnYZvsziObMU3SKPETjlKhW3BPE5ONc= Authentication-Results: mail-nwsmtp-smtp-corp-main-83.vla.yp-c.yandex.net; dkim=pass header.i=@yandex-team.ru From: Vladimir Sementsov-Ogievskiy To: peterx@redhat.com Cc: stefanb@linux.vnet.ibm.com, farosas@suse.de, qemu-devel@nongnu.org, armbru@redhat.com, berrange@redhat.com, vsementsov@yandex-team.ru, armenon@redhat.com Subject: [PATCH v4 2/2] tmp_emulator: improve and fix use of errp Date: Tue, 28 Oct 2025 16:07:38 +0300 Message-ID: <20251028130738.29037-3-vsementsov@yandex-team.ru> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251028130738.29037-1-vsementsov@yandex-team.ru> References: <20251028130738.29037-1-vsementsov@yandex-team.ru> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a02:6b8:c0e:500:1:45:d181:df01; envelope-from=vsementsov@yandex-team.ru; helo=forwardcorp1a.mail.yandex.net X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @yandex-team.ru) X-ZM-MESSAGEID: 1761656926895154100 Content-Type: text/plain; charset="utf-8" tpm_emulator_post_load() and tpm_emulator_set_state_blobs() has error paths, where they return negative value, but do not set errp. To fix that, we also have to convert several other functions to set errp instead of error_reporting. Signed-off-by: Vladimir Sementsov-Ogievskiy --- backends/tpm/tpm_emulator.c | 63 +++++++++++++++++++++++-------------- 1 file changed, 39 insertions(+), 24 deletions(-) diff --git a/backends/tpm/tpm_emulator.c b/backends/tpm/tpm_emulator.c index dacfca5ab7..6abe9872e6 100644 --- a/backends/tpm/tpm_emulator.c +++ b/backends/tpm/tpm_emulator.c @@ -308,22 +308,22 @@ static int tpm_emulator_check_caps(TPMEmulator *tpm_e= mu) return 0; } =20 -static int tpm_emulator_stop_tpm(TPMBackend *tb) +static int tpm_emulator_stop_tpm(TPMBackend *tb, Error **errp) { TPMEmulator *tpm_emu =3D TPM_EMULATOR(tb); ptm_res res; =20 if (tpm_emulator_ctrlcmd(tpm_emu, CMD_STOP, &res, 0, sizeof(ptm_res), sizeof(res)) < 0) { - error_report("tpm-emulator: Could not stop TPM: %s", - strerror(errno)); + error_setg(errp, "tpm-emulator: Could not stop TPM: %s", + strerror(errno)); return -1; } =20 res =3D be32_to_cpu(res); if (res) { - error_report("tpm-emulator: TPM result for CMD_STOP: 0x%x %s", res, - tpm_emulator_strerror(res)); + error_setg(errp, "tpm-emulator: TPM result for CMD_STOP: 0x%x %s",= res, + tpm_emulator_strerror(res)); return -1; } =20 @@ -362,12 +362,13 @@ static int tpm_emulator_lock_storage(TPMEmulator *tpm= _emu) =20 static int tpm_emulator_set_buffer_size(TPMBackend *tb, size_t wanted_size, - size_t *actual_size) + size_t *actual_size, + Error **errp) { TPMEmulator *tpm_emu =3D TPM_EMULATOR(tb); ptm_setbuffersize psbs; =20 - if (tpm_emulator_stop_tpm(tb) < 0) { + if (tpm_emulator_stop_tpm(tb, errp) < 0) { return -1; } =20 @@ -376,16 +377,17 @@ static int tpm_emulator_set_buffer_size(TPMBackend *t= b, if (tpm_emulator_ctrlcmd(tpm_emu, CMD_SET_BUFFERSIZE, &psbs, sizeof(psbs.u.req), sizeof(psbs.u.resp.tpm_re= sult), sizeof(psbs.u.resp)) < 0) { - error_report("tpm-emulator: Could not set buffer size: %s", - strerror(errno)); + error_setg(errp, "tpm-emulator: Could not set buffer size: %s", + strerror(errno)); return -1; } =20 psbs.u.resp.tpm_result =3D be32_to_cpu(psbs.u.resp.tpm_result); if (psbs.u.resp.tpm_result !=3D 0) { - error_report("tpm-emulator: TPM result for set buffer size : 0x%x = %s", - psbs.u.resp.tpm_result, - tpm_emulator_strerror(psbs.u.resp.tpm_result)); + error_setg(errp, + "tpm-emulator: TPM result for set buffer size : 0x%x %s= ", + psbs.u.resp.tpm_result, + tpm_emulator_strerror(psbs.u.resp.tpm_result)); return -1; } =20 @@ -402,7 +404,7 @@ static int tpm_emulator_set_buffer_size(TPMBackend *tb, } =20 static int tpm_emulator_startup_tpm_resume(TPMBackend *tb, size_t buffersi= ze, - bool is_resume) + bool is_resume, Error **errp) { TPMEmulator *tpm_emu =3D TPM_EMULATOR(tb); ptm_init init =3D { @@ -413,7 +415,7 @@ static int tpm_emulator_startup_tpm_resume(TPMBackend *= tb, size_t buffersize, trace_tpm_emulator_startup_tpm_resume(is_resume, buffersize); =20 if (buffersize !=3D 0 && - tpm_emulator_set_buffer_size(tb, buffersize, NULL) < 0) { + tpm_emulator_set_buffer_size(tb, buffersize, NULL, errp) < 0) { goto err_exit; } =20 @@ -424,15 +426,15 @@ static int tpm_emulator_startup_tpm_resume(TPMBackend= *tb, size_t buffersize, if (tpm_emulator_ctrlcmd(tpm_emu, CMD_INIT, &init, sizeof(init), sizeof(init.u.resp.tpm_result), sizeof(init)) < 0) { - error_report("tpm-emulator: could not send INIT: %s", - strerror(errno)); + error_setg(errp, "tpm-emulator: could not send INIT: %s", + strerror(errno)); goto err_exit; } =20 res =3D be32_to_cpu(init.u.resp.tpm_result); if (res) { - error_report("tpm-emulator: TPM result for CMD_INIT: 0x%x %s", res, - tpm_emulator_strerror(res)); + error_setg(errp, "tpm-emulator: TPM result for CMD_INIT: 0x%x %s",= res, + tpm_emulator_strerror(res)); goto err_exit; } return 0; @@ -441,18 +443,31 @@ err_exit: return -1; } =20 -static int tpm_emulator_startup_tpm(TPMBackend *tb, size_t buffersize) +static int do_tpm_emulator_startup_tpm(TPMBackend *tb, size_t buffersize, + Error **errp) { /* TPM startup will be done from post_load hook */ if (runstate_check(RUN_STATE_INMIGRATE)) { if (buffersize !=3D 0) { - return tpm_emulator_set_buffer_size(tb, buffersize, NULL); + return tpm_emulator_set_buffer_size(tb, buffersize, NULL, errp= ); } =20 return 0; } =20 - return tpm_emulator_startup_tpm_resume(tb, buffersize, false); + return tpm_emulator_startup_tpm_resume(tb, buffersize, false, errp); +} + +static int tpm_emulator_startup_tpm(TPMBackend *tb, size_t buffersize) +{ + Error *local_err =3D NULL; + int ret =3D do_tpm_emulator_startup_tpm(tb, buffersize, &local_err); + + if (ret < 0) { + error_report_err(local_err); + } + + return ret; } =20 static bool tpm_emulator_get_tpm_established_flag(TPMBackend *tb) @@ -546,7 +561,7 @@ static size_t tpm_emulator_get_buffer_size(TPMBackend *= tb) { size_t actual_size; =20 - if (tpm_emulator_set_buffer_size(tb, 0, &actual_size) < 0) { + if (tpm_emulator_set_buffer_size(tb, 0, &actual_size, NULL) < 0) { return 4096; } =20 @@ -889,7 +904,7 @@ static int tpm_emulator_set_state_blobs(TPMBackend *tb,= Error **errp) =20 trace_tpm_emulator_set_state_blobs(); =20 - if (tpm_emulator_stop_tpm(tb) < 0) { + if (tpm_emulator_stop_tpm(tb, errp) < 0) { trace_tpm_emulator_set_state_blobs_error("Could not stop TPM"); return -EIO; } @@ -960,7 +975,7 @@ static int tpm_emulator_post_load(void *opaque, int ver= sion_id, Error **errp) return ret; } =20 - if (tpm_emulator_startup_tpm_resume(tb, 0, true) < 0) { + if (tpm_emulator_startup_tpm_resume(tb, 0, true, errp) < 0) { return -EIO; } =20 --=20 2.48.1