From nobody Mon Feb 9 18:59:53 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 1532175154914756.2543128277326; Sat, 21 Jul 2018 05:12:34 -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 12BEC87644; Sat, 21 Jul 2018 12:12:25 +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 D671D5D76F; Sat, 21 Jul 2018 12:12:24 +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 8D6DD1841C4A; Sat, 21 Jul 2018 12:12:23 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6LC90M6016612 for ; Sat, 21 Jul 2018 08:09:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 68B9A1062246; Sat, 21 Jul 2018 12:09:00 +0000 (UTC) Received: from mx1.redhat.com (ext-mx07.extmail.prod.ext.phx2.redhat.com [10.5.110.31]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5E0E2101F97D for ; Sat, 21 Jul 2018 12:08:51 +0000 (UTC) Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (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 DE5ECC04B940 for ; Sat, 21 Jul 2018 12:08:40 +0000 (UTC) Received: by mail-pg1-f170.google.com with SMTP id y4-v6so8960965pgp.9 for ; Sat, 21 Jul 2018 05:08:40 -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.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 21 Jul 2018 05:08:39 -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=3zXyA1x+cLxDjHMemVOlcE6bn3Dr9Q8SBY+/F4tAlPI=; b=D27r8Pwgu8dLhbXLHpBheGnXBsXbxktNk/eol8cHbhIIHqp+bPVwOSNQbxdIZByjxG nlE7zQgCEFyMSz0Jrvp7AnRYBD4w+jhUoZTkKoPhZgP0TnNmvKrg1jkXzjQ2ztCtc9xj i/z5q8BdVzsNnxWXzEr8fJ0GUisO9rnMUat8vcuPGn/5ionA41KACywdjZ4nnEcBCU0K GikOG7/JyhBLRmvEV/JPwrI12lWSzeLaJVr2Y68JXvu/BIc54zHFkZ+sGUKBMrJhPn4K HSnPLeApTkGN/ydwAEuBn/FBJOOhnJNKRiS0fDPoxsMauTs2MD52huE88oeIaPjePzYA UL4w== 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=3zXyA1x+cLxDjHMemVOlcE6bn3Dr9Q8SBY+/F4tAlPI=; b=iapCXEm0wGeMvix0k2ov0UILiCAcpjMCItyd2X6gcI7lQR7a21ZzLWkRISliZyXGB6 OaZx9XnI6l5W+ged5y9N43HCq3SHTyRdv/NvkXde6ylYgzPvEM8/5QKm8ioJfGkKdLZq BHza5n2/Go8eye2iHq5AVR2f5M7rsVJLXBjMgFJp+qG52zodHeAzN20cC8+015vN0Rsd zRzmE8X3FeoxJTeqGkDG2AN0PdeM5Je1pQS1Azu26DR77WubF8tXwoelYL7yZ+Jb2+7i GR+0+X9v04iJYOQFAcDwJJeFv8Bh2VYzv1CEYPxY5Ga05FHz0ato3BVjb8qsUsT9oklb ZHrw== X-Gm-Message-State: AOUpUlHxRCt6v0KbaAGeZCvvVOg74vp33t1+tkQ3DtzY1MXDXYF1ycfJ HN/KvUhoqKm+or2NQTf4vefaYfBw X-Google-Smtp-Source: AAOMgpd+56y/bjoQfR2d1M2BWaeNtt//v1/YId94WzLLPuGIjXlMGmyxcqSjF71g1hQ6/OP+lQSC/A== X-Received: by 2002:a65:5307:: with SMTP id m7-v6mr5546426pgq.431.1532174920158; Sat, 21 Jul 2018 05:08:40 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Sat, 21 Jul 2018 17:37:03 +0530 Message-Id: <1532174832-21644-32-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.31]); Sat, 21 Jul 2018 12:08:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 21 Jul 2018 12:08:41 +0000 (UTC) for IP:'209.85.215.170' DOMAIN:'mail-pg1-f170.google.com' HELO:'mail-pg1-f170.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.215.170 mail-pg1-f170.google.com 209.85.215.170 mail-pg1-f170.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.31 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v1 31/40] util: hostdev: use VIR_AUTOFREE instead of VIR_FREE for scalar 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.26]); Sat, 21 Jul 2018 12:12:34 +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_AUTOFREE macro for declaring scalar variables, majority of the VIR_FREE calls 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 | 91 +++++++++++++++++------------------------------= ---- 1 file changed, 30 insertions(+), 61 deletions(-) diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index f4bd19d..c4335a9 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -186,17 +186,14 @@ virHostdevManagerNew(void) goto error; } } else { - char *rundir =3D NULL; + VIR_AUTOFREE(char *) rundir =3D NULL; mode_t old_umask; =20 if (!(rundir =3D virGetUserRuntimeDirectory())) goto error; =20 - if (virAsprintf(&hostdevMgr->stateDir, "%s/hostdevmgr", rundir) < = 0) { - VIR_FREE(rundir); + if (virAsprintf(&hostdevMgr->stateDir, "%s/hostdevmgr", rundir) < = 0) goto error; - } - VIR_FREE(rundir); =20 old_umask =3D umask(077); =20 @@ -289,17 +286,12 @@ virHostdevPCISysfsPath(virDomainHostdevDefPtr hostdev, static int virHostdevIsVirtualFunction(virDomainHostdevDefPtr hostdev) { - char *sysfs_path =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) sysfs_path =3D NULL; =20 if (virHostdevPCISysfsPath(hostdev, &sysfs_path) < 0) - return ret; + return -1; =20 - ret =3D virPCIIsVirtualFunction(sysfs_path); - - VIR_FREE(sysfs_path); - - return ret; + return virPCIIsVirtualFunction(sysfs_path); } =20 =20 @@ -309,17 +301,15 @@ virHostdevNetDevice(virDomainHostdevDefPtr hostdev, char **linkdev, int *vf) { - int ret =3D -1; - char *sysfs_path =3D NULL; + VIR_AUTOFREE(char *) sysfs_path =3D NULL; =20 if (virHostdevPCISysfsPath(hostdev, &sysfs_path) < 0) - return ret; + return -1; =20 if (virPCIIsVirtualFunction(sysfs_path) =3D=3D 1) { if (virPCIGetVirtualFunctionInfo(sysfs_path, pfNetDevIdx, - linkdev, vf) < 0) { - goto cleanup; - } + linkdev, vf) < 0) + return -1; } else { /* In practice this should never happen, since we currently * only support assigning SRIOV VFs via parent.data.net); virtPort =3D virDomainNetGetActualVirtPortProfile(hostdev->parent.data= .net); @@ -507,24 +487,19 @@ virHostdevSetNetConfig(virDomainHostdevDefPtr hostdev, _("direct setting of the vlan tag is not allowe= d " "for hostdev devices using %s mode"), virNetDevVPortTypeToString(virtPort->virtPortTy= pe)); - goto cleanup; + return -1; } if (virHostdevNetConfigVirtPortProfile(linkdev, vf, virtPort, &hostdev->parent.data.net->= mac, - uuid, port_profile_associat= e) < 0) { - goto cleanup; - } + uuid, port_profile_associat= e) < 0) + return -1; } else { if (virNetDevSetNetConfig(linkdev, vf, &hostdev->parent.data.net->= mac, - vlan, NULL, true) < 0) { - goto cleanup; - } + vlan, NULL, true) < 0) + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(linkdev); - return ret; + return 0; } =20 =20 @@ -540,13 +515,13 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr hos= tdev, const char *stateDir, const char *oldStateDir) { - char *linkdev =3D NULL; + VIR_AUTOFREE(char *) linkdev =3D NULL; + VIR_AUTOFREE(virMacAddrPtr) MAC =3D NULL; + VIR_AUTOFREE(virMacAddrPtr) adminMAC =3D NULL; virNetDevVPortProfilePtr virtPort; int ret =3D -1; int vf =3D -1; bool port_profile_associate =3D false; - virMacAddrPtr MAC =3D NULL; - virMacAddrPtr adminMAC =3D NULL; virNetDevVlanPtr vlan =3D NULL; =20 =20 @@ -656,9 +631,6 @@ virHostdevRestoreNetConfig(virDomainHostdevDefPtr hostd= ev, } =20 cleanup: - VIR_FREE(linkdev); - VIR_FREE(MAC); - VIR_FREE(adminMAC); virNetDevVlanFree(vlan); =20 return ret; @@ -763,8 +735,8 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, mgr->inactivePCIHostdevs) < 0) goto reattachdevs; } else { - char *driverPath; - char *driverName; + VIR_AUTOFREE(char *) driverPath =3D NULL; + VIR_AUTOFREE(char *) driverName =3D NULL; int stub; =20 /* Unmanaged devices should already have been marked as @@ -790,9 +762,6 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, =20 stub =3D virPCIStubDriverTypeFromString(driverName); =20 - VIR_FREE(driverPath); - VIR_FREE(driverName); - if (stub > VIR_PCI_STUB_DRIVER_NONE && stub < VIR_PCI_STUB_DRIVER_LAST) { =20 --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list