From nobody Sun Feb 8 09:32:35 2026 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1657229716; cv=none; d=zohomail.com; s=zohoarc; b=Rq+I4l2CZ2uSFVej2AmtNQC96tEZ9ngwnQwnFqQDmD8HrjhNtDj/904KGiwPtMsRx480dT6kvCZsuqjngZ8ucCJvBkbtXB7p+hzRnaNYhFIGu8SOY2Z4kSI2G/xoGX964DXzzwfiAkdpElvvxZFwP05Me2F1kurxkm7u+B/1TL8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657229716; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EbgRJ9MdyHPnaY3lqJatX0u5qeF8Vuc/iS2wZ00ilX4=; b=A/YiaZhrwWKZk6htqhBYtvzBFoS4w+ZrXP/yt9UlKcRJ1bYZWWiIWcYW/qXyPwVgfQ2wMkO1D5WOWkdSkbaS2eCSIrATjU1KoUrcamPZ6wnd+QPpWAo6T4Gtvk3tPzt/j/hWo5/b6qbkFDHNDM/VenBGy8dQIuR1X13udH2sKQw= 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 1657229716346816.7157345502708; Thu, 7 Jul 2022 14:35:16 -0700 (PDT) Received: from localhost ([::1]:58546 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9Z9X-00058b-1U for importer@patchew.org; Thu, 07 Jul 2022 17:35:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55448) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o9Z4t-0000HF-AH; Thu, 07 Jul 2022 17:30:27 -0400 Received: from mail-ua1-x92c.google.com ([2607:f8b0:4864:20::92c]:35661) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o9Z4q-0004gH-Hu; Thu, 07 Jul 2022 17:30:26 -0400 Received: by mail-ua1-x92c.google.com with SMTP id s3so5269263uaq.2; Thu, 07 Jul 2022 14:30:23 -0700 (PDT) Received: from balboa.ibmuc.com (201-27-97-88.dsl.telesp.net.br. [201.27.97.88]) by smtp.gmail.com with ESMTPSA id 66-20020a1f1745000000b0036bfe74006esm12122103vkx.31.2022.07.07.14.30.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 14:30:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EbgRJ9MdyHPnaY3lqJatX0u5qeF8Vuc/iS2wZ00ilX4=; b=Iiluu95spCzepkDpGRhxq8d9IbRgVwmVIj+XEM6MWhGXlyvLsVBwCKmJDdnSK6HkVy lQJ1mxJFy88Bo3+CqE0YG+3cL1sop4nFcz+JJQ96ycBFPW2mT5dSBEq65ySoLck2xytQ vNxjlv1oWYAjnBVgcCLR2AdZVdAkS9yC8joEGrI6YJ/+cDikoTfBv3FYprh81jRdiH01 UaV4QYMH6M/MzLFTHSVxazstW0Xs9SwXtgyti5icWVbEWsWEVU5gVEaxR6wxtxhXqq9l q6Svxh6OFFZCE3ahgQ0IU0Mv6m/qbJ1NFP4uH1UrOeuaNyAAGqLvw/DmXep6hwaBow1Q 2UOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EbgRJ9MdyHPnaY3lqJatX0u5qeF8Vuc/iS2wZ00ilX4=; b=3Rm8G9xuC1qAhVX9yDEGV7oDav5sJBzMbfm4h22qxvuDM5BmBKP58EePZ+5gE0eBY7 HjeGxIWI+WNbpcSvlhqcBKPL9hJMn1z30Xt6G+S+7WzZU9MO8WN02pnAUy7c6KzMXzRG WrHEcdHOqBw6IOmbLhyWGxustzdFlsj9u2ib6h2uyfCN8qtPII6Dejm9WNgQXdFpvIki 7k3PkKnCwfmbw7+TivYdH/g/L6j+RgUjLsGthAF3PABryCooz1PTMRcRon1mBzqCWHXV r61sgB8iJoaz1ziGmyudxAKpoH1oPMtA5BR437H8/g0sT3TrCy0/ZvAjyhGFV/su5Psz huNA== X-Gm-Message-State: AJIora+PeCD9ch3xcRznjA2fwyvvjD7qy3xoafm+DRAwQK+iZRXkStvX oHQEBKTj05CLpZluERHnSzIELn2lwyM= X-Google-Smtp-Source: AGRyM1sZb5Xorwloee0Xq3jZC+LJGsBz9K05olPZPcnf2WPVNGsyO0aE9NTIyyuLaxrvRg2CxmN0/A== X-Received: by 2002:ab0:69d4:0:b0:381:f49f:21ee with SMTP id u20-20020ab069d4000000b00381f49f21eemr17831uaq.92.1657229422729; Thu, 07 Jul 2022 14:30:22 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-ppc@nongnu.org, clg@kaod.org, jianchunfu , Daniel Henrique Barboza Subject: [PATCH v3 1/4] target/ppc: add error report when fopen fails in kvmppc_read_int_dt() Date: Thu, 7 Jul 2022 18:30:12 -0300 Message-Id: <20220707213015.552104-2-danielhb413@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220707213015.552104-1-danielhb413@gmail.com> References: <20220707213015.552104-1-danielhb413@gmail.com> 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=2607:f8b0:4864:20::92c; envelope-from=danielhb413@gmail.com; helo=mail-ua1-x92c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1657229717404100001 Content-Type: text/plain; charset="utf-8" From: jianchunfu Use an Error pointer to report the error back to the caller. While we're at it, return '0' instead of '-1' on error since the function is supposed to return an uint64_t. Signed-off-by: jianchunfu [danielhb: return 0, use error_set_errno() instead of fprintf] Signed-off-by: Daniel Henrique Barboza --- target/ppc/kvm.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 6eed466f80..65d136ed5a 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -1896,7 +1896,7 @@ static int kvmppc_find_cpu_dt(char *buf, int buf_len) return 0; } =20 -static uint64_t kvmppc_read_int_dt(const char *filename) +static uint64_t kvmppc_read_int_dt(const char *filename, Error **errp) { union { uint32_t v32; @@ -1907,7 +1907,8 @@ static uint64_t kvmppc_read_int_dt(const char *filena= me) =20 f =3D fopen(filename, "rb"); if (!f) { - return -1; + error_setg_errno(errp, errno, "error opening %s", filename); + return 0; } =20 len =3D fread(&u, 1, sizeof(u), f); @@ -1938,7 +1939,7 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *pr= opname) } =20 tmp =3D g_strdup_printf("%s/%s", buf, propname); - val =3D kvmppc_read_int_dt(tmp); + val =3D kvmppc_read_int_dt(tmp, NULL); g_free(tmp); =20 return val; --=20 2.36.1 From nobody Sun Feb 8 09:32:35 2026 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1657229589; cv=none; d=zohomail.com; s=zohoarc; b=ijbhz/5ftoJn81zknTPx7Nz8DKNA1WmlYI/ZmVAE9BjDw8kDfaKaN+F6IVRFPEm/gRdPffnjNV3c367r/63B4121jzoeb5lGcHOu71jIcZ9jrre3eZpT1G7bqTKuJzapAVQHqXDzfr7IswKM5ju+FvnHHZb024QGj+lNutp6pYE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657229589; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=XOredsu6SbX+k+sREA6mtNqWDsTUQkxRJJ/oY0tCG7w=; b=HOEFMqs5cBdSdi+tZzjG7Bzq5tE4QWv/rjcAATs3XAc4qZ4PHsA+3ELh+e93/WE+QYaRW9HzqFHNycco/uiYj++8lA5b0GD/nABFRMTyH4Dgd4JEB7jvOs3SGISXE2Hlc7NsSKeMpXmuHr1JmaKQFgxJI/HlJMMhzdnsCP/TxLs= 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 1657229589947222.5180548064078; Thu, 7 Jul 2022 14:33:09 -0700 (PDT) Received: from localhost ([::1]:54476 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9Z7U-0002Oc-Jw for importer@patchew.org; Thu, 07 Jul 2022 17:33:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55480) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o9Z4u-0000Ho-Lu; Thu, 07 Jul 2022 17:30:28 -0400 Received: from mail-vs1-xe35.google.com ([2607:f8b0:4864:20::e35]:35462) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o9Z4s-0004gd-Mt; Thu, 07 Jul 2022 17:30:28 -0400 Received: by mail-vs1-xe35.google.com with SMTP id 189so19643128vsh.2; Thu, 07 Jul 2022 14:30:25 -0700 (PDT) Received: from balboa.ibmuc.com (201-27-97-88.dsl.telesp.net.br. [201.27.97.88]) by smtp.gmail.com with ESMTPSA id 66-20020a1f1745000000b0036bfe74006esm12122103vkx.31.2022.07.07.14.30.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 14:30:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XOredsu6SbX+k+sREA6mtNqWDsTUQkxRJJ/oY0tCG7w=; b=kHIwDjdP4iGtPuhOOQJmbV8p7lKrlcXNqpWiGhCO3dkIk+jERNqGJ1G9UhKPL4bbZ2 z3/zrJvF5R51Tt+dLU+TpuIsVwRtQFYxnPXEXXdNT4JZeb7JgVEIHYmmonbJzOrdxIzI X093WGvULWSfEWC2AoaaDGZ5M3qd7USvYxOyJ57x0S/O9eDXQjvzXNmsVZGd/QhidcAF arXiRkHobd3LfuUFesh3h8u5vLgtyIFrlFwVB3bQvZJ5D8AJDxDxF9SDI0V6AHKC2uth 4m2SKomCgOIiuZ2C/+0tVoxLW6a6RJMJkN7p79IbPU+w3YaWBisxEGVrY1wHDYwGPVfk UahA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XOredsu6SbX+k+sREA6mtNqWDsTUQkxRJJ/oY0tCG7w=; b=B74pYKc4kmI+fN/Egrvm2I3fXBmYqwKoboEUnwGTP3EEfRa6bOINSDoWYPVTVVNlJe U1W6bOwhElRUMrXGEdfUyQxpEo9tjB9sU4lQO8TLW3rIzF/Eu7v5lkpqU7YICzs7WvrV Fikc6Qi/qWrzxdRoJhnONG34MSKXpuT7OTrU1T8qj0BfVLnFdfTtIDd1wi6Cn4EsdErV 9S5/9cCeGxrRGuFH8MJg6xHz3LGFw8WLfz6Cbh13/AUoenYHeIKaRh9c5kRrEh2Bl0NO h1XG0b87aC6ZG7ctXfYNgC/ALKLjzVrsRVc7cPbxr2iE0MWeK/F2lk/yQRQHdtpL09vD 5LJA== X-Gm-Message-State: AJIora80JziKqRFEbtJ0iCy7Ytxn0H7LSF3r3gL0ZNm7kyonzU2FObPc BfgVrsEJvbV+zYC76r0D6eQC5r33+B4= X-Google-Smtp-Source: AGRyM1uTAzIpUggWPLApzyFUPLNPfvzc6sEWOH47xWlvgj67xNr0GOgPHCsHlSp4M+x/NXB//RYhMQ== X-Received: by 2002:a05:6102:a34:b0:354:4268:c2d4 with SMTP id 20-20020a0561020a3400b003544268c2d4mr26784026vsb.21.1657229424446; Thu, 07 Jul 2022 14:30:24 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-ppc@nongnu.org, clg@kaod.org, Daniel Henrique Barboza Subject: [PATCH v3 2/4] target/ppc: enhance error report in kvmppc_read_int_cpu_dt() Date: Thu, 7 Jul 2022 18:30:13 -0300 Message-Id: <20220707213015.552104-3-danielhb413@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220707213015.552104-1-danielhb413@gmail.com> References: <20220707213015.552104-1-danielhb413@gmail.com> 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=2607:f8b0:4864:20::e35; envelope-from=danielhb413@gmail.com; helo=mail-vs1-xe35.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1657229590533100003 Content-Type: text/plain; charset="utf-8" First and foremost, the function can't return '-1' when an error occurs because the return type is set to uint64_t. Let's fix that. After that, the function can't simply return 0 whether an error happened and call it a day. We must provide a way of letting callers know if the zero return is legitimate or due to an error. Add an Error pointer to kvmppc_read_int_cpu_dt() that will be filled with an appropriate error, if one occurs. Callers are then free to pass an Error pointer and handle it. Signed-off-by: Daniel Henrique Barboza --- target/ppc/kvm.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 65d136ed5a..cf4610b6fa 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -1926,20 +1926,22 @@ static uint64_t kvmppc_read_int_dt(const char *file= name, Error **errp) =20 /* * Read a CPU node property from the host device tree that's a single - * integer (32-bit or 64-bit). Returns 0 if anything goes wrong - * (can't find or open the property, or doesn't understand the format) + * integer (32-bit or 64-bit). Returns 0 and set errp if anything goes + * wrong (can't find or open the property, or doesn't understand the + * format) */ -static uint64_t kvmppc_read_int_cpu_dt(const char *propname) +static uint64_t kvmppc_read_int_cpu_dt(const char *propname, Error **errp) { char buf[PATH_MAX], *tmp; uint64_t val; =20 if (kvmppc_find_cpu_dt(buf, sizeof(buf))) { - return -1; + error_setg(errp, "Failed to read CPU property %s", propname); + return 0; } =20 tmp =3D g_strdup_printf("%s/%s", buf, propname); - val =3D kvmppc_read_int_dt(tmp, NULL); + val =3D kvmppc_read_int_dt(tmp, errp); g_free(tmp); =20 return val; @@ -1947,12 +1949,12 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *= propname) =20 uint64_t kvmppc_get_clockfreq(void) { - return kvmppc_read_int_cpu_dt("clock-frequency"); + return kvmppc_read_int_cpu_dt("clock-frequency", NULL); } =20 static int kvmppc_get_dec_bits(void) { - int nr_bits =3D kvmppc_read_int_cpu_dt("ibm,dec-bits"); + int nr_bits =3D kvmppc_read_int_cpu_dt("ibm,dec-bits", NULL); =20 if (nr_bits > 0) { return nr_bits; @@ -2337,8 +2339,8 @@ static void alter_insns(uint64_t *word, uint64_t flag= s, bool on) static void kvmppc_host_cpu_class_init(ObjectClass *oc, void *data) { PowerPCCPUClass *pcc =3D POWERPC_CPU_CLASS(oc); - uint32_t dcache_size =3D kvmppc_read_int_cpu_dt("d-cache-size"); - uint32_t icache_size =3D kvmppc_read_int_cpu_dt("i-cache-size"); + uint32_t dcache_size =3D kvmppc_read_int_cpu_dt("d-cache-size", NULL); + uint32_t icache_size =3D kvmppc_read_int_cpu_dt("i-cache-size", NULL); =20 /* Now fix up the class with information we can query from the host */ pcc->pvr =3D mfpvr(); --=20 2.36.1 From nobody Sun Feb 8 09:32:35 2026 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1657229879; cv=none; d=zohomail.com; s=zohoarc; b=VgvRk4s93LGQxxA3Lw79k8vYTxiei4BbB4OYfgfqLPDJNVlKLA2llYE3fShVv5BhHckgcQF6bfotlzLzVxyAHSpx8IxF2UvAEclZLaeWuEIEENUNQbDeVrHXGqe+uj8w1onAbFwjgdIi9NcqfzZWYSbakHoXN332mA1yscSrfhI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657229879; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=vUo+kam0edsqNjfYKT4YrUA41QbVirwtKsGpf4GPc8g=; b=RCAOm4yWzlcz6MYwLtDu/X+ltZmIGC6tG2EGsISM0dOWjw6AaoFxqDxlEGr6/wvdBbPneerLafXPte8VPyPUPch3lBd+cDHqzPTA0NMFwY/TaybSUkOOey97ApMskm4WZBCewWHTViYCX8aifo8WcylJFNiNhczSGRRgit7N4gc= 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 1657229879882576.9250321883472; Thu, 7 Jul 2022 14:37:59 -0700 (PDT) Received: from localhost ([::1]:34648 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9ZCA-0008DP-Lj for importer@patchew.org; Thu, 07 Jul 2022 17:37:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55504) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o9Z4v-0000JT-T6; Thu, 07 Jul 2022 17:30:31 -0400 Received: from mail-vk1-xa34.google.com ([2607:f8b0:4864:20::a34]:42899) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o9Z4t-0004hW-Dv; Thu, 07 Jul 2022 17:30:29 -0400 Received: by mail-vk1-xa34.google.com with SMTP id r184so2731286vkg.9; Thu, 07 Jul 2022 14:30:26 -0700 (PDT) Received: from balboa.ibmuc.com (201-27-97-88.dsl.telesp.net.br. [201.27.97.88]) by smtp.gmail.com with ESMTPSA id 66-20020a1f1745000000b0036bfe74006esm12122103vkx.31.2022.07.07.14.30.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 14:30:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vUo+kam0edsqNjfYKT4YrUA41QbVirwtKsGpf4GPc8g=; b=n3jJZsLeZO+wwUTpaJhAnYK8siCUGiyL+FIJZwmh74TC0Cfagxx41l7UCAqG41Dd/3 C+zqXZsjzYbe4O4i3BaynTt8wN/MJgXBvDmKAv4Pwmj3qG3mn3FuVTYIH/PlcsPI4Rkl mcQSZQMYmpTK60IdwbfEfvVr0rtq2Wy4/3N5vSxnkpwxqzzm/sVwo7GoFn3JzcVsl/OH 2YvJicOAX2+S6WAItHWrHoaSYxLxpa7U+9rr7zB2Xj7vAEagHed8AD78PWaG1J0y/FsF zbxrNc2GMOCuGF8frUvhtZi3PxPeyqvUaurXQIYkTtyD0dt60MjFvfFHVoWwqXA8gIHr 1XtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vUo+kam0edsqNjfYKT4YrUA41QbVirwtKsGpf4GPc8g=; b=aBStZ1z0Id/eVWXqwMClLKqZl4cJIyO2ndv89kROzclKZ3GrCnBOo3prppLAdbFDly LYukTSMwfmcmxVS4tsfyZFxG5A5gy2r8zm7ZXBzb26gVBRxkU539THz6HrzSPJoPZOs7 BSIup2FwKuRkvmBxX0h6tBI1Wa4cOUkMWkIMVdq4wIKICidQbxKKEHEuioyNTzshkNTY O6XNQVdKEmGgLIwVlMBRA4d5yGfU5mJth+FEg5Lb8x2fG2y42JiTjgXhvj47jhWJpxt1 09QX2TLLgeRKkv9hXVqIdUbM7yIB65MaMx4AHwY4MiUanzenOkRc5Mo9TuqP37R3XTY0 qlsg== X-Gm-Message-State: AJIora98/SRhSi8lwuUEimBh+TznfNU+F2zjX/whQS0spvZKubVYFL0V C8pZG/1yAltcEQmZpEhOu+r8nXXbIVU= X-Google-Smtp-Source: AGRyM1v/dlnIDfjBzC1004sjJLgfBXWN8DsP3fP8dm00R1EkZtrais5l12Hdp1Nct2GF9VYsrMqy3w== X-Received: by 2002:a05:6122:25b:b0:36c:5f1a:d94b with SMTP id t27-20020a056122025b00b0036c5f1ad94bmr28116546vko.31.1657229426039; Thu, 07 Jul 2022 14:30:26 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-ppc@nongnu.org, clg@kaod.org, Daniel Henrique Barboza Subject: [PATCH v3 3/4] target/ppc: use g_autofree in kvmppc_read_int_cpu_dt() Date: Thu, 7 Jul 2022 18:30:14 -0300 Message-Id: <20220707213015.552104-4-danielhb413@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220707213015.552104-1-danielhb413@gmail.com> References: <20220707213015.552104-1-danielhb413@gmail.com> 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=2607:f8b0:4864:20::a34; envelope-from=danielhb413@gmail.com; helo=mail-vk1-xa34.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1657229880890100001 Content-Type: text/plain; charset="utf-8" This spares us a g_free() call. Let's also not use 'val' and return the value of kvmppc_read_int_dt() directly. Signed-off-by: Daniel Henrique Barboza --- target/ppc/kvm.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index cf4610b6fa..37a312288d 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -1932,8 +1932,8 @@ static uint64_t kvmppc_read_int_dt(const char *filena= me, Error **errp) */ static uint64_t kvmppc_read_int_cpu_dt(const char *propname, Error **errp) { - char buf[PATH_MAX], *tmp; - uint64_t val; + g_autofree char *tmp =3D NULL; + char buf[PATH_MAX]; =20 if (kvmppc_find_cpu_dt(buf, sizeof(buf))) { error_setg(errp, "Failed to read CPU property %s", propname); @@ -1941,10 +1941,8 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *p= ropname, Error **errp) } =20 tmp =3D g_strdup_printf("%s/%s", buf, propname); - val =3D kvmppc_read_int_dt(tmp, errp); - g_free(tmp); =20 - return val; + return kvmppc_read_int_dt(tmp, errp); } =20 uint64_t kvmppc_get_clockfreq(void) --=20 2.36.1 From nobody Sun Feb 8 09:32:35 2026 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=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1657229724; cv=none; d=zohomail.com; s=zohoarc; b=AD8wwa9TumTmvgYLQs3bDqbN8wXS0UhG4L0pYaYYtHteIfW9VfkuQnxdH5dFc1GyfYx5EbOFeiql56TGyg6dGROW2wCiJr6YhSPw+GHMd2XIr+ybpiEfuNKMqo9+0f9k8RCGIjHPEn+VYkhG/1iz7TqBuOxLU2mFvjjUBlvzGdI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1657229724; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=X7g0ZEIbbAirSzVLJgJceqK9f+d4u/48V7OosDEGVa0=; b=LSp5dT+swPxqMQivVjw4qA/1awp6Njl3qIoRH3zvZGbYwEhRghcn3eXqEhxbxY+lurbEssuPSipmhP5XLLQ1ZZ7wxRh+HRW9CJlZ15I9SSHpFyXgWLchjoyOA3e1bd+ACDAld8HzbhMUL/0uGwt1oyPL8zIHCC3faWRBDNs0mzg= 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 1657229724437129.87037915066935; Thu, 7 Jul 2022 14:35:24 -0700 (PDT) Received: from localhost ([::1]:58990 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o9Z9f-0005Qa-BO for importer@patchew.org; Thu, 07 Jul 2022 17:35:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55506) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o9Z4w-0000Ja-Ed; Thu, 07 Jul 2022 17:30:31 -0400 Received: from mail-vs1-xe2c.google.com ([2607:f8b0:4864:20::e2c]:46933) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o9Z4v-0004iJ-1C; Thu, 07 Jul 2022 17:30:30 -0400 Received: by mail-vs1-xe2c.google.com with SMTP id 126so19600709vsq.13; Thu, 07 Jul 2022 14:30:28 -0700 (PDT) Received: from balboa.ibmuc.com (201-27-97-88.dsl.telesp.net.br. [201.27.97.88]) by smtp.gmail.com with ESMTPSA id 66-20020a1f1745000000b0036bfe74006esm12122103vkx.31.2022.07.07.14.30.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 14:30:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X7g0ZEIbbAirSzVLJgJceqK9f+d4u/48V7OosDEGVa0=; b=L3YyPdvEAVHYlqRVKBeSK0hvGJivtJUr4I2PWkrAjt8t/WLLbWzaKejhGuA9V/nSoC rDvrSRW115vpFNPW2BN56Yc5glBtlyPq4liQ0wbYo2kIRjx/2VMhAcPE2ssvD7Ev7RJn y1nN7Ol7fyR9EqMZ8hS0eeViRpwNGIOp+ZfaeVkth4rgA2YOOuPs2v2QSz9izQBRKXLA DAdUHL9x8icDM9QA0viOwUgGrotbQMRD+fJOfC6GeJNvOQoYRHHLyMxsMtLWdIRYNB12 57/x3KejhaO6FKEfLJ/HN6lAEY3SIaRKDeYmY56ep94Y6cNwEQkI1oQDaIvsrnuC8x1F BKOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=X7g0ZEIbbAirSzVLJgJceqK9f+d4u/48V7OosDEGVa0=; b=G4KUUCiubUNN4+8CrWCNZGNZvVsZaMGaoP0XJdmfFYfcQgDUcUZFRyiH5OOKXO84MO GMsoE1aakP/aZ0XgM34PLG/m0+4syYGqSqU3tKogjcaI8/3oV87OzPfxPNlqVbTmMwD7 D1knyp8tXxMHdNc/51HmNBAQ+8ThsSixQR5PObq7LYyz+18Cu47o0IFUNhjFcfKRBBU8 dYaptGOUy66qZDglrGAEKSXNAuYzUnHoZ6dAoNgzDvUEft02rbDRx3dLaCRXWso2+PxQ w6zMd2Q9Auv0KM1cjz0pccybG7oezusX4sgetKXieS6FAVdupb2hSJULTAaQoAG0DxmB 456g== X-Gm-Message-State: AJIora822D8O+aeVa3k9lcNNJT/lwvy/4JShlbTjS3P6s+OR7LkDe7/z 8IWl0dPFTg+iVuuLLOT4bl82pgMZcUY= X-Google-Smtp-Source: AGRyM1uM7mVsug6R+ynP5P5KzkGKSrLMUu1fNwEZCljzgoKmfV+E5PPYVk1704VJHiM/DXAy9MuvZA== X-Received: by 2002:a05:6102:e8b:b0:356:5222:e574 with SMTP id l11-20020a0561020e8b00b003565222e574mr26881795vst.62.1657229427796; Thu, 07 Jul 2022 14:30:27 -0700 (PDT) From: Daniel Henrique Barboza To: qemu-devel@nongnu.org Cc: qemu-ppc@nongnu.org, clg@kaod.org, Daniel Henrique Barboza Subject: [PATCH v3 4/4] target/ppc: exit(1) on failure in kvmppc_get_clockfreq() Date: Thu, 7 Jul 2022 18:30:15 -0300 Message-Id: <20220707213015.552104-5-danielhb413@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220707213015.552104-1-danielhb413@gmail.com> References: <20220707213015.552104-1-danielhb413@gmail.com> 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=2607:f8b0:4864:20::e2c; envelope-from=danielhb413@gmail.com; helo=mail-vs1-xe2c.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 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, FREEMAIL_ENVFROM_END_DIGIT=0.25, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 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" X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1657229725265100001 Content-Type: text/plain; charset="utf-8" When running under KVM accel it is expected to have 'clock-frequency' in the DT. Not having this attribute is too risky for both the machine emulation and userspace. We have a way of telling whether this error scenario might happen or not via kvmppc_read_int_cpu_dt() now being able to report errors. From now on, when running KVM, we will assume that 'clock-frequency' will always be present in the DT. Signed-off-by: Daniel Henrique Barboza --- target/ppc/kvm.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/target/ppc/kvm.c b/target/ppc/kvm.c index 37a312288d..14faa14da3 100644 --- a/target/ppc/kvm.c +++ b/target/ppc/kvm.c @@ -1945,9 +1945,24 @@ static uint64_t kvmppc_read_int_cpu_dt(const char *p= ropname, Error **errp) return kvmppc_read_int_dt(tmp, errp); } =20 +/* + * Read the clock-frequency from the DT. On error (e.g. + * 'clock-frequency' is not present in the DT) will + * report an error and exit(1). + */ uint64_t kvmppc_get_clockfreq(void) { - return kvmppc_read_int_cpu_dt("clock-frequency", NULL); + Error *local_err =3D NULL; + int ret; + + ret =3D kvmppc_read_int_cpu_dt("clock-frequency", &local_err); + + if (local_err) { + error_report_err(local_err); + exit(1); + } + + return ret; } =20 static int kvmppc_get_dec_bits(void) --=20 2.36.1