From nobody Mon Feb 9 21:24:24 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 153371421912647.216006076011695; Wed, 8 Aug 2018 00:43:39 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4C8493BEB9; Wed, 8 Aug 2018 07:43:36 +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 0D77C308BDA4; Wed, 8 Aug 2018 07:43:36 +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 B026318037F3; Wed, 8 Aug 2018 07:43:35 +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 w787hY2W005576 for ; Wed, 8 Aug 2018 03:43:34 -0400 Received: by smtp.corp.redhat.com (Postfix) id 774441001F58; Wed, 8 Aug 2018 07:43:34 +0000 (UTC) Received: from mx1.redhat.com (ext-mx02.extmail.prod.ext.phx2.redhat.com [10.5.110.26]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6C9321001F49 for ; Wed, 8 Aug 2018 07:43:32 +0000 (UTC) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) (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 8259F12C36 for ; Wed, 8 Aug 2018 07:43:30 +0000 (UTC) Received: by mail-pf1-f193.google.com with SMTP id d4-v6so731816pfn.0 for ; Wed, 08 Aug 2018 00:43:30 -0700 (PDT) Received: from centos.localdomain ([42.106.0.165]) by smtp.gmail.com with ESMTPSA id 9-v6sm9617719pfv.53.2018.08.08.00.43.27 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 08 Aug 2018 00:43:29 -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=wM23RG5V4e8Ui2JeloUpfqNL6vec0/WNB8YfTH0M0io=; b=sQoC7T72aJlWUzw/aK9hoEJrqhM+NAqKWnn4L5IONBkWCn/NwXch7CdpMN7C7sW1CW 3/6YMcJ6c2e+ckZuIGGIdbMIHbt3J2DaJVelcHWbmNjQZgqDVtf7HwynVNRzCegeN10n cxxAhoFejjFqnV4V2bXnfucTQOXSU+oySLqFJFgWbNeHwwQT3vtSEgQy71OzBNPwu7Or T3t/RdIlOTCbW/S9qMZ1zBpgtXTuE5ZxABtRc0VR36Rw98yd6gI8O4ZldtmjlJ8HIwt2 4NBHYIdjtyJ4enhkl9Sf+AaYiMOBx022O4C2+B2csVue3Wy4oXaWB0jmFOhkg37ZsYTi 2+IA== 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=wM23RG5V4e8Ui2JeloUpfqNL6vec0/WNB8YfTH0M0io=; b=jpJCK3tqTi7Kh1EgBsmFvYPPaMPh/9ZRyLDSFZgPte6yuLgxrqU4aEjWY3xjYxHTCz AbOTgChE+pvpqlu1qkVh2P5tpWpKCc05XRzhQfYWM0ZEZghuRpWw6jWxyPYtHrZ+THPT YAfeCQcEqKtzyJ7siNo7HnAUg3d6u0rkT0PHXhsKAuHn5XhIWhqrUJaNoXcB+le1ahoM niEc6fpa9fCTW1kZS4Kq/QPefmMVaAJ2DC7PM8USgxlyM/dhlJTIfDFERAJQT2fSHzGu WjK7sXoWs1UaHm7e/3YNvmJWkelOGrg97S5ijN5N/jOpXDAa4LA7iZkv9fDJmVN1hv1u rhOA== X-Gm-Message-State: AOUpUlEfAyuzvBb0wNtGsCSS6zepcqc7Se4vnPlMvVis2aMNvuo4bR2y ntjiadItXmvIvVUv6uD0Ty6lKCT6 X-Google-Smtp-Source: AA+uWPyzGAIDfw8rjLMtNrcJ+JNMT1VDfe433oDe4hFnZg93YdnClUOHeuSDfRfJweklpHYKlgaiUA== X-Received: by 2002:a63:fd52:: with SMTP id m18-v6mr1464029pgj.304.1533714209657; Wed, 08 Aug 2018 00:43:29 -0700 (PDT) From: Sukrit Bhatnagar To: libvir-list@redhat.com Date: Mon, 6 Aug 2018 02:13:37 +0530 Message-Id: <1533501842-24503-11-git-send-email-skrtbhtngr@gmail.com> In-Reply-To: <1533501842-24503-1-git-send-email-skrtbhtngr@gmail.com> References: <1533501842-24503-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.26]); Wed, 08 Aug 2018 07:43:30 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 08 Aug 2018 07:43:30 +0000 (UTC) for IP:'209.85.210.193' DOMAIN:'mail-pf1-f193.google.com' HELO:'mail-pf1-f193.google.com' FROM:'skrtbhtngr@gmail.com' RCPT:'' X-RedHat-Spam-Score: -0.13 (DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_PASS) 209.85.210.193 mail-pf1-f193.google.com 209.85.210.193 mail-pf1-f193.google.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.26 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com Subject: [libvirt] [PATCH v2 10/35] util: netdev: 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.84 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Wed, 08 Aug 2018 07:43:37 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_1 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 --- src/util/virnetdev.c | 328 +++++++++++++++++++----------------------------= ---- 1 file changed, 119 insertions(+), 209 deletions(-) diff --git a/src/util/virnetdev.c b/src/util/virnetdev.c index 9eca786..5651f6f 100644 --- a/src/util/virnetdev.c +++ b/src/util/virnetdev.c @@ -535,18 +535,17 @@ int virNetDevSetMTUFromDevice(const char *ifname, */ int virNetDevSetNamespace(const char *ifname, pid_t pidInNs) { - int ret =3D -1; - char *pid =3D NULL; - char *phy =3D NULL; - char *phy_path =3D NULL; int len; + VIR_AUTOFREE(char *) pid =3D NULL; + VIR_AUTOFREE(char *) phy =3D NULL; + VIR_AUTOFREE(char *) phy_path =3D NULL; =20 if (virAsprintf(&pid, "%lld", (long long) pidInNs) =3D=3D -1) return -1; =20 /* The 802.11 wireless devices only move together with their PHY. */ if (virNetDevSysfsFile(&phy_path, ifname, "phy80211/name") < 0) - goto cleanup; + return -1; =20 if ((len =3D virFileReadAllQuiet(phy_path, 1024, &phy)) <=3D 0) { /* Not a wireless device. */ @@ -556,7 +555,7 @@ int virNetDevSetNamespace(const char *ifname, pid_t pid= InNs) =20 argv[5] =3D pid; if (virRun(argv, NULL) < 0) - goto cleanup; + return -1; =20 } else { const char *argv[] =3D { @@ -569,15 +568,10 @@ int virNetDevSetNamespace(const char *ifname, pid_t p= idInNs) argv[2] =3D phy; argv[5] =3D pid; if (virRun(argv, NULL) < 0) - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(phy_path); - VIR_FREE(phy); - VIR_FREE(pid); - return ret; + return 0; } =20 #if defined(SIOCSIFNAME) && defined(HAVE_STRUCT_IFREQ) @@ -969,25 +963,21 @@ int virNetDevGetIndex(const char *ifname ATTRIBUTE_UN= USED, int virNetDevGetMaster(const char *ifname, char **master) { - int ret =3D -1; - void *nlData =3D NULL; struct nlattr *tb[IFLA_MAX + 1] =3D {NULL, }; + VIR_AUTOFREE(void *) nlData =3D NULL; =20 *master =3D NULL; =20 if (virNetlinkDumpLink(ifname, -1, &nlData, tb, 0, 0) < 0) - goto cleanup; + return -1; =20 if (tb[IFLA_MASTER]) { if (!(*master =3D virNetDevGetName(*(int *)RTA_DATA(tb[IFLA_MASTER= ])))) - goto cleanup; + return -1; } =20 VIR_DEBUG("IFLA_MASTER for %s is %s", ifname, *master ? *master : "(no= ne)"); - ret =3D 0; - cleanup: - VIR_FREE(nlData); - return ret; + return 0; } =20 =20 @@ -1168,39 +1158,33 @@ virNetDevSysfsDeviceFile(char **pf_sysfs_device_lin= k, const char *ifname, static bool virNetDevIsPCIDevice(const char *devpath) { - char *subsys_link =3D NULL; - char *abs_path =3D NULL; char *subsys =3D NULL; - bool ret =3D false; + VIR_AUTOFREE(char *) subsys_link =3D NULL; + VIR_AUTOFREE(char *) abs_path =3D NULL; =20 if (virAsprintf(&subsys_link, "%s/subsystem", devpath) < 0) return false; =20 if (!virFileExists(subsys_link)) - goto cleanup; + return false; =20 if (virFileResolveLink(subsys_link, &abs_path) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to resolve device subsystem symlink %s"), subsys_link); - goto cleanup; + return false; } =20 subsys =3D last_component(abs_path); - ret =3D STRPREFIX(subsys, "pci"); - - cleanup: - VIR_FREE(subsys_link); - VIR_FREE(abs_path); - return ret; + return STRPREFIX(subsys, "pci"); } =20 static virPCIDevicePtr virNetDevGetPCIDevice(const char *devName) { - char *vfSysfsDevicePath =3D NULL; virPCIDeviceAddressPtr vfPCIAddr =3D NULL; virPCIDevicePtr vfPCIDevice =3D NULL; + VIR_AUTOFREE(char *) vfSysfsDevicePath =3D NULL; =20 if (virNetDevSysfsFile(&vfSysfsDevicePath, devName, "device") < 0) goto cleanup; @@ -1216,7 +1200,6 @@ virNetDevGetPCIDevice(const char *devName) vfPCIAddr->slot, vfPCIAddr->function); =20 cleanup: - VIR_FREE(vfSysfsDevicePath); VIR_FREE(vfPCIAddr); =20 return vfPCIDevice; @@ -1241,25 +1224,20 @@ int virNetDevGetPhysPortID(const char *ifname, char **physPortID) { - int ret =3D -1; - char *physPortIDFile =3D NULL; + VIR_AUTOFREE(char *) physPortIDFile =3D NULL; =20 *physPortID =3D NULL; =20 if (virNetDevSysfsFile(&physPortIDFile, ifname, "phys_port_id") < 0) - goto cleanup; + return -1; =20 /* a failure to read just means the driver doesn't support - * phys_port_id, so set success now and ignore the return from - * virFileReadAllQuiet(). + * phys_port_id, so ignore the return from virFileReadAllQuiet() + * and return success. */ - ret =3D 0; - ignore_value(virFileReadAllQuiet(physPortIDFile, 1024, physPortID)); =20 - cleanup: - VIR_FREE(physPortIDFile); - return ret; + return 0; } =20 =20 @@ -1280,67 +1258,61 @@ virNetDevGetVirtualFunctions(const char *pfname, size_t *n_vfname, unsigned int *max_vfs) { - int ret =3D -1; size_t i; - char *pf_sysfs_device_link =3D NULL; - char *pci_sysfs_device_link =3D NULL; - char *pciConfigAddr =3D NULL; - char *pfPhysPortID =3D NULL; + VIR_AUTOFREE(char *) pf_sysfs_device_link =3D NULL; + VIR_AUTOFREE(char *) pci_sysfs_device_link =3D NULL; + VIR_AUTOFREE(char *) pciConfigAddr =3D NULL; + VIR_AUTOFREE(char *) pfPhysPortID =3D NULL; + VIR_AUTOFREE(char **) tmpVfname =3D NULL; + VIR_AUTOFREE(virPCIDeviceAddressPtr *) tmpVirtFns =3D NULL; =20 *virt_fns =3D NULL; *n_vfname =3D 0; *max_vfs =3D 0; =20 if (virNetDevGetPhysPortID(pfname, &pfPhysPortID) < 0) - goto cleanup; + return -1; =20 if (virNetDevSysfsFile(&pf_sysfs_device_link, pfname, "device") < 0) - goto cleanup; + return -1; =20 - if (virPCIGetVirtualFunctions(pf_sysfs_device_link, virt_fns, - n_vfname, max_vfs) < 0) - goto cleanup; + if (virPCIGetVirtualFunctions(pf_sysfs_device_link, &tmpVirtFns, + n_vfname, max_vfs) < 0) { + return -1; + } =20 - if (VIR_ALLOC_N(*vfname, *n_vfname) < 0) - goto cleanup; + if (VIR_ALLOC_N(tmpVfname, *n_vfname) < 0) + return -1; =20 for (i =3D 0; i < *n_vfname; i++) { - if (virPCIGetAddrString((*virt_fns)[i]->domain, - (*virt_fns)[i]->bus, - (*virt_fns)[i]->slot, - (*virt_fns)[i]->function, + if (virPCIGetAddrString(tmpVirtFns[i]->domain, + tmpVirtFns[i]->bus, + tmpVirtFns[i]->slot, + tmpVirtFns[i]->function, &pciConfigAddr) < 0) { virReportSystemError(ENOSYS, "%s", _("Failed to get PCI Config Address Strin= g")); - goto cleanup; + return -1; } if (virPCIGetSysfsFile(pciConfigAddr, &pci_sysfs_device_link) < 0)= { virReportSystemError(ENOSYS, "%s", _("Failed to get PCI SYSFS file")); - goto cleanup; + return -1; } =20 if (virPCIGetNetName(pci_sysfs_device_link, 0, - pfPhysPortID, &((*vfname)[i])) < 0) { - goto cleanup; + pfPhysPortID, &tmpVfname[i]) < 0) { + return -1; } =20 - if (!(*vfname)[i]) + if (!tmpVfname[i]) VIR_INFO("VF does not have an interface name"); } =20 - ret =3D 0; + VIR_STEAL_PTR(*vfname, tmpVfname); + VIR_STEAL_PTR(*virt_fns, tmpVirtFns); =20 - cleanup: - if (ret < 0) { - VIR_FREE(*vfname); - VIR_FREE(*virt_fns); - } - VIR_FREE(pfPhysPortID); - VIR_FREE(pf_sysfs_device_link); - VIR_FREE(pci_sysfs_device_link); - VIR_FREE(pciConfigAddr); - return ret; + return 0; } =20 /** @@ -1355,17 +1327,12 @@ virNetDevGetVirtualFunctions(const char *pfname, int virNetDevIsVirtualFunction(const char *ifname) { - char *if_sysfs_device_link =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) if_sysfs_device_link =3D NULL; =20 if (virNetDevSysfsFile(&if_sysfs_device_link, ifname, "device") < 0) - return ret; + return -1; =20 - ret =3D virPCIIsVirtualFunction(if_sysfs_device_link); - - VIR_FREE(if_sysfs_device_link); - - return ret; + return virPCIIsVirtualFunction(if_sysfs_device_link); } =20 /** @@ -1383,25 +1350,19 @@ int virNetDevGetVirtualFunctionIndex(const char *pfname, const char *vfname, int *vf_index) { - char *pf_sysfs_device_link =3D NULL, *vf_sysfs_device_link =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) pf_sysfs_device_link =3D NULL; + VIR_AUTOFREE(char *) vf_sysfs_device_link =3D NULL; =20 if (virNetDevSysfsFile(&pf_sysfs_device_link, pfname, "device") < 0) - return ret; + return -1; =20 - if (virNetDevSysfsFile(&vf_sysfs_device_link, vfname, "device") < 0) { - VIR_FREE(pf_sysfs_device_link); - return ret; - } + if (virNetDevSysfsFile(&vf_sysfs_device_link, vfname, "device") < 0) + return -1; =20 - ret =3D virPCIGetVirtualFunctionIndex(pf_sysfs_device_link, + return virPCIGetVirtualFunctionIndex(pf_sysfs_device_link, vf_sysfs_device_link, vf_index); =20 - VIR_FREE(pf_sysfs_device_link); - VIR_FREE(vf_sysfs_device_link); - - return ret; } =20 /** @@ -1417,19 +1378,18 @@ virNetDevGetVirtualFunctionIndex(const char *pfname= , const char *vfname, int virNetDevGetPhysicalFunction(const char *ifname, char **pfname) { - char *physfn_sysfs_path =3D NULL; - char *vfPhysPortID =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) physfn_sysfs_path =3D NULL; + VIR_AUTOFREE(char *) vfPhysPortID =3D NULL; =20 if (virNetDevGetPhysPortID(ifname, &vfPhysPortID) < 0) - goto cleanup; + return -1; =20 if (virNetDevSysfsDeviceFile(&physfn_sysfs_path, ifname, "physfn") < 0) - goto cleanup; + return -1; =20 if (virPCIGetNetName(physfn_sysfs_path, 0, vfPhysPortID, pfname) < 0) { - goto cleanup; + return -1; } =20 if (!*pfname) { @@ -1439,14 +1399,10 @@ virNetDevGetPhysicalFunction(const char *ifname, ch= ar **pfname) virReportError(VIR_ERR_INTERNAL_ERROR, _("The PF device for VF %s has no network device na= me"), ifname); - goto cleanup; + return -1; } =20 - ret =3D 0; - cleanup: - VIR_FREE(vfPhysPortID); - VIR_FREE(physfn_sysfs_path); - return ret; + return 0; } =20 =20 @@ -1470,26 +1426,25 @@ virNetDevGetPhysicalFunction(const char *ifname, ch= ar **pfname) int virNetDevPFGetVF(const char *pfname, int vf, char **vfname) { - char *virtfnName =3D NULL; - char *virtfnSysfsPath =3D NULL; - char *pfPhysPortID =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) virtfnName =3D NULL; + VIR_AUTOFREE(char *) virtfnSysfsPath =3D NULL; + VIR_AUTOFREE(char *) pfPhysPortID =3D NULL; =20 /* a VF may have multiple "ports", each one having its own netdev, * and each netdev having a different phys_port_id. Be sure we get * the VF netdev with a phys_port_id matchine that of pfname */ if (virNetDevGetPhysPortID(pfname, &pfPhysPortID) < 0) - goto cleanup; + return -1; =20 if (virAsprintf(&virtfnName, "virtfn%d", vf) < 0) - goto cleanup; + return -1; =20 /* this provides the path to the VF's directory in sysfs, * e.g. "/sys/class/net/enp2s0f0/virtfn3" */ if (virNetDevSysfsDeviceFile(&virtfnSysfsPath, pfname, virtfnName) < 0) - goto cleanup; + return -1; =20 /* and this gets the netdev name associated with it, which is a * directory entry in [virtfnSysfsPath]/net, @@ -1498,14 +1453,7 @@ virNetDevPFGetVF(const char *pfname, int vf, char **= vfname) * isn't bound to a netdev driver, it won't have a netdev name, * and vfname will be NULL). */ - ret =3D virPCIGetNetName(virtfnSysfsPath, 0, pfPhysPortID, vfname); - - cleanup: - VIR_FREE(virtfnName); - VIR_FREE(virtfnSysfsPath); - VIR_FREE(pfPhysPortID); - - return ret; + return virPCIGetNetName(virtfnSysfsPath, 0, pfPhysPortID, vfname); } =20 =20 @@ -1522,30 +1470,24 @@ int virNetDevGetVirtualFunctionInfo(const char *vfname, char **pfname, int *vf) { - char *pf_sysfs_path =3D NULL, *vf_sysfs_path =3D NULL; - int ret =3D -1; + VIR_AUTOFREE(char *) pf_sysfs_path =3D NULL; + VIR_AUTOFREE(char *) vf_sysfs_path =3D NULL; + VIR_AUTOFREE(char *) tmpPfname =3D NULL; =20 *pfname =3D NULL; =20 - if (virNetDevGetPhysicalFunction(vfname, pfname) < 0) - return ret; + if (virNetDevGetPhysicalFunction(vfname, &tmpPfname) < 0) + return -1; =20 - if (virNetDevSysfsFile(&pf_sysfs_path, *pfname, "device") < 0) - goto cleanup; + if (virNetDevSysfsFile(&pf_sysfs_path, tmpPfname, "device") < 0) + return -1; =20 if (virNetDevSysfsFile(&vf_sysfs_path, vfname, "device") < 0) - goto cleanup; + return -1; =20 - ret =3D virPCIGetVirtualFunctionIndex(pf_sysfs_path, vf_sysfs_path, vf= ); + VIR_STEAL_PTR(*pfname, tmpPfname); =20 - cleanup: - if (ret < 0) - VIR_FREE(*pfname); - - VIR_FREE(vf_sysfs_path); - VIR_FREE(pf_sysfs_path); - - return ret; + return virPCIGetVirtualFunctionIndex(pf_sysfs_path, vf_sysfs_path, vf); } =20 #else /* !__linux__ */ @@ -1657,7 +1599,6 @@ virNetDevSetVfConfig(const char *ifname, int vf, { int rc =3D -1; char macstr[VIR_MAC_STRING_BUFLEN]; - struct nlmsghdr *resp =3D NULL; struct nlmsgerr *err; unsigned int recvbuflen =3D 0; struct nl_msg *nl_msg; @@ -1666,6 +1607,7 @@ virNetDevSetVfConfig(const char *ifname, int vf, .ifi_family =3D AF_UNSPEC, .ifi_index =3D -1, }; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 if (!macaddr && vlanid < 0) return -1; @@ -1769,7 +1711,6 @@ virNetDevSetVfConfig(const char *ifname, int vf, vlanid, rc < 0 ? "Fail" : "Success"); =20 nlmsg_free(nl_msg); - VIR_FREE(resp); return rc; =20 malformed_resp: @@ -1843,19 +1784,15 @@ virNetDevGetVfConfig(const char *ifname, int vf, vi= rMacAddrPtr mac, int *vlanid) { int rc =3D -1; - void *nlData =3D NULL; struct nlattr *tb[IFLA_MAX + 1] =3D {NULL, }; int ifindex =3D -1; + VIR_AUTOFREE(void *) nlData =3D NULL; =20 rc =3D virNetlinkDumpLink(ifname, ifindex, &nlData, tb, 0, 0); if (rc < 0) - goto cleanup; + return rc; =20 - rc =3D virNetDevParseVfConfig(tb, vf, mac, vlanid); - - cleanup: - VIR_FREE(nlData); - return rc; + return virNetDevParseVfConfig(tb, vf, mac, vlanid); } =20 =20 @@ -1914,14 +1851,14 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, { int ret =3D -1; const char *pfDevName =3D NULL; - char *pfDevOrig =3D NULL; - char *vfDevOrig =3D NULL; virMacAddr oldMAC; char MACStr[VIR_MAC_STRING_BUFLEN]; int oldVlanTag =3D -1; - char *filePath =3D NULL; - char *fileStr =3D NULL; virJSONValuePtr configJSON =3D NULL; + VIR_AUTOFREE(char *) pfDevOrig =3D NULL; + VIR_AUTOFREE(char *) vfDevOrig =3D NULL; + VIR_AUTOFREE(char *) filePath =3D NULL; + VIR_AUTOFREE(char *) fileStr =3D NULL; =20 if (vf >=3D 0) { /* linkdev is the PF */ @@ -2030,10 +1967,6 @@ virNetDevSaveNetConfig(const char *linkdev, int vf, =20 ret =3D 0; cleanup: - VIR_FREE(pfDevOrig); - VIR_FREE(vfDevOrig); - VIR_FREE(filePath); - VIR_FREE(fileStr); virJSONValueFree(configJSON); return ret; } @@ -2069,14 +2002,14 @@ virNetDevReadNetConfig(const char *linkdev, int vf, { int ret =3D -1; const char *pfDevName =3D NULL; - char *pfDevOrig =3D NULL; - char *vfDevOrig =3D NULL; - char *filePath =3D NULL; - char *fileStr =3D NULL; virJSONValuePtr configJSON =3D NULL; const char *MACStr =3D NULL; const char *adminMACStr =3D NULL; int vlanTag =3D -1; + VIR_AUTOFREE(char *) pfDevOrig =3D NULL; + VIR_AUTOFREE(char *) vfDevOrig =3D NULL; + VIR_AUTOFREE(char *) filePath =3D NULL; + VIR_AUTOFREE(char *) fileStr =3D NULL; =20 *adminMAC =3D NULL; *vlan =3D NULL; @@ -2245,10 +2178,6 @@ virNetDevReadNetConfig(const char *linkdev, int vf, VIR_FREE(*vlan); } =20 - VIR_FREE(pfDevOrig); - VIR_FREE(vfDevOrig); - VIR_FREE(filePath); - VIR_FREE(fileStr); virJSONValueFree(configJSON); return ret; } @@ -2282,10 +2211,10 @@ virNetDevSetNetConfig(const char *linkdev, int vf, int ret =3D -1; char MACStr[VIR_MAC_STRING_BUFLEN]; const char *pfDevName =3D NULL; - char *pfDevOrig =3D NULL; - char *vfDevOrig =3D NULL; int vlanTag =3D -1; virPCIDevicePtr vfPCIDevice =3D NULL; + VIR_AUTOFREE(char *) pfDevOrig =3D NULL; + VIR_AUTOFREE(char *) vfDevOrig =3D NULL; =20 if (vf >=3D 0) { /* linkdev is the PF */ @@ -2462,8 +2391,6 @@ virNetDevSetNetConfig(const char *linkdev, int vf, =20 ret =3D 0; cleanup: - VIR_FREE(pfDevOrig); - VIR_FREE(vfDevOrig); virPCIDeviceFree(vfPCIDevice); return ret; } @@ -2543,28 +2470,27 @@ int virNetDevGetLinkInfo(const char *ifname, virNetDevIfLinkPtr lnk) { - int ret =3D -1; - char *path =3D NULL; - char *buf =3D NULL; char *tmp; int tmp_state; unsigned int tmp_speed; + VIR_AUTOFREE(char *) path =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; =20 if (virNetDevSysfsFile(&path, ifname, "operstate") < 0) - goto cleanup; + return -1; =20 if (virFileReadAll(path, 1024, &buf) < 0) { virReportSystemError(errno, _("unable to read: %s"), path); - goto cleanup; + return -1; } =20 if (!(tmp =3D strchr(buf, '\n'))) { virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse: %s"), buf); - goto cleanup; + return -1; } =20 *tmp =3D '\0'; @@ -2575,7 +2501,7 @@ virNetDevGetLinkInfo(const char *ifname, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse: %s"), buf); - goto cleanup; + return -1; } =20 lnk->state =3D tmp_state; @@ -2586,26 +2512,24 @@ virNetDevGetLinkInfo(const char *ifname, * speed if that's the case. */ if (lnk->state !=3D VIR_NETDEV_IF_STATE_UP) { lnk->speed =3D 0; - ret =3D 0; - goto cleanup; + return 0; } =20 VIR_FREE(path); VIR_FREE(buf); =20 if (virNetDevSysfsFile(&path, ifname, "speed") < 0) - goto cleanup; + return -1; =20 if (virFileReadAllQuiet(path, 1024, &buf) < 0) { /* Some devices doesn't report speed, in which case we get EINVAL = */ - if (errno =3D=3D EINVAL) { - ret =3D 0; - goto cleanup; - } + if (errno =3D=3D EINVAL) + return 0; + virReportSystemError(errno, _("unable to read: %s"), path); - goto cleanup; + return -1; } =20 if (virStrToLong_ui(buf, &tmp, 10, &tmp_speed) < 0 || @@ -2613,16 +2537,12 @@ virNetDevGetLinkInfo(const char *ifname, virReportError(VIR_ERR_INTERNAL_ERROR, _("Unable to parse: %s"), buf); - goto cleanup; + return -1; } =20 lnk->speed =3D tmp_speed; =20 - ret =3D 0; - cleanup: - VIR_FREE(buf); - VIR_FREE(path); - return ret; + return 0; } =20 #else @@ -2830,10 +2750,10 @@ static int virNetDevGetMcastList(const char *ifname, virNetDevMcastListPtr mcast) { char *cur =3D NULL; - char *buf =3D NULL; char *next =3D NULL; int ret =3D -1, len; virNetDevMcastEntryPtr entry =3D NULL; + VIR_AUTOFREE(char *) buf =3D NULL; =20 mcast->entries =3D NULL; mcast->nentries =3D 0; @@ -2866,7 +2786,6 @@ static int virNetDevGetMcastList(const char *ifname, =20 ret =3D 0; cleanup: - VIR_FREE(buf); VIR_FREE(entry); =20 return ret; @@ -3006,13 +2925,11 @@ static int virNetDevRDMAFeature(const char *ifname, virBitmapPtr *out) { - char *eth_devpath =3D NULL; - char *ib_devpath =3D NULL; - char *eth_res_buf =3D NULL; - char *ib_res_buf =3D NULL; DIR *dirp =3D NULL; struct dirent *dp; int ret =3D -1; + VIR_AUTOFREE(char *) eth_devpath =3D NULL; + VIR_AUTOFREE(char *) eth_res_buf =3D NULL; =20 if (!virFileExists(SYSFS_INFINIBAND_DIR)) return 0; @@ -3028,6 +2945,9 @@ virNetDevRDMAFeature(const char *ifname, goto cleanup; =20 while (virDirRead(dirp, &dp, SYSFS_INFINIBAND_DIR) > 0) { + VIR_AUTOFREE(char *) ib_devpath =3D NULL; + VIR_AUTOFREE(char *) ib_res_buf =3D NULL; + if (virAsprintf(&ib_devpath, SYSFS_INFINIBAND_DIR "%s/device/resou= rce", dp->d_name) < 0) continue; @@ -3036,17 +2956,11 @@ virNetDevRDMAFeature(const char *ifname, ignore_value(virBitmapSetBit(*out, VIR_NET_DEV_FEAT_RDMA)); break; } - VIR_FREE(ib_devpath); - VIR_FREE(ib_res_buf); } ret =3D 0; =20 cleanup: VIR_DIR_CLOSE(dirp); - VIR_FREE(eth_devpath); - VIR_FREE(ib_devpath); - VIR_FREE(eth_res_buf); - VIR_FREE(ib_res_buf); return ret; } =20 @@ -3205,11 +3119,11 @@ static uint32_t virNetDevGetFamilyId(const char *family_name) { struct nl_msg *nl_msg =3D NULL; - struct nlmsghdr *resp =3D NULL; struct genlmsghdr* gmsgh =3D NULL; struct nlattr *tb[CTRL_ATTR_MAX + 1] =3D {NULL, }; unsigned int recvbuflen; uint32_t family_id =3D 0; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; =20 if (!(nl_msg =3D nlmsg_alloc_simple(GENL_ID_CTRL, NLM_F_REQUEST | NLM_F_ACK))) { @@ -3245,7 +3159,6 @@ virNetDevGetFamilyId(const char *family_name) =20 cleanup: nlmsg_free(nl_msg); - VIR_FREE(resp); return family_id; } =20 @@ -3265,16 +3178,16 @@ virNetDevSwitchdevFeature(const char *ifname, virBitmapPtr *out) { struct nl_msg *nl_msg =3D NULL; - struct nlmsghdr *resp =3D NULL; unsigned int recvbuflen; struct nlattr *tb[DEVLINK_ATTR_MAX + 1] =3D {NULL, }; virPCIDevicePtr pci_device_ptr =3D NULL; struct genlmsghdr* gmsgh =3D NULL; const char *pci_name; - char *pfname =3D NULL; int is_vf =3D -1; int ret =3D -1; uint32_t family_id; + VIR_AUTOFREE(struct nlmsghdr *) resp =3D NULL; + VIR_AUTOFREE(char *) pfname =3D NULL; =20 if ((family_id =3D virNetDevGetFamilyId(DEVLINK_GENL_NAME)) <=3D 0) return ret; @@ -3333,8 +3246,6 @@ virNetDevSwitchdevFeature(const char *ifname, cleanup: nlmsg_free(nl_msg); virPCIDeviceFree(pci_device_ptr); - VIR_FREE(resp); - VIR_FREE(pfname); return ret; } # else @@ -3375,7 +3286,7 @@ virNetDevGetEthtoolGFeatures(virBitmapPtr bitmap, int fd, struct ifreq *ifr) { - struct ethtool_gfeatures *g_cmd; + VIR_AUTOFREE(struct ethtool_gfeatures *) g_cmd =3D NULL; =20 if (VIR_ALLOC_VAR(g_cmd, struct ethtool_get_features_block, GFEATURES_SIZE) <= 0) @@ -3385,7 +3296,6 @@ virNetDevGetEthtoolGFeatures(virBitmapPtr bitmap, g_cmd->size =3D GFEATURES_SIZE; if (virNetDevGFeatureAvailable(fd, ifr, g_cmd)) ignore_value(virBitmapSetBit(bitmap, VIR_NET_DEV_FEAT_TXUDPTNL)); - VIR_FREE(g_cmd); return 0; } # else --=20 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list