From nobody Tue May 13 11:26:46 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 1532639492090137.75993241269362; Thu, 26 Jul 2018 14:11:32 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 077E23086262; Thu, 26 Jul 2018 21:11:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7972F63132; Thu, 26 Jul 2018 21:11:29 +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 79D7B4A465; Thu, 26 Jul 2018 21:11:28 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w6QLBNTJ027870 for ; Thu, 26 Jul 2018 17:11:23 -0400 Received: by smtp.corp.redhat.com (Postfix) id 82326CDFB7; Thu, 26 Jul 2018 21:11:23 +0000 (UTC) Received: from mx1.redhat.com (ext-mx20.extmail.prod.ext.phx2.redhat.com [10.5.110.49]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D8B63CE23F for ; Thu, 26 Jul 2018 21:05:42 +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 19E4C3086262 for ; Thu, 26 Jul 2018 21:05:41 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id y5-v6so1889791pgv.1 for ; Thu, 26 Jul 2018 14:05:41 -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.38 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 26 Jul 2018 14:05: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=wyzIetLjvJmYQCPMC2kOgiUPwV6GwoOEndQQyyBye2A=; b=Q4trJ+Ad5440KXgZ9uovEAGNnCcfyRGMWuBsfxcc1TnhJQAHHbQFRJ05WnG0l1isaX jPC7yICPZiRFIlq62CVwO+poJXlmdCjix8wNmGPbHe1jcXr4GIHA/ROqP93E6kAqrsJh smzlOUEYLf3JiZokGvD2eue1YhFwgFtL2kCr5CqtWzktkKN50qaT4ujxqCFJ4IYj/frj JBELjyRt6qwk1POP5fCUmHLcgKB+GaJGCpoKoHk7xNKPkU01Wl/xGJF4ssqzZ8YQt9pb zA4NeyWXdwJWgsbFu08jcNs+QfS2/x5qbWQbTjoZezLe6fxgLPp4fbnZA/Nj7wuNWDlo vajA== 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=wyzIetLjvJmYQCPMC2kOgiUPwV6GwoOEndQQyyBye2A=; b=oAiSEJBr3CXRzwbB7GK1cnkeSBLoIFBNun4bOkE81DCP+l6+xaBoQuIXYXzU17jpQJ 7aBaXW659i+KyFbeHfAySPjeO1AezfrXja/FsqAJJ2zXNXHRn0wGc5DhB3XxnGI0wN5m Snd7VTTWkG6OynFUidpICwPOjIvXmiH8KyKAGjEjKqO4V2LVrpQN8JXpSMJb50zoRDYm /vHmIBj3Km484jZVlW5DISIOJ5bzggj7R54iSW4XUOAQrtduk31QvJff/n5TZq98I1oR dSeX3XSQrpyoJXoFKxfn70oBo2aCL74/jVnnxsLhpu6GhBIAk8iI+OCrN5JqwHnWDbly Az0w== X-Gm-Message-State: AOUpUlGb917/PnMixd5LW/ICbt7opAFoWZYO4Wok60SZbh47L3bk2iMh FCZbVgdhT9Hzx0gwEATDLPJGM8EP X-Google-Smtp-Source: AAOMgpdMI2N31vPbeKNwzKKevtQNI/uZkRGtmYy3pMTZDIAxsKsF3VswUfcH1uyOCSOFfTzM2E3qjw== X-Received: by 2002:a62:dc1d:: with SMTP id t29-v6mr3726504pfg.244.1532639140327; Thu, 26 Jul 2018 14:05:40 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Tue, 24 Jul 2018 21:22:33 +0530 Message-Id: <1532447562-24010-33-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.49]); Thu, 26 Jul 2018 21:05:41 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Thu, 26 Jul 2018 21:05:41 +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.84 on 10.5.110.49 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.27 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 32/41] 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.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.49]); Thu, 26 Jul 2018 21:11:30 +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 d5075ac..492c42f 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