'virBitmapFormat' always returns a string; remove pointless checks. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- src/ch/ch_driver.c | 3 +-- src/conf/capabilities.c | 9 +-------- src/conf/domain_conf.c | 27 +++++++-------------------- src/conf/numa_conf.c | 18 ++++++------------ src/conf/virnetworkobj.c | 3 --- src/hypervisor/domain_cgroup.c | 6 ++---- src/libxl/libxl_driver.c | 3 +-- src/libxl/xen_common.c | 6 ++---- src/qemu/qemu_command.c | 3 +-- src/qemu/qemu_domain.c | 10 ++++------ src/qemu/qemu_driver.c | 21 ++++++--------------- src/util/vircgroup.c | 5 +---- src/vz/vz_sdk.c | 3 +-- 13 files changed, 33 insertions(+), 84 deletions(-) diff --git a/src/ch/ch_driver.c b/src/ch/ch_driver.c index fa6e4edcf6..3bdcf66ebd 100644 --- a/src/ch/ch_driver.c +++ b/src/ch/ch_driver.c @@ -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 || diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c index 3d0602e1b6..1821e36e61 100644 --- a/src/conf/capabilities.c +++ b/src/conf/capabilities.c @@ -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); diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index c79831fe0b..7db4368b2a 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -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)) diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c index 0a0e2911f7..6bc54f9405 100644 --- a/src/conf/numa_conf.c +++ b/src/conf/numa_conf.c @@ -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; + 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'", diff --git a/src/conf/virnetworkobj.c b/src/conf/virnetworkobj.c index 5abc295506..4405645d6d 100644 --- a/src/conf/virnetworkobj.c +++ b/src/conf/virnetworkobj.c @@ -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); diff --git a/src/hypervisor/domain_cgroup.c b/src/hypervisor/domain_cgroup.c index 2b9a1cc9b1..fda495faf5 100644 --- a/src/hypervisor/domain_cgroup.c +++ b/src/hypervisor/domain_cgroup.c @@ -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); diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index edf7b37581..512b456bfe 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -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) diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c index 3a64f565f7..b7ec552631 100644 --- a/src/libxl/xen_common.c +++ b/src/libxl/xen_common.c @@ -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) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 54130ac4f0..d898e548e1 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -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, ','))) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index df1ed0223d..a9bcd62123 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -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); diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 174dad64b0..d486169bc8 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -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; } diff --git a/src/util/vircgroup.c b/src/util/vircgroup.c index b424e1b5d4..1daa95e178 100644 --- a/src/util/vircgroup.c +++ b/src/util/vircgroup.c @@ -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; diff --git a/src/vz/vz_sdk.c b/src/vz/vz_sdk.c index b20d454fb8..b5a78d3668 100644 --- a/src/vz/vz_sdk.c +++ b/src/vz/vz_sdk.c @@ -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); -- 2.48.1