]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virBitmapFormat: Don't check return value
authorPeter Krempa <pkrempa@redhat.com>
Mon, 17 Feb 2025 12:43:16 +0000 (13:43 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 20 Feb 2025 14:15:40 +0000 (15:15 +0100)
'virBitmapFormat' always returns a string; remove pointless checks.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
13 files changed:
src/ch/ch_driver.c
src/conf/capabilities.c
src/conf/domain_conf.c
src/conf/numa_conf.c
src/conf/virnetworkobj.c
src/hypervisor/domain_cgroup.c
src/libxl/libxl_driver.c
src/libxl/xen_common.c
src/qemu/qemu_command.c
src/qemu/qemu_domain.c
src/qemu/qemu_driver.c
src/util/vircgroup.c
src/vz/vz_sdk.c

index fa6e4edcf68d96a91bd04d1a415ced779c16b473..3bdcf66ebdf020bcc04bc1bfa1a2fc1bb038c54a 100644 (file)
@@ -2083,8 +2083,7 @@ chDomainSetNumaParamsLive(virDomainObj *vm,
         return -1;
 
     /* Ensure the cpuset string is formatted before passing to cgroup */
-    if (!(nodeset_str = virBitmapFormat(nodeset)))
-        return -1;
+    nodeset_str = virBitmapFormat(nodeset);
 
     if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_EMULATOR, 0,
                            false, &cgroup_temp) < 0 ||
index 3d0602e1b6fe6574eae766760192327291ee9fe1..1821e36e610aa3ead7f4f2f5b28f60187f79c939 100644 (file)
@@ -816,8 +816,7 @@ virCapsHostNUMACellCPUFormat(virBuffer *buf,
         if (cpus[j].siblings) {
             g_autofree char *siblings = NULL;
 
-            if (!(siblings = virBitmapFormat(cpus[j].siblings)))
-                return -1;
+            siblings = virBitmapFormat(cpus[j].siblings);
 
             virBufferAsprintf(&childBuf,
                               " socket_id='%d' die_id='%d' cluster_id='%d' core_id='%d' siblings='%s'",
@@ -954,9 +953,6 @@ virCapabilitiesFormatCaches(virBuffer *buf,
         const char *unit = NULL;
         unsigned long long short_size = virFormatIntPretty(bank->size, &unit);
 
-        if (!cpus_str)
-            return -1;
-
         /*
          * Let's just *hope* the size is aligned to KiBs so that it does not
          * bite is back in the future
@@ -1038,9 +1034,6 @@ virCapabilitiesFormatMemoryBandwidth(virBuffer *buf,
         virResctrlInfoMemBWPerNode *control = &node->control;
         g_autofree char *cpus_str = virBitmapFormat(node->cpus);
 
-        if (!cpus_str)
-            return -1;
-
         virBufferAsprintf(&attrBuf,
                           " id='%u' cpus='%s'",
                           node->id, cpus_str);
index c79831fe0b96b5fbed452c5a0a644611b075daf0..7db4368b2a88e06a36b5b8c8a1f5a8bf7fb270c4 100644 (file)
@@ -18223,8 +18223,6 @@ virDomainResctrlNew(xmlNodePtr node,
     /* We need to format it back because we need to be consistent in the naming
      * even when users specify some "sub-optimal" string there. */
     vcpus_str = virBitmapFormat(vcpus);
-    if (!vcpus_str)
-        return NULL;
 
     if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE))
         alloc_id = virXMLPropString(node, "id");
@@ -25881,8 +25879,7 @@ virDomainMemorySourceDefFormat(virBuffer *buf,
     switch (def->model) {
     case VIR_DOMAIN_MEMORY_MODEL_DIMM:
         if (def->source.dimm.nodes) {
-            if (!(bitmap = virBitmapFormat(def->source.dimm.nodes)))
-                return -1;
+            bitmap = virBitmapFormat(def->source.dimm.nodes);
 
             virBufferAsprintf(&childBuf, "<nodemask>%s</nodemask>\n", bitmap);
         }
@@ -25893,8 +25890,7 @@ virDomainMemorySourceDefFormat(virBuffer *buf,
         break;
     case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM:
         if (def->source.virtio_mem.nodes) {
-            if (!(bitmap = virBitmapFormat(def->source.virtio_mem.nodes)))
-                return -1;
+            bitmap = virBitmapFormat(def->source.virtio_mem.nodes);
 
             virBufferAsprintf(&childBuf, "<nodemask>%s</nodemask>\n", bitmap);
         }
@@ -25921,8 +25917,7 @@ virDomainMemorySourceDefFormat(virBuffer *buf,
 
     case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC:
         if (def->source.sgx_epc.nodes) {
-            if (!(bitmap = virBitmapFormat(def->source.sgx_epc.nodes)))
-                return -1;
+            bitmap = virBitmapFormat(def->source.sgx_epc.nodes);
 
             virBufferAsprintf(&childBuf, "<nodemask>%s</nodemask>\n", bitmap);
         }
@@ -26992,9 +26987,8 @@ virDomainHugepagesFormatBuf(virBuffer *buf,
                       hugepage->size);
 
     if (hugepage->nodemask) {
-        g_autofree char *nodeset = NULL;
-        if (!(nodeset = virBitmapFormat(hugepage->nodemask)))
-            return -1;
+        g_autofree char *nodeset = virBitmapFormat(hugepage->nodemask);
+
         virBufferAsprintf(buf, " nodeset='%s'", nodeset);
     }
 
@@ -27321,8 +27315,6 @@ virDomainResctrlMonDefFormatHelper(virDomainResctrlMonDef *domresmon,
     }
 
     vcpus = virBitmapFormat(domresmon->vcpus);
-    if (!vcpus)
-        return -1;
 
     virBufferAsprintf(buf, "vcpus='%s'/>\n", vcpus);
 
@@ -27356,8 +27348,6 @@ virDomainCachetuneDefFormat(virBuffer *buf,
         return 0;
 
     vcpus = virBitmapFormat(resctrl->vcpus);
-    if (!vcpus)
-        return -1;
 
     virBufferAsprintf(&attrBuf, " vcpus='%s'", vcpus);
 
@@ -27415,8 +27405,6 @@ virDomainMemorytuneDefFormat(virBuffer *buf,
         return 0;
 
     vcpus = virBitmapFormat(resctrl->vcpus);
-    if (!vcpus)
-        return -1;
 
     virBufferAsprintf(&attrBuf, " vcpus='%s'", vcpus);
 
@@ -27545,15 +27533,14 @@ virDomainCpuDefFormat(virBuffer *buf,
 {
     virDomainVcpuDef *vcpu;
     size_t i;
-    g_autofree char *cpumask = NULL;
 
     virBufferAddLit(buf, "<vcpu");
     virBufferAsprintf(buf, " placement='%s'",
                       virDomainCpuPlacementModeTypeToString(def->placement_mode));
 
     if (def->cpumask && !virBitmapIsAllSet(def->cpumask)) {
-        if ((cpumask = virBitmapFormat(def->cpumask)) == NULL)
-            return -1;
+        g_autofree char *cpumask = virBitmapFormat(def->cpumask);
+
         virBufferAsprintf(buf, " cpuset='%s'", cpumask);
     }
     if (virDomainDefHasVcpusOffline(def))
index 0a0e2911f7cc7e6e3314502c446d5f7da83185ce..00f0c605ee3b77104854206fd94bc68f4b17631d 100644 (file)
@@ -273,7 +273,6 @@ virDomainNumatuneFormatXML(virBuffer *buf,
                            virDomainNuma *numatune)
 {
     const char *tmp = NULL;
-    char *nodeset = NULL;
     bool nodesetSpecified = false;
     size_t i = 0;
 
@@ -298,10 +297,9 @@ virDomainNumatuneFormatXML(virBuffer *buf,
         virBufferAsprintf(buf, "<memory mode='%s' ", tmp);
 
         if (numatune->memory.placement == VIR_DOMAIN_NUMATUNE_PLACEMENT_STATIC) {
-            if (!(nodeset = virBitmapFormat(numatune->memory.nodeset)))
-                return -1;
+            g_autofree char *nodeset = virBitmapFormat(numatune->memory.nodeset);
+
             virBufferAsprintf(buf, "nodeset='%s'/>\n", nodeset);
-            VIR_FREE(nodeset);
         } else if (numatune->memory.placement) {
             tmp = virDomainNumatunePlacementTypeToString(numatune->memory.placement);
             virBufferAsprintf(buf, "placement='%s'/>\n", tmp);
@@ -310,19 +308,18 @@ virDomainNumatuneFormatXML(virBuffer *buf,
 
     for (i = 0; i < numatune->nmem_nodes; i++) {
         virDomainNumaNode *mem_node = &numatune->mem_nodes[i];
+        g_autofree char *nodeset = NULL;
 
         if (!mem_node->nodeset)
             continue;
 
-        if (!(nodeset = virBitmapFormat(mem_node->nodeset)))
-            return -1;
+        nodeset = virBitmapFormat(mem_node->nodeset);
 
         virBufferAsprintf(buf,
                           "<memnode cellid='%zu' mode='%s' nodeset='%s'/>\n",
                           i,
                           virDomainNumatuneMemModeTypeToString(mem_node->mode),
                           nodeset);
-        VIR_FREE(nodeset);
     }
 
     virBufferAdjustIndent(buf, -2);
@@ -461,9 +458,8 @@ virDomainNumatuneMaybeFormatNodeset(virDomainNuma *numatune,
                                          cellid) < 0)
         return -1;
 
-    if (nodeset &&
-        !(*mask = virBitmapFormat(nodeset)))
-        return -1;
+    if (nodeset)
+        *mask = virBitmapFormat(nodeset);
 
     return 0;
 }
@@ -1010,8 +1006,6 @@ virDomainNumaDefFormatXML(virBuffer *buf,
         if (cpumask) {
             g_autofree char *cpustr = virBitmapFormat(cpumask);
 
-            if (!cpustr)
-                return -1;
             virBufferAsprintf(&attrBuf, " cpus='%s'", cpustr);
         }
         virBufferAsprintf(&attrBuf, " memory='%llu'",
index 5abc295506e08c8ce91dc9806f93bfbd7750a2d5..4405645d6dc33093d33e4f41db04bfe91163d047 100644 (file)
@@ -799,9 +799,6 @@ virNetworkObjFormat(virNetworkObj *obj,
     char *classIdStr = virBitmapFormat(obj->classIdMap);
     size_t i;
 
-    if (!classIdStr)
-        return NULL;
-
     virBufferAddLit(&buf, "<networkstatus>\n");
     virBufferAdjustIndent(&buf, 2);
     virBufferAsprintf(&buf, "<class_id bitmap='%s'/>\n", classIdStr);
index 2b9a1cc9b17df314d84c17334eda07d4aacf829f..fda495faf5fddd2a662a4253ec8aad6d81dfd364 100644 (file)
@@ -410,8 +410,7 @@ virDomainCgroupRestoreCgroupState(virDomainObj *vm,
     if (!(all_nodes = virNumaGetHostMemoryNodeset()))
         goto error;
 
-    if (!(mem_mask = virBitmapFormat(all_nodes)))
-        goto error;
+    mem_mask = virBitmapFormat(all_nodes);
 
     if (virCgroupHasEmptyTasks(cgroup, VIR_CGROUP_CONTROLLER_CPUSET) <= 0)
         goto error;
@@ -648,8 +647,7 @@ virDomainCgroupEmulatorAllNodesAllow(virCgroup *cgroup,
     if (!(all_nodes = virNumaGetHostMemoryNodeset()))
         goto cleanup;
 
-    if (!(all_nodes_str = virBitmapFormat(all_nodes)))
-        goto cleanup;
+    all_nodes_str = virBitmapFormat(all_nodes);
 
     data = g_new0(virCgroupEmulatorAllNodesData, 1);
 
index edf7b3758175afca16c3c010ccf89b256cddc82f..512b456bfeeabdb7df0b9578efde1e3c8cb9b384 100644 (file)
@@ -5051,8 +5051,7 @@ libxlDomainGetNumaParameters(virDomainPtr dom,
                 }
             }
 
-            if (!(nodeset = virBitmapFormat(nodes)))
-                goto cleanup;
+            nodeset = virBitmapFormat(nodes);
 
             if (virTypedParameterAssign(param, VIR_DOMAIN_NUMA_NODESET,
                                         VIR_TYPED_PARAM_STRING, nodeset) < 0)
index 3a64f565f74995633b48bcec501bbb1ce2fcfd8c..b7ec552631e7726ef8b8f07a90ddcd13860b474a 100644 (file)
@@ -2030,10 +2030,8 @@ xenFormatCPUAllocation(virConf *conf, virDomainDef *def)
     if (xenConfigSetInt(conf, "vcpus", virDomainDefGetVcpus(def)) < 0)
         return -1;
 
-    if ((def->cpumask != NULL) &&
-        ((cpus = virBitmapFormat(def->cpumask)) == NULL)) {
-        return -1;
-    }
+    if (def->cpumask != NULL)
+        cpus = virBitmapFormat(def->cpumask);
 
     if (cpus &&
         xenConfigSetString(conf, "cpus", cpus) < 0)
index 54130ac4f0997af0d039c27184f0b9efd19f7e87..d898e548e1874b9cecc4090d9b78acb5e895363f 100644 (file)
@@ -7498,8 +7498,7 @@ qemuBuildNumaCPUs(virBuffer *buf,
     if (!cpu)
         return 0;
 
-    if (!(cpumask = virBitmapFormat(cpu)))
-        return -1;
+    cpumask = virBitmapFormat(cpu);
 
     for (tmpmask = cpumask; tmpmask; tmpmask = next) {
         if ((next = strchr(tmpmask, ',')))
index df1ed0223d3e4659813e3eefec711aa86f48df17..a9bcd621233440a2a6c8426b7fbdcf8e7de051c9 100644 (file)
@@ -2306,13 +2306,11 @@ qemuDomainObjPrivateXMLFormatAutomaticPlacement(virBuffer *buf,
     if (!priv->autoNodeset && !priv->autoCpuset)
         return 0;
 
-    if (priv->autoNodeset &&
-        !((nodeset = virBitmapFormat(priv->autoNodeset))))
-        return -1;
+    if (priv->autoNodeset)
+        nodeset = virBitmapFormat(priv->autoNodeset);
 
-    if (priv->autoCpuset &&
-        !((cpuset = virBitmapFormat(priv->autoCpuset))))
-        return -1;
+    if (priv->autoCpuset)
+        cpuset = virBitmapFormat(priv->autoCpuset);
 
     virBufferAddLit(buf, "<numad");
     virBufferEscapeString(buf, " nodeset='%s'", nodeset);
index 174dad64b0614db2d062f411ce1d349cd832d7da..d486169bc8c1bec6a8bd8685bc94c055b93d9114 100644 (file)
@@ -4300,9 +4300,7 @@ qemuDomainPinVcpuLive(virDomainObj *vm,
     }
 
     tmpmap = virBitmapNewCopy(cpumap);
-
-    if (!(str = virBitmapFormat(cpumap)))
-        goto cleanup;
+    str = virBitmapFormat(cpumap);
 
     if (vcpuinfo->online) {
         /* Configure the corresponding cpuset cgroup before set affinity. */
@@ -8233,9 +8231,7 @@ qemuDomainSetNumaParamsLive(virDomainObj *vm,
     if (!virNumaNodesetIsAvailable(nodeset))
         return -1;
 
-    /* Ensure the cpuset string is formatted before passing to cgroup */
-    if (!(nodeset_str = virBitmapFormat(nodeset)))
-        return -1;
+    nodeset_str = virBitmapFormat(nodeset);
 
     if (virCgroupNewThread(priv->cgroup, VIR_CGROUP_THREAD_EMULATOR, 0,
                            false, &cgroup_thread) < 0 ||
@@ -16682,9 +16678,7 @@ qemuDomainGetResctrlMonData(virQEMUDriver *driver,
              * res.vcpus is assigned with an memory space holding it,
              * let this newly allocated memory buffer to be freed along with
              * the free of 'res' */
-            if (!(res->vcpus = virBitmapFormat(domresmon->vcpus)))
-                goto error;
-
+            res->vcpus = virBitmapFormat(domresmon->vcpus);
             res->name = g_strdup(virResctrlMonitorGetID(monitor));
 
             if (virResctrlMonitorGetStats(monitor, (const char **)features,
@@ -18451,9 +18445,7 @@ qemuDomainGetGuestVcpusParams(virTypedParameterPtr *params,
 
 #define ADD_BITMAP(name) \
     do { \
-        g_autofree char *tmp = NULL; \
-        if (!(tmp = virBitmapFormat(name))) \
-            goto cleanup; \
+        g_autofree char *tmp = virBitmapFormat(name); \
         if (virTypedParamsAddString(&par, &npar, &maxpar, #name, tmp) < 0) \
             goto cleanup; \
     } while (0)
@@ -18583,10 +18575,9 @@ qemuDomainSetGuestVcpus(virDomainPtr dom,
     }
 
     if (!virBitmapIsAllClear(map)) {
-        char *tmp = virBitmapFormat(map);
+        g_autofree char *tmp = virBitmapFormat(map);
         virReportError(VIR_ERR_INVALID_ARG,
-                       _("guest is missing vCPUs '%1$s'"), NULLSTR(tmp));
-        VIR_FREE(tmp);
+                       _("guest is missing vCPUs '%1$s'"), tmp);
         goto endjob;
     }
 
index b424e1b5d4d1ecd95b3855cd50e61f4275e755c3..1daa95e178a098af1cf2cb7e09ff9c7a94ddf821 100644 (file)
@@ -3946,10 +3946,7 @@ virCgroupSetupBlkioDeviceWriteBps(virCgroup *cgroup, const char *path,
 int
 virCgroupSetupCpusetCpus(virCgroup *cgroup, virBitmap *cpumask)
 {
-    g_autofree char *new_cpus = NULL;
-
-    if (!(new_cpus = virBitmapFormat(cpumask)))
-        return -1;
+    g_autofree char *new_cpus = virBitmapFormat(cpumask);
 
     if (virCgroupSetCpusetCpus(cgroup, new_cpus) < 0)
         return -1;
index b20d454fb885db423a44412786d6af4944f986f0..b5a78d3668e5caa872475fa3de5f3a1a405eb364 100644 (file)
@@ -3903,8 +3903,7 @@ prlsdkDoApplyConfig(struct _vzDriver *driver,
     pret = PrlVmCfg_SetCpuCount(sdkdom, virDomainDefGetVcpus(def));
     prlsdkCheckRetGoto(pret, error);
 
-    if (!(mask = virBitmapFormat(def->cpumask)))
-        goto error;
+    mask = virBitmapFormat(def->cpumask);
 
     pret = PrlVmCfg_SetCpuMask(sdkdom, mask);
     prlsdkCheckRetGoto(pret, error);