]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: netdev: use g_new0
authorJán Tomko <jtomko@redhat.com>
Mon, 5 Oct 2020 17:08:12 +0000 (19:08 +0200)
committerJán Tomko <jtomko@redhat.com>
Tue, 6 Oct 2020 10:31:34 +0000 (12:31 +0200)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
src/util/virnetdev.c
src/util/virnetdevbandwidth.c
src/util/virnetdevip.c
src/util/virnetdevmacvlan.c
src/util/virnetdevtap.c
src/util/virnetdevvlan.c
src/util/virnetdevvportprofile.c

index 76aeeba22a42cbe14d42ceae9f99e4a85f82d297..e711a6dc8a7463ab5b66ae73f17f62050059f69e 100644 (file)
@@ -1209,8 +1209,7 @@ virNetDevGetVirtualFunctions(const char *pfname,
                                   n_vfname, max_vfs) < 0)
         goto cleanup;
 
-    if (VIR_ALLOC_N(*vfname, *n_vfname) < 0)
-        goto cleanup;
+    *vfname = g_new0(char *, *n_vfname);
 
     for (i = 0; i < *n_vfname; i++) {
         g_autofree char *pciConfigAddr = NULL;
@@ -2039,8 +2038,7 @@ virNetDevReadNetConfig(const char *linkdev, int vf,
     }
 
     if (MACStr) {
-        if (VIR_ALLOC(*MAC) < 0)
-            goto cleanup;
+        *MAC = g_new0(virMacAddr, 1);
 
         if (virMacAddrParse(MACStr, *MAC) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -2051,8 +2049,7 @@ virNetDevReadNetConfig(const char *linkdev, int vf,
     }
 
     if (adminMACStr) {
-        if (VIR_ALLOC(*adminMAC) < 0)
-            goto cleanup;
+        *adminMAC = g_new0(virMacAddr, 1);
 
         if (virMacAddrParse(adminMACStr, *adminMAC) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
@@ -2064,10 +2061,8 @@ virNetDevReadNetConfig(const char *linkdev, int vf,
 
     if (vlanTag != -1) {
         /* construct a simple virNetDevVlan object with a single tag */
-        if (VIR_ALLOC(*vlan) < 0)
-            goto cleanup;
-        if (VIR_ALLOC((*vlan)->tag) < 0)
-            goto cleanup;
+        *vlan = g_new0(virNetDevVlan, 1);
+        (*vlan)->tag = g_new0(unsigned int, 1);
         (*vlan)->nTags = 1;
         (*vlan)->tag[0] = vlanTag;
     }
@@ -2664,8 +2659,8 @@ static int virNetDevGetMcastList(const char *ifname,
 
     cur = buf;
     while (cur) {
-        if (!entry && VIR_ALLOC(entry) < 0)
-                return -1;
+        if (!entry)
+            entry = g_new0(virNetDevMcastEntry, 1);
 
         next = strchr(cur, '\n');
         if (next)
@@ -2709,8 +2704,7 @@ static int virNetDevGetMulticastTable(const char *ifname,
         goto cleanup;
 
     if (mcast.nentries > 0) {
-        if (VIR_ALLOC_N(filter->multicast.table, mcast.nentries) < 0)
-            goto cleanup;
+        filter->multicast.table = g_new0(virMacAddr, mcast.nentries);
 
         for (i = 0; i < mcast.nentries; i++) {
             virMacAddrSet(&filter->multicast.table[i],
@@ -2733,8 +2727,7 @@ virNetDevRxFilterNew(void)
 {
     virNetDevRxFilterPtr filter;
 
-    if (VIR_ALLOC(filter) < 0)
-        return NULL;
+    filter = g_new0(virNetDevRxFilter, 1);
     return filter;
 }
 
index 5fd7186760492be2f5387de522ede7e89497843f..c8eb5cfc7978883cf771aba3103efcab0c8b7bce 100644 (file)
@@ -442,39 +442,25 @@ int
 virNetDevBandwidthCopy(virNetDevBandwidthPtr *dest,
                        const virNetDevBandwidth *src)
 {
-    int ret = -1;
-
     *dest = NULL;
     if (!src) {
         /* nothing to be copied */
         return 0;
     }
 
-    if (VIR_ALLOC(*dest) < 0)
-        goto cleanup;
+    *dest = g_new0(virNetDevBandwidth, 1);
 
     if (src->in) {
-        if (VIR_ALLOC((*dest)->in) < 0)
-            goto cleanup;
+        (*dest)->in = g_new0(virNetDevBandwidthRate, 1);
         memcpy((*dest)->in, src->in, sizeof(*src->in));
     }
 
     if (src->out) {
-        if (VIR_ALLOC((*dest)->out) < 0) {
-            VIR_FREE((*dest)->in);
-            goto cleanup;
-        }
+        (*dest)->out = g_new0(virNetDevBandwidthRate, 1);
         memcpy((*dest)->out, src->out, sizeof(*src->out));
     }
 
-    ret = 0;
-
- cleanup:
-    if (ret < 0) {
-        virNetDevBandwidthFree(*dest);
-        *dest = NULL;
-    }
-    return ret;
+    return 0;
 }
 
 bool
index a69567da6f94da66014c571fcdb0cd2a132f4658..fc7808cbaa7fba41a6187b3bdc896779823787c4 100644 (file)
@@ -180,8 +180,7 @@ virNetDevIPAddrAdd(const char *ifname,
     if (VIR_SOCKET_ADDR_FAMILY(addr) == AF_INET &&
         !(peer && VIR_SOCKET_ADDR_VALID(peer))) {
         /* compute a broadcast address if this is IPv4 */
-        if (VIR_ALLOC(broadcast) < 0)
-            return -1;
+        broadcast = g_new0(virSocketAddr, 1);
 
         if (virSocketAddrBroadcastByPrefix(addr, prefix, broadcast) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
index f301a9e96ce681bf282265d26349a544c6ad5f84..72f0d67086aeb87225e9decb0d6e5da989dafb73 100644 (file)
@@ -726,11 +726,9 @@ virNetDevMacVLanVPortProfileRegisterCallback(const char *ifname,
     virNetlinkCallbackDataPtr calld = NULL;
 
     if (virtPortProfile && virNetlinkEventServiceIsRunning(NETLINK_ROUTE)) {
-        if (VIR_ALLOC(calld) < 0)
-            goto error;
+        calld = g_new0(struct virNetlinkCallbackData, 1);
         calld->cr_ifname = g_strdup(ifname);
-        if (VIR_ALLOC(calld->virtPortProfile) < 0)
-            goto error;
+        calld->virtPortProfile = g_new0(virNetDevVPortProfile, 1);
         memcpy(calld->virtPortProfile, virtPortProfile, sizeof(*virtPortProfile));
         virMacAddrSet(&calld->macaddress, macaddress);
         calld->linkdev = g_strdup(linkdev);
index 1738f48a5f71cb06054ef60770e22494cf5605b4..198607b5bb4a82c906d3b067745dea95fdd6e6a6 100644 (file)
@@ -165,8 +165,7 @@ virNetDevTapGetRealDeviceName(char *ifname G_GNUC_UNUSED)
         return NULL;
     }
 
-    if (VIR_ALLOC_N(ret, len) < 0)
-        return NULL;
+    ret = g_new0(char, len);
 
     if (sysctl(name, 6, ret, &len, 0, 0) < 0) {
         virReportSystemError(errno,
index 2076cc48dc3072e01e6b7c3118df38df6b45f022..154d92497c42dcc9e20ba6dad25907a34bd0e3a0 100644 (file)
@@ -83,9 +83,7 @@ virNetDevVlanCopy(virNetDevVlanPtr dst, const virNetDevVlan *src)
     if (!src || src->nTags == 0)
         return 0;
 
-    if (VIR_ALLOC_N(dst->tag, src->nTags) < 0)
-        return -1;
-
+    dst->tag = g_new0(unsigned int, src->nTags);
     dst->trunk = src->trunk;
     dst->nTags = src->nTags;
     dst->nativeMode = src->nativeMode;
index 5dae8aa57d0cf5a76cbc0fdb90861ebb0a3b35d3..5d6c055b32c58d7176659e762a725dee2fc40138 100644 (file)
@@ -129,9 +129,7 @@ int virNetDevVPortProfileCopy(virNetDevVPortProfilePtr *dst, const virNetDevVPor
         return 0;
     }
 
-    if (VIR_ALLOC(*dst) < 0)
-        return -1;
-
+    *dst = g_new0(virNetDevVPortProfile, 1);
     memcpy(*dst, src, sizeof(*src));
     return 0;
 }
@@ -431,8 +429,7 @@ int virNetDevVPortProfileMerge3(virNetDevVPortProfilePtr *result,
     }
 
     /* at least one of the source profiles is non-empty */
-    if (VIR_ALLOC(*result) < 0)
-        return ret;
+    *result = g_new0(virNetDevVPortProfile, 1);
 
     /* start with the interface's profile. There are no pointers in a
      * virtualPortProfile, so a shallow copy is sufficient.