From nobody Tue Feb 10 17:31:21 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1630048397059945.789107239372; Fri, 27 Aug 2021 00:13:17 -0700 (PDT) Received: from localhost ([::1]:59234 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mJW39-00047b-3x for importer@patchew.org; Fri, 27 Aug 2021 03:13:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52088) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJVzy-0000qx-Iz; Fri, 27 Aug 2021 03:09:58 -0400 Received: from ozlabs.org ([203.11.71.1]:37383) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mJVzv-0007Js-0k; Fri, 27 Aug 2021 03:09:58 -0400 Received: by ozlabs.org (Postfix, from userid 1007) id 4GwrSY6SfWz9sVw; Fri, 27 Aug 2021 17:09:49 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1630048189; bh=A/GPSIrXoRtaTFNtgH+eDraZ098SIFkg84T/SIERrgc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XPKS0oCpFHOKzGm655nK59+3na5HisSdfSti0HdhIrfhBhUE0T0N3YfjbXegqmtt5 FsVz9MfkUD6itja+qOEPYDIome7YjRHBcXyjWici1AkoBknEO0tKg5E2zQL8HT7iqh Yp7HzosnJ6oh9fvAEr30Y+h+v3csfZB99jptO+/c= From: David Gibson To: peter.maydell@linaro.org, groug@kaod.org Subject: [PULL 02/18] spapr_pci: Fix leak in spapr_phb_vfio_get_loc_code() with g_autofree Date: Fri, 27 Aug 2021 17:09:30 +1000 Message-Id: <20210827070946.219970-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210827070946.219970-1-david@gibson.dropbear.id.au> References: <20210827070946.219970-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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=203.11.71.1; envelope-from=dgibson@ozlabs.org; helo=ozlabs.org X-Spam_score_int: -17 X-Spam_score: -1.8 X-Spam_bar: - X-Spam_report: (-1.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HEADER_FROM_DIFFERENT_DOMAINS=0.249, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , qemu-ppc@nongnu.org, qemu-devel@nongnu.org, David Gibson Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1630048398232100001 This uses g_autofree to simplify logic in spapr_phb_vfio_get_loc_code(), in the process fixing a leak in one of the paths. I'm told this fixes Coverity error CID 1460454 Reported-by: Peter Maydell Fixes: 16b0ea1d852 ("spapr_pci: populate ibm,loc-code") Reviewed-by: Philippe Mathieu-Daud=C3=A9 Signed-off-by: David Gibson --- hw/ppc/spapr_pci.c | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/hw/ppc/spapr_pci.c b/hw/ppc/spapr_pci.c index 7a725855f9..7430bd6314 100644 --- a/hw/ppc/spapr_pci.c +++ b/hw/ppc/spapr_pci.c @@ -782,33 +782,29 @@ static AddressSpace *spapr_pci_dma_iommu(PCIBus *bus,= void *opaque, int devfn) =20 static char *spapr_phb_vfio_get_loc_code(SpaprPhbState *sphb, PCIDevice *= pdev) { - char *path =3D NULL, *buf =3D NULL, *host =3D NULL; + g_autofree char *path =3D NULL; + g_autofree char *host =3D NULL; + g_autofree char *devspec =3D NULL; + char *buf =3D NULL; =20 /* Get the PCI VFIO host id */ host =3D object_property_get_str(OBJECT(pdev), "host", NULL); if (!host) { - goto err_out; + return NULL; } =20 /* Construct the path of the file that will give us the DT location */ path =3D g_strdup_printf("/sys/bus/pci/devices/%s/devspec", host); - g_free(host); - if (!g_file_get_contents(path, &buf, NULL, NULL)) { - goto err_out; + if (!g_file_get_contents(path, &devspec, NULL, NULL)) { + return NULL; } - g_free(path); =20 /* Construct and read from host device tree the loc-code */ - path =3D g_strdup_printf("/proc/device-tree%s/ibm,loc-code", buf); - g_free(buf); + path =3D g_strdup_printf("/proc/device-tree%s/ibm,loc-code", devspec); if (!g_file_get_contents(path, &buf, NULL, NULL)) { - goto err_out; + return NULL; } return buf; - -err_out: - g_free(path); - return NULL; } =20 static char *spapr_phb_get_loc_code(SpaprPhbState *sphb, PCIDevice *pdev) --=20 2.31.1