From nobody Tue May 13 11:24:16 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 1532639152791558.5769336159414; Thu, 26 Jul 2018 14:05:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id C951930832E2; Thu, 26 Jul 2018 21:05:50 +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 8217D100164C; Thu, 26 Jul 2018 21:05:50 +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 1E1D01800B71; Thu, 26 Jul 2018 21:05:50 +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 w6QL5ne5025037 for ; Thu, 26 Jul 2018 17:05:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 2F7D46017E; Thu, 26 Jul 2018 21:05:49 +0000 (UTC) Received: from mx1.redhat.com (ext-mx17.extmail.prod.ext.phx2.redhat.com [10.5.110.46]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 24AAD60177 for ; Thu, 26 Jul 2018 21:05:44 +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 296D33001768 for ; Thu, 26 Jul 2018 21:05:43 +0000 (UTC) Received: by mail-pl0-f68.google.com with SMTP id f6-v6so1351045plo.1 for ; Thu, 26 Jul 2018 14:05:43 -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.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jul 2018 14:05:41 -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=GOWS4nNPlHqtmvZ3uIeEEia9+jmvqr15cQJJa07uw1w=; b=hd758E/OdQy4qVqP3yYUSEOrb6p1eVQQdpFysESyU1KcudBJe8iTYbi+bIk14BD2ye baxU4s2rwY5FGTB5sa7oOTRYJd8T0oJsTyDk7j4EQg8zW/V7Lzv44gHcWyk/mpjtHaxX iu73xZVKM3Wl3G1Zu4CbJXEfLuyj5p+hKu5B4OZPGEjKgW5vu9c2lWkElYo2+K2H1Ers vmBlNosQDVMKa97OdwI2KMAFyaebYybDlD4jwgxgruiAfJ+4i0ha0b1TF5nV9xbrEqRK ZLhiYA5w5oNGHgaAB+gT9Yj7z94sR9+kfNlqMh8mt4PW1n6Uo1aT4xG8NHFT6oKseDRY LS1Q== 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=GOWS4nNPlHqtmvZ3uIeEEia9+jmvqr15cQJJa07uw1w=; b=VjEKcb+FtJKs9KMaYyBqruJ30+Vq3L5X4FWYK0mQUzhUU+sDxrOmjLEBHidYcJQAsP yLHqJKH/eIGvZrBousSdtdp/ROesDSROZiejg+Owc+Umki45KciyUNQw6I+P8axJBIT5 c7oLds9WnUYn70daS6MYlW4T/Jj7GOw1qrLnqaGht8hNm91SSTLfc5i9WkajVkfssfoa ZNLQh7IYtSdeWVG/Gz786bHY2e0IoNHutepzsHH9fyyNgDHLNjDRPo5BpExi/oWQH3yL wN/sLsJuJ8raVEK4xTp+PlBXUkTUprsuvdoq29tbHJXeJQ7gQvvyccn2fCmWoDjbdqMC AYSg== X-Gm-Message-State: AOUpUlG9xnLXKPNW18u/tlmfBPaPeYWeLKt3FBfZ/FLCC7l8dBWiV6Z2 wQNyQaHUJLtrJXW5C6F1/C/tRBDV X-Google-Smtp-Source: AAOMgpfwL17Qz9WD24VpOBwmN3Vozy3DVbIvXEVFB/iVW/7CyXbbPYuX5ygkc2M4TPehz+iwDugGGg== X-Received: by 2002:a17:902:b412:: with SMTP id x18-v6mr1427177plr.203.1532639142204; Thu, 26 Jul 2018 14:05:42 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Tue, 24 Jul 2018 21:22:34 +0530 Message-Id: <1532447562-24010-34-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.46]); Thu, 26 Jul 2018 21:05:43 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.46]); Thu, 26 Jul 2018 21:05:43 +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.37 * (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, SPF_PASS) 209.85.160.68 mail-pl0-f68.google.com 209.85.160.68 mail-pl0-f68.google.com X-Scanned-By: MIMEDefang 2.84 on 10.5.110.46 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 33/41] util: hostdev: 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.22 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Thu, 26 Jul 2018 21:05:51 +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 Reviewed-by: Erik Skultety --- src/util/virhostdev.c | 71 ++++++++++++++++++-----------------------------= ---- 1 file changed, 25 insertions(+), 46 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index 492c42f..ca79c37 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -518,11 +518,10 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr hos= tdev, VIR_AUTOFREE(char *) linkdev =3D NULL; VIR_AUTOFREE(virMacAddrPtr) MAC =3D NULL; VIR_AUTOFREE(virMacAddrPtr) adminMAC =3D NULL; + VIR_AUTOPTR(virNetDevVlan) vlan =3D NULL; virNetDevVPortProfilePtr virtPort; - int ret =3D -1; int vf =3D -1; bool port_profile_associate =3D false; - virNetDevVlanPtr vlan =3D NULL; =20 =20 /* This is only needed for PCI devices that have been defined @@ -535,16 +534,16 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr hos= tdev, virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Interface type hostdev is currently supported on" " SR-IOV Virtual Functions only")); - return ret; + return -1; } =20 if (virHostdevNetDevice(hostdev, 0, &linkdev, &vf) < 0) - return ret; + return -1; =20 virtPort =3D virDomainNetGetActualVirtPortProfile( hostdev->parent.data.net); if (virtPort) { - ret =3D virHostdevNetConfigVirtPortProfile(linkdev, vf, virtPort, + return virHostdevNetConfigVirtPortProfile(linkdev, vf, virtPort, &hostdev->parent.data.net= ->mac, NULL, port_profile_associate); @@ -574,7 +573,7 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr hostd= ev, /* 1) standard location */ if (virNetDevReadNetConfig(linkdev, vf, stateDir, &adminMAC, &vlan, &MAC) < 0) { - goto cleanup; + return -1; } =20 /* 2) "old" (pre-1.2.3 circa 2014) location - whenever we get @@ -585,7 +584,7 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr hostd= ev, if (!(adminMAC || vlan || MAC) && oldStateDir && virNetDevReadNetConfig(linkdev, vf, oldStateDir, &adminMAC, &vlan, &MAC) < 0) { - goto cleanup; + return -1; } =20 /* 3) try using the PF's "port 2" netdev as the name of the @@ -597,7 +596,7 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr hostd= ev, if (virHostdevNetDevice(hostdev, 1, &linkdev, &vf) < 0 || virNetDevReadNetConfig(linkdev, vf, stateDir, &adminMAC, &vlan, &MAC) < 0) { - goto cleanup; + return -1; } } =20 @@ -627,13 +626,8 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr host= dev, =20 ignore_value(virNetDevSetNetConfig(linkdev, vf, adminMAC, vlan, MAC, true)); - ret =3D 0; + return 0; } - - cleanup: - virNetDevVlanFree(vlan); - - return ret; } =20 int @@ -1117,7 +1111,6 @@ virHostdevUpdateActivePCIDevices(virHostdevManagerPtr= mgr, const char *dom_name) { virDomainHostdevDefPtr hostdev =3D NULL; - virPCIDevicePtr actual =3D NULL; size_t i; int ret =3D -1; =20 @@ -1128,6 +1121,7 @@ virHostdevUpdateActivePCIDevices(virHostdevManagerPtr= mgr, virObjectLock(mgr->inactivePCIHostdevs); =20 for (i =3D 0; i < nhostdevs; i++) { + VIR_AUTOPTR(virPCIDevice) actual =3D NULL; virDomainHostdevSubsysPCIPtr pcisrc; hostdev =3D hostdevs[i]; pcisrc =3D &hostdev->source.subsys.u.pci; @@ -1165,7 +1159,6 @@ virHostdevUpdateActivePCIDevices(virHostdevManagerPtr= mgr, =20 ret =3D 0; cleanup: - virPCIDeviceFree(actual); virObjectUnlock(mgr->activePCIHostdevs); virObjectUnlock(mgr->inactivePCIHostdevs); return ret; @@ -1226,31 +1219,27 @@ virHostdevUpdateActiveSCSIHostDevices(virHostdevMan= agerPtr mgr, virDomainHostdevSubsysSCSIHostPtr scsihostsrc =3D &scsisrc->u.host; virSCSIDevicePtr scsi =3D NULL; virSCSIDevicePtr tmp =3D NULL; - int ret =3D -1; =20 if (!(scsi =3D virSCSIDeviceNew(NULL, scsihostsrc->adapter, scsihostsrc->bus, scsihostsrc->target, scsihostsrc->unit, hostdev->readonly, hostdev->shareable))) - goto cleanup; + return -1; =20 if ((tmp =3D virSCSIDeviceListFind(mgr->activeSCSIHostdevs, scsi))) { if (virSCSIDeviceSetUsedBy(tmp, drv_name, dom_name) < 0) { virSCSIDeviceFree(scsi); - goto cleanup; + return -1; } virSCSIDeviceFree(scsi); } else { if (virSCSIDeviceSetUsedBy(scsi, drv_name, dom_name) < 0 || virSCSIDeviceListAdd(mgr->activeSCSIHostdevs, scsi) < 0) { virSCSIDeviceFree(scsi); - goto cleanup; + return -1; } } - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 int @@ -1301,7 +1290,7 @@ virHostdevUpdateActiveMediatedDevices(virHostdevManag= erPtr mgr, { int ret =3D -1; size_t i; - virMediatedDevicePtr mdev =3D NULL; + VIR_AUTOPTR(virMediatedDevice) mdev =3D NULL; =20 if (nhostdevs =3D=3D 0) return 0; @@ -1327,7 +1316,6 @@ virHostdevUpdateActiveMediatedDevices(virHostdevManag= erPtr mgr, =20 ret =3D 0; cleanup: - virMediatedDeviceFree(mdev); virObjectUnlock(mgr->activeMediatedHostdevs); return ret; } @@ -1560,29 +1548,25 @@ virHostdevPrepareSCSIHostDevices(virDomainHostdevDe= fPtr hostdev, { virDomainHostdevSubsysSCSIHostPtr scsihostsrc =3D &scsisrc->u.host; virSCSIDevicePtr scsi; - int ret =3D -1; =20 if (hostdev->managed) { virReportError(VIR_ERR_XML_ERROR, "%s", _("SCSI host device doesn't support managed mode")); - goto cleanup; + return -1; } =20 if (!(scsi =3D virSCSIDeviceNew(NULL, scsihostsrc->adapter, scsihostsrc->bus, scsihostsrc->target, scsihostsrc->unit, hostdev->readonly, hostdev->shareable))) - goto cleanup; + return -1; =20 if (virSCSIDeviceListAdd(list, scsi) < 0) { virSCSIDeviceFree(scsi); - goto cleanup; + return -1; } =20 - ret =3D 0; - - cleanup: - return ret; + return 0; } =20 int @@ -1859,7 +1843,8 @@ virHostdevReAttachUSBDevices(virHostdevManagerPtr mgr, for (i =3D 0; i < nhostdevs; i++) { virDomainHostdevDefPtr hostdev =3D hostdevs[i]; virDomainHostdevSubsysUSBPtr usbsrc =3D &hostdev->source.subsys.u.= usb; - virUSBDevicePtr usb, tmp; + VIR_AUTOPTR(virUSBDevice) usb =3D NULL; + virUSBDevicePtr tmp; const char *usedby_drvname; const char *usedby_domname; =20 @@ -1883,7 +1868,6 @@ virHostdevReAttachUSBDevices(virHostdevManagerPtr mgr, * the list which were taken by @name */ =20 tmp =3D virUSBDeviceListFind(mgr->activeUSBHostdevs, usb); - virUSBDeviceFree(usb); =20 if (!tmp) { VIR_WARN("Unable to find device %03d.%03d " @@ -1911,7 +1895,7 @@ virHostdevReAttachSCSIHostDevices(virHostdevManagerPt= r mgr, const char *dom_name) { virDomainHostdevSubsysSCSIHostPtr scsihostsrc =3D &scsisrc->u.host; - virSCSIDevicePtr scsi; + VIR_AUTOPTR(virSCSIDevice) scsi =3D NULL; virSCSIDevicePtr tmp; =20 if (!(scsi =3D virSCSIDeviceNew(NULL, @@ -1932,7 +1916,6 @@ virHostdevReAttachSCSIHostDevices(virHostdevManagerPt= r mgr, "in list of active SCSI devices", scsihostsrc->adapter, scsihostsrc->bus, scsihostsrc->target, scsihostsrc->unit); - virSCSIDeviceFree(scsi); return; } =20 @@ -1942,7 +1925,6 @@ virHostdevReAttachSCSIHostDevices(virHostdevManagerPt= r mgr, =20 virSCSIDeviceListDel(mgr->activeSCSIHostdevs, tmp, drv_name, dom_name); - virSCSIDeviceFree(scsi); } =20 void @@ -1982,14 +1964,14 @@ virHostdevReAttachSCSIVHostDevices(virHostdevManage= rPtr mgr, int nhostdevs) { size_t i; - virSCSIVHostDevicePtr host, tmp; - =20 if (!nhostdevs) return; =20 virObjectLock(mgr->activeSCSIVHostHostdevs); for (i =3D 0; i < nhostdevs; i++) { + VIR_AUTOPTR(virSCSIVHostDevice) host =3D NULL; + virSCSIVHostDevicePtr tmp; virDomainHostdevDefPtr hostdev =3D hostdevs[i]; virDomainHostdevSubsysSCSIVHostPtr hostsrc =3D &hostdev->source.su= bsys.u.scsi_host; const char *usedby_drvname; @@ -2017,7 +1999,6 @@ virHostdevReAttachSCSIVHostDevices(virHostdevManagerP= tr mgr, VIR_WARN("Unable to find device %s " "in list of active SCSI_host devices", hostsrc->wwpn); - virSCSIVHostDeviceFree(host); virObjectUnlock(mgr->activeSCSIVHostHostdevs); return; } @@ -2031,8 +2012,6 @@ virHostdevReAttachSCSIVHostDevices(virHostdevManagerP= tr mgr, =20 virSCSIVHostDeviceListDel(mgr->activeSCSIVHostHostdevs, tmp); } - - virSCSIVHostDeviceFree(host); } virObjectUnlock(mgr->activeSCSIVHostHostdevs); } @@ -2060,7 +2039,8 @@ virHostdevReAttachMediatedDevices(virHostdevManagerPt= r mgr, =20 virObjectLock(mgr->activeMediatedHostdevs); for (i =3D 0; i < nhostdevs; i++) { - virMediatedDevicePtr mdev, tmp; + VIR_AUTOPTR(virMediatedDevice) mdev =3D NULL; + virMediatedDevicePtr tmp; virDomainHostdevSubsysMediatedDevPtr mdevsrc; virDomainHostdevDefPtr hostdev =3D hostdevs[i]; =20 @@ -2076,7 +2056,6 @@ virHostdevReAttachMediatedDevices(virHostdevManagerPt= r mgr, /* Remove from the list only mdevs assigned to @drv_name/@dom_name= */ =20 tmp =3D virMediatedDeviceListFind(mgr->activeMediatedHostdevs, mde= v); - virMediatedDeviceFree(mdev); =20 /* skip inactive devices */ if (!tmp) --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list