From nobody Tue May 13 11:11:34 2025 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 1532639140887876.5034887553155; Thu, 26 Jul 2018 14:05:40 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2FC1130024D6; Thu, 26 Jul 2018 21:05:39 +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 D498D5D755; Thu, 26 Jul 2018 21:05:38 +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 7ECCE1800CAC; Thu, 26 Jul 2018 21:05:38 +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 w6QL5TJq024910 for ; Thu, 26 Jul 2018 17:05:29 -0400 Received: by smtp.corp.redhat.com (Postfix) id D36F96017F; Thu, 26 Jul 2018 21:05:29 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id AB45660175 for ; Thu, 26 Jul 2018 21:05:20 +0000 (UTC) Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) (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 C6DFB36809 for ; Thu, 26 Jul 2018 21:05:19 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id z8-v6so1882609pgu.8 for ; Thu, 26 Jul 2018 14:05:19 -0700 (PDT) Received: from centos.localdomain ([42.106.3.93]) by smtp.gmail.com with ESMTPSA id z10-v6sm3279182pfh.83.2018.07.26.14.05.17 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jul 2018 14:05:18 -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=UtLtmzrymPaZ9jWQrs44Tw6dgVJ/iCFvGVKrAQHvrUA=; b=cy1PTt3+EJUBD5qrvazjo8QlITHxeO8FPnlUnq8yYNA5Lh6uMrssduUtksr4YvWlFq B4dMb95mZyHxj2ouCigoZ459BuNojxjdXZqUwu+UbCNp2X8YH0rEeCJvyOgAS+rP1z7t PpuqB4JaczFG7wTzdY+D5wJsFxgoC6XDDg8v2Ygg30nix4izO4ZWbPivtqNP5joxDh1i quVfdaK8i7GWMjWh9+UQsgoasVXDHkN4oqiZ4yaUHEj30sqHBu4A5CGQ5Ekui96Jg64U nUWx1sebfGqzOannI3onjHZHHS5jUkV/aE5JJWbIfRVjD1Ymwbb3rK0paMR6atP+xJk1 CQoA== 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=UtLtmzrymPaZ9jWQrs44Tw6dgVJ/iCFvGVKrAQHvrUA=; b=QdgcHzRvnwiTEroTEDtbcJBNLmtYqNZXQwM++cZ2FM5kshZXlJ5XM7LfEDtJgo/wAK 6/SavxEfpe9SDHQmfvQo+OwGshhMlciK27gUA1JBHJs75uouF3DeygDz7pKiEXuZUdia WQ7t0tWVx4Oy4C3skmmI5GqIUK8U9Rn3tBOCC6D+pVvVCrgOFgQTb2K2u+Y4aT13UyIc uo+cCmT+krn0PC15zIDXDyDnUmqVlf74K+s9fszZSZuCw7W9qD4B87x0Rwxa13gmBorg 3YxqVvLuVBSbBVry235jsxNIkmeFMfNUCAcul8LFUs1H0uLFkklIedpJPCw7itm0qTW8 pP1A== X-Gm-Message-State: AOUpUlGSgtCtTTDdGJWAJvS7TQ+9aPaYdScxJgh/dSoz2wn966AzbT/K fLQo6UNjvyj/bzXZDfK3JoyNR0ud X-Google-Smtp-Source: AAOMgpe95AJmYISNasGBtrPZc5OPzBClw9+rES6AU2CYkPEQP/HQI2DagVDu+8x1CxsF289L/kEZ2Q== X-Received: by 2002:a63:ef10:: with SMTP id u16-v6mr3401515pgh.269.1532639118991; Thu, 26 Jul 2018 14:05:18 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Tue, 24 Jul 2018 21:22:22 +0530 Message-Id: <1532447562-24010-22-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1532447562-24010-1-git-send-email-skrtbhtngr@gmail.com> References: <1532447562-24010-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.30]); Thu, 26 Jul 2018 21:05:19 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 26 Jul 2018 21:05:19 +0000 (UTC) for IP:'209.85.215.194' DOMAIN:'mail-pg1-f194.google.com' HELO:'mail-pg1-f194.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: 1.389 * (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, RCVD_IN_SORBS_WEB, SPF_PASS) 209.85.215.194 mail-pg1-f194.google.com 209.85.215.194 mail-pg1-f194.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 21/41] 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.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.43]); Thu, 26 Jul 2018 21:05:39 +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 | 78 +++++++++++++++++++++------------------------------= ---- 1 file changed, 29 insertions(+), 49 deletions(-) diff --git a/src/util/virpci.c b/src/util/virpci.c index 1b3e52f..634df8d 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,13 @@ 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; - } + if (!dev || VIR_STRDUP(*pciConfigAddr, dev->name) < 0) + return -1; =20 - cleanup: - virPCIDeviceFree(dev); - return ret; + return 0; } =20 virPCIDevicePtr @@ -1700,7 +1690,8 @@ virPCIDeviceNew(unsigned int domain, unsigned int slot, unsigned int function) { - virPCIDevicePtr dev; + virPCIDevicePtr ret =3D NULL; + VIR_AUTOPTR(virPCIDevice) dev =3D NULL; VIR_AUTOFREE(char *) vendor =3D NULL; VIR_AUTOFREE(char *) product =3D NULL; =20 @@ -1717,17 +1708,17 @@ virPCIDeviceNew(unsigned int domain, virReportError(VIR_ERR_INTERNAL_ERROR, _("dev->name buffer overflow: %.4x:%.2x:%.2x.%.1x"), domain, bus, slot, function); - goto error; + goto cleanup; } if (virAsprintf(&dev->path, PCI_SYSFS "devices/%s/config", dev->name) < 0) - goto error; + goto cleanup; =20 if (!virFileExists(dev->path)) { virReportSystemError(errno, _("Device %s not found: could not access %s"), dev->name, dev->path); - goto error; + goto cleanup; } =20 vendor =3D virPCIDeviceReadID(dev, "vendor"); @@ -1737,7 +1728,7 @@ virPCIDeviceNew(unsigned int domain, virReportError(VIR_ERR_INTERNAL_ERROR, _("Failed to read product/vendor ID for %s"), dev->name); - goto error; + goto cleanup; } =20 /* strings contain '0x' prefix */ @@ -1746,18 +1737,15 @@ virPCIDeviceNew(unsigned int domain, virReportError(VIR_ERR_INTERNAL_ERROR, _("dev->id buffer overflow: %s %s"), &vendor[2], &product[2]); - goto error; + goto cleanup; } =20 VIR_DEBUG("%s %s: initialized", dev->id, dev->name); =20 - cleanup: - return dev; + VIR_STEAL_PTR(ret, dev); =20 - error: - virPCIDeviceFree(dev); - dev =3D NULL; - goto cleanup;; + cleanup: + return ret; } =20 =20 @@ -1960,14 +1948,14 @@ virPCIDeviceListAdd(virPCIDeviceListPtr list, int virPCIDeviceListAddCopy(virPCIDeviceListPtr list, virPCIDevicePtr dev) { - virPCIDevicePtr copy =3D virPCIDeviceCopy(dev); + VIR_AUTOPTR(virPCIDevice) copy =3D virPCIDeviceCopy(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 @@ -2015,8 +2003,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 @@ -2170,22 +2157,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 @@ -2397,7 +2380,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; @@ -2421,14 +2404,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 @@ -2437,7 +2419,6 @@ virPCIDeviceIsBehindSwitchLackingACS(virPCIDevicePtr = dev) =20 tmp =3D parent; ret =3D virPCIDeviceGetParent(parent, &parent); - virPCIDeviceFree(tmp); if (ret < 0) return -1; } while (parent); @@ -2942,7 +2923,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; @@ -2978,7 +2959,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