From nobody Sun Feb 8 17:48:20 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=fail(p=none dis=none) header.from=gmail.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1532174938034246.10424721982088; Sat, 21 Jul 2018 05:08:58 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 152D730820DF; Sat, 21 Jul 2018 12:08:53 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CB5C3CC400; Sat, 21 Jul 2018 12:08:52 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 857061841C5A; Sat, 21 Jul 2018 12:08:52 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC8XDd016470 for ; Sat, 21 Jul 2018 08:08:33 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0EA2B60175; Sat, 21 Jul 2018 12:08:33 +0000 (UTC) Received: from mx1.redhat.com (ext-mx05.extmail.prod.ext.phx2.redhat.com [10.5.110.29]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 0661760172 for ; Sat, 21 Jul 2018 12:08:28 +0000 (UTC) Received: from mail-pl0-f68.google.com (mail-pl0-f68.google.com [209.85.160.68]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id F2DC536A5C3 for ; Sat, 21 Jul 2018 12:08:16 +0000 (UTC) Received: by mail-pl0-f68.google.com with SMTP id w8-v6so6296048ply.8 for ; Sat, 21 Jul 2018 05:08:16 -0700 (PDT) Received: from centos.localdomain ([42.106.1.69]) by smtp.gmail.com with ESMTPSA id s16-v6sm5861694pfm.114.2018.07.21.05.08.14 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=/63wE1mTluF/p9KgWUj4UEn3Zje0QzKLp/j0+mb54Fg=; b=SebDs9Ji4oSVfj706DnkIlqGK0bU+tDosHjvdTh5BVZWLnpJEEYOT57yG+/k1pvLT5 vPE+/2raMv3OF7TkyA5DC2n23WZwCSqDSN6tP2bnN5XTu6a7VIa8z1s07SuS+B8EKFbo 2WdTfIXOIiRlZQ74ZEGv9BbG25rZk5Yr1iJXaN4Ia2bYzS5P0sW/Zs+fwOO5F9HtWP5p akumQEh4+nGCUm7HkS1O7br5uRtDzrjUtYH/vCz80K/Uc7/lUZmYGjQ6nDE2ojMOSY4b uMrkCFQ9MIGOFP1iXZpeKGxwjCOXsR70w6HDys2xMVPMtYHfkiOF1Zf0PD4rbvi11jGr hrRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=/63wE1mTluF/p9KgWUj4UEn3Zje0QzKLp/j0+mb54Fg=; b=gUMZLGWJTdGCQ9oNVEPnCRSvFdeyUc7smamoxMoFxeWbbSOEWL+KW54gHSNKxW0vwL ry5D9ReAZ9JfXpcysoTKS9O2YcFrTQ2V6PydrzES8f6Xiieu2aFiuBpCVQdbCcZWAHFO CPKuKJTFgirriHP3AHIYeMNNVbj9vSfCdW6tG44L9FQzFjwmdwJNgbRWrSijpDCPn46u k9O0feiUwpHz4giEMpIaiWvjaKShAczZ9AFG6HDJ9SynQLEH48/DfywActkdPG0Wz5rx zJO2ozGUqMJYPGQnGMdzxp4EbW6W/tA0jp8y8ny2LboXIzk5o3LlzUjKXN9vxT636aSp 16IA== X-Gm-Message-State: AOUpUlE6DGDxpO6btHJ2XgI1DeEtPqJgVeW7dhdbVDOt2OPuQFfMg59d R5RAknAvim0fsxyzwZNvROPRQ1ax X-Google-Smtp-Source: AAOMgpd7PJ0JGrm2oDhJnS8gDJ3eh4NbJ4uRXSQjefeNrPCpU3bD3QhAPKhI8jbpsqgWGm1Avw/q3A== X-Received: by 2002:a17:902:262:: with SMTP id 89-v6mr5597478plc.221.1532174896219; Sat, 21 Jul 2018 05:08:16 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:36:53 +0530 Message-Id: <1532174832-21644-22-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> References: <1532174832-21644-1-git-send-email-skrtbhtngr@gmail.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 21 Jul 2018 12:08:17 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 21 Jul 2018 12:08:17 +0000 (UTC) for IP:'209.85.160.68' DOMAIN:'mail-pl0-f68.google.com' HELO:'mail-pl0-f68.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.281 * (DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, NML_ADSP_CUSTOM_MED, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS, T_DKIM_INVALID) 209.85.160.68 mail-pl0-f68.google.com 209.85.160.68 mail-pl0-f68.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.29 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 21/40] util: pci: use VIR_AUTOPTR for aggregate types X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Sat, 21 Jul 2018 12:08:57 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar --- src/util/virpci.c | 51 ++++++++++++++++++--------------------------------- 1 file changed, 18 insertions(+), 33 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index 1f6ac0b..7b0964c 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -490,8 +490,6 @@ virPCIDeviceIterDevices(virPCIDeviceIterPredicate predi= cate, ret =3D 1; break; } - - virPCIDeviceFree(check); } VIR_DIR_CLOSE(dir); return ret; @@ -781,7 +779,8 @@ virPCIDeviceTrySecondaryBusReset(virPCIDevicePtr dev, int cfgfd, virPCIDeviceList *inactiveDevs) { - virPCIDevicePtr parent, conflict; + VIR_AUTOPTR(virPCIDevice) parent =3D NULL; + VIR_AUTOPTR(virPCIDevice) conflict =3D NULL; uint8_t config_space[PCI_CONF_LEN]; uint16_t ctl; int ret =3D -1; @@ -795,7 +794,6 @@ virPCIDeviceTrySecondaryBusReset(virPCIDevicePtr dev, virReportError(VIR_ERR_INTERNAL_ERROR, _("Active %s devices on bus with %s, not doing bus = reset"), conflict->name, dev->name); - virPCIDeviceFree(conflict); return -1; } =20 @@ -848,7 +846,6 @@ virPCIDeviceTrySecondaryBusReset(virPCIDevicePtr dev, =20 out: virPCIDeviceConfigClose(parent, parentfd); - virPCIDeviceFree(parent); return ret; } =20 @@ -1270,8 +1267,8 @@ virPCIDeviceBindToStubWithNewid(virPCIDevicePtr dev) VIR_AUTOFREE(char *) stubDriverPath =3D NULL; VIR_AUTOFREE(char *) driverLink =3D NULL; VIR_AUTOFREE(char *) path =3D NULL; /* reused for different purposes */ + VIR_AUTOPTR(virError) err =3D NULL; const char *stubDriverName =3D NULL; - virErrorPtr err =3D NULL; =20 /* Check the device is configured to use one of the known stub drivers= */ if (dev->stubDriver =3D=3D VIR_PCI_STUB_DRIVER_NONE) { @@ -1406,7 +1403,6 @@ virPCIDeviceBindToStubWithNewid(virPCIDevicePtr dev) =20 if (err) virSetError(err); - virFreeError(err); =20 return result; } @@ -1679,19 +1675,16 @@ virPCIGetAddrString(unsigned int domain, unsigned int function, char **pciConfigAddr) { - virPCIDevicePtr dev =3D NULL; - int ret =3D -1; + VIR_AUTOPTR(virPCIDevice) dev =3D NULL; =20 dev =3D virPCIDeviceNew(domain, bus, slot, function); if (dev !=3D NULL) { if (VIR_STRDUP(*pciConfigAddr, dev->name) < 0) - goto cleanup; - ret =3D 0; + return -1; + return 0; } =20 - cleanup: - virPCIDeviceFree(dev); - return ret; + return -1; } =20 virPCIDevicePtr @@ -1962,10 +1955,10 @@ virPCIDeviceListAddCopy(virPCIDeviceListPtr list, v= irPCIDevicePtr dev) =20 if (!copy) return -1; - if (virPCIDeviceListAdd(list, copy) < 0) { - virPCIDeviceFree(copy); + if (virPCIDeviceListAdd(list, copy) < 0) return -1; - } + + copy =3D NULL; return 0; } =20 @@ -2013,8 +2006,7 @@ void virPCIDeviceListDel(virPCIDeviceListPtr list, virPCIDevicePtr dev) { - virPCIDevicePtr ret =3D virPCIDeviceListSteal(list, dev); - virPCIDeviceFree(ret); + VIR_AUTOPTR(virPCIDevice) ret =3D virPCIDeviceListSteal(list, dev); } =20 int @@ -2168,22 +2160,18 @@ virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAd= dressPtr orig, static int virPCIDeviceGetIOMMUGroupAddOne(virPCIDeviceAddressPtr newDevAddr, void *o= paque) { - int ret =3D -1; virPCIDeviceListPtr groupList =3D opaque; - virPCIDevicePtr newDev; + VIR_AUTOPTR(virPCIDevice) newDev =3D NULL; =20 if (!(newDev =3D virPCIDeviceNew(newDevAddr->domain, newDevAddr->bus, newDevAddr->slot, newDevAddr->function)= )) - goto cleanup; + return -1; =20 if (virPCIDeviceListAdd(groupList, newDev) < 0) - goto cleanup; + return -1; =20 newDev =3D NULL; /* it's now on the list */ - ret =3D 0; - cleanup: - virPCIDeviceFree(newDev); - return ret; + return 0; } =20 =20 @@ -2395,7 +2383,7 @@ virPCIDeviceDownstreamLacksACS(virPCIDevicePtr dev) static int virPCIDeviceIsBehindSwitchLackingACS(virPCIDevicePtr dev) { - virPCIDevicePtr parent; + VIR_AUTOPTR(virPCIDevice) parent =3D NULL; =20 if (virPCIDeviceGetParent(dev, &parent) < 0) return -1; @@ -2419,14 +2407,13 @@ virPCIDeviceIsBehindSwitchLackingACS(virPCIDevicePt= r dev) * parent can be found */ do { - virPCIDevicePtr tmp; + VIR_AUTOPTR(virPCIDevice) tmp =3D NULL; int acs; int ret; =20 acs =3D virPCIDeviceDownstreamLacksACS(parent); =20 if (acs) { - virPCIDeviceFree(parent); if (acs < 0) return -1; else @@ -2435,7 +2422,6 @@ virPCIDeviceIsBehindSwitchLackingACS(virPCIDevicePtr = dev) =20 tmp =3D parent; ret =3D virPCIDeviceGetParent(parent, &parent); - virPCIDeviceFree(tmp); if (ret < 0) return -1; } while (parent); @@ -2940,7 +2926,7 @@ virPCIGetMdevTypes(const char *sysfspath, DIR *dir =3D NULL; struct dirent *entry; VIR_AUTOFREE(char *) types_path =3D NULL; - virMediatedDeviceTypePtr mdev_type =3D NULL; + VIR_AUTOPTR(virMediatedDeviceType) mdev_type =3D NULL; virMediatedDeviceTypePtr *mdev_types =3D NULL; size_t ntypes =3D 0; size_t i; @@ -2976,7 +2962,6 @@ virPCIGetMdevTypes(const char *sysfspath, ret =3D ntypes; ntypes =3D 0; cleanup: - virMediatedDeviceTypeFree(mdev_type); for (i =3D 0; i < ntypes; i++) virMediatedDeviceTypeFree(mdev_types[i]); VIR_FREE(mdev_types); --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list