]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: capabilities: use g_new0
authorJán Tomko <jtomko@redhat.com>
Wed, 7 Oct 2020 19:12:01 +0000 (21:12 +0200)
committerJán Tomko <jtomko@redhat.com>
Thu, 8 Oct 2020 09:09:26 +0000 (11:09 +0200)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Neal Gompa <ngompa13@gmail.com>
Reviewed-by: Erik Skultety <eskultet@redhat.com>
src/conf/capabilities.c

index 0ba7323ee835d5169d5b572cc4ae11ad695f5e8d..90ad4e0c13e2218a7ee5b7400b77a9470130fe05 100644 (file)
@@ -382,14 +382,10 @@ virCapabilitiesAllocMachines(const char *const *names, int nnames)
     virCapsGuestMachinePtr *machines;
     size_t i;
 
-    if (VIR_ALLOC_N(machines, nnames) < 0)
-        return NULL;
+    machines = g_new0(virCapsGuestMachinePtr, nnames);
 
     for (i = 0; i < nnames; i++) {
-        if (VIR_ALLOC(machines[i]) < 0) {
-            virCapabilitiesFreeMachines(machines, nnames);
-            return NULL;
-        }
+        machines[i] = g_new0(virCapsGuestMachine, 1);
         machines[i]->name = g_strdup(names[i]);
     }
 
@@ -442,8 +438,7 @@ virCapabilitiesAddGuest(virCapsPtr caps,
 {
     virCapsGuestPtr guest;
 
-    if (VIR_ALLOC(guest) < 0)
-        goto error;
+    guest = g_new0(virCapsGuest, 1);
 
     guest->ostype = ostype;
     guest->arch.id = arch;
@@ -492,8 +487,7 @@ virCapabilitiesAddGuestDomain(virCapsGuestPtr guest,
 {
     virCapsGuestDomainPtr dom;
 
-    if (VIR_ALLOC(dom) < 0)
-        goto error;
+    dom = g_new0(virCapsGuestDomain, 1);
 
     dom->type = hvtype;
     dom->info.emulator = g_strdup(emulator);
@@ -728,8 +722,7 @@ virCapabilitiesDomainDataLookupInternal(virCapsPtr caps,
         return ret;
     }
 
-    if (VIR_ALLOC(ret) < 0)
-        return ret;
+    ret = g_new0(virCapsDomainData, 1);
 
     ret->ostype = foundguest->ostype;
     ret->arch = foundguest->arch.id;
@@ -806,8 +799,7 @@ virCapabilitiesAddStoragePool(virCapsPtr caps,
 {
     virCapsStoragePoolPtr pool;
 
-    if (VIR_ALLOC(pool) < 0)
-        goto error;
+    pool = g_new0(virCapsStoragePool, 1);
 
     pool->type = poolType;
 
@@ -1493,8 +1485,7 @@ virCapabilitiesGetNUMASiblingInfo(int node,
         return 0;
     }
 
-    if (VIR_ALLOC_N(tmp, ndistances) < 0)
-        goto cleanup;
+    tmp = g_new0(virCapsHostNUMACellSiblingInfo, ndistances);
 
     for (i = 0; i < ndistances; i++) {
         if (!distances[i])
@@ -1532,8 +1523,7 @@ virCapabilitiesGetNUMAPagesInfo(int node,
     if (virNumaGetPages(node, &pages_size, &pages_avail, NULL, &npages) < 0)
         goto cleanup;
 
-    if (VIR_ALLOC_N(*pageinfo, npages) < 0)
-        goto cleanup;
+    *pageinfo = g_new0(virCapsHostNUMACellPageInfo, npages);
     *npageinfo = npages;
 
     for (i = 0; i < npages; i++) {
@@ -1572,8 +1562,7 @@ virCapabilitiesHostNUMAInitFake(virCapsHostNUMAPtr caps)
         int nodecpus = nodeinfo.sockets * nodeinfo.cores * nodeinfo.threads;
         cid = 0;
 
-        if (VIR_ALLOC_N(cpus, nodecpus) < 0)
-            return -1;
+        cpus = g_new0(virCapsHostNUMACellCPU, nodecpus);
 
         for (s = 0; s < nodeinfo.sockets; s++) {
             for (c = 0; c < nodeinfo.cores; c++) {
@@ -1644,8 +1633,7 @@ virCapabilitiesHostNUMAInitReal(virCapsHostNUMAPtr caps)
             goto cleanup;
         }
 
-        if (VIR_ALLOC_N(cpus, ncpus) < 0)
-            goto cleanup;
+        cpus = g_new0(virCapsHostNUMACellCPU, ncpus);
         cpu = 0;
 
         for (i = 0; i < virBitmapSize(cpumap); i++) {
@@ -1816,8 +1804,7 @@ virCapabilitiesInitResctrlMemory(virCapsPtr caps)
 
     for (i = 0; i < caps->host.cache.nbanks; i++) {
         virCapsHostCacheBankPtr bank = caps->host.cache.banks[i];
-        if (VIR_ALLOC(node) < 0)
-            goto cleanup;
+        node = g_new0(virCapsHostMemBWNode, 1);
 
         if (virResctrlInfoGetMemoryBandwidth(caps->host.resctrl,
                                              bank->level, &node->control) > 0) {
@@ -1901,9 +1888,7 @@ virCapabilitiesInitCaches(virCapsPtr caps)
             if (level < cache_min_level)
                 continue;
 
-            if (VIR_ALLOC(bank) < 0)
-                goto cleanup;
-
+            bank = g_new0(virCapsHostCacheBank, 1);
             bank->level = level;
 
             if (virFileReadValueUint(&bank->id,