From nobody Tue Dec 16 11:46:00 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) client-ip=8.43.85.245; envelope-from=devel-bounces@lists.libvirt.org; helo=lists.libvirt.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.libvirt.org designates 8.43.85.245 as permitted sender) smtp.mailfrom=devel-bounces@lists.libvirt.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.libvirt.org (lists.libvirt.org [8.43.85.245]) by mx.zohomail.com with SMTPS id 1740042425770641.349861783821; Thu, 20 Feb 2025 01:07:05 -0800 (PST) Received: by lists.libvirt.org (Postfix, from userid 996) id 9D3CD1E3D; Thu, 20 Feb 2025 04:07:04 -0500 (EST) Received: from lists.libvirt.org (localhost [IPv6:::1]) by lists.libvirt.org (Postfix) with ESMTP id 5A8291E03; Thu, 20 Feb 2025 04:02:24 -0500 (EST) Received: by lists.libvirt.org (Postfix, from userid 996) id 55DB71CF6; Thu, 20 Feb 2025 04:02:14 -0500 (EST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.libvirt.org (Postfix) with ESMTPS id 1101C1E83 for ; Thu, 20 Feb 2025 04:01:57 -0500 (EST) Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-622-RX__9jzYN8KCpJ5wDpkBlw-1; Thu, 20 Feb 2025 04:01:54 -0500 Received: from mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.40]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6F2691800873 for ; Thu, 20 Feb 2025 09:01:53 +0000 (UTC) Received: from speedmetal.lan (unknown [10.44.22.26]) by mx-prod-int-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 90E7E19412A3 for ; Thu, 20 Feb 2025 09:01:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on lists.libvirt.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,RCVD_IN_VALIDITY_RPBL_BLOCKED, RCVD_IN_VALIDITY_SAFE_BLOCKED,SPF_HELO_NONE autolearn=unavailable autolearn_force=no version=3.4.4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1740042116; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=X+ZNlkg7koNp5GkaEXYSgLieXuEde2VgVtePa+b1Q/A=; b=OCrHqx5cgTFWEgatLVwEp1ISltzVw/myyyxvIlH5Rhl7aNotaSfkN2twMhlJY8OzqzyCqW gap8XYZtQZ1EqGeGFmVgN9NCT2gOUCLANZ3a+aMl2Y/LeeOEa1cCV1nckek/3634YIFh8U GYmVX59ifibd1nBQGEiiSL6CbtXiYB4= X-MC-Unique: RX__9jzYN8KCpJ5wDpkBlw-1 X-Mimecast-MFC-AGG-ID: RX__9jzYN8KCpJ5wDpkBlw_1740042113 From: Peter Krempa To: devel@lists.libvirt.org Subject: [PATCH 11/21] virBitmapFormat: Don't check return value Date: Thu, 20 Feb 2025 10:01:24 +0100 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.40 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: q5ZcpPOJNlNJIivtmQ0Zqd79sv1f4ldOKFWGGWWJ9WE_1740042113 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable Message-ID-Hash: O2P3G6M45JJM3HV3NLOQXXRX6EBNMOIP X-Message-ID-Hash: O2P3G6M45JJM3HV3NLOQXXRX6EBNMOIP X-MailFrom: pkrempa@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-config-1; header-match-config-2; header-match-config-3; header-match-devel.lists.libvirt.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.2 Precedence: list List-Id: Development discussions about the libvirt library & tools Archived-At: List-Archive: List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZM-MESSAGEID: 1740042427906019100 Content-Type: text/plain; charset="utf-8" 'virBitmapFormat' always returns a string; remove pointless checks. Signed-off-by: Peter Krempa --- 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 =3D virBitmapFormat(nodeset))) - return -1; + nodeset_str =3D 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 =3D NULL; - if (!(siblings =3D virBitmapFormat(cpus[j].siblings))) - return -1; + siblings =3D virBitmapFormat(cpus[j].siblings); virBufferAsprintf(&childBuf, " socket_id=3D'%d' die_id=3D'%d' cluster_id= =3D'%d' core_id=3D'%d' siblings=3D'%s'", @@ -954,9 +953,6 @@ virCapabilitiesFormatCaches(virBuffer *buf, const char *unit =3D NULL; unsigned long long short_size =3D virFormatIntPretty(bank->size, &= unit); - if (!cpus_str) - return -1; - /* * Let's just *hope* the size is aligned to KiBs so that it does n= ot * bite is back in the future @@ -1038,9 +1034,6 @@ virCapabilitiesFormatMemoryBandwidth(virBuffer *buf, virResctrlInfoMemBWPerNode *control =3D &node->control; g_autofree char *cpus_str =3D virBitmapFormat(node->cpus); - if (!cpus_str) - return -1; - virBufferAsprintf(&attrBuf, " id=3D'%u' cpus=3D'%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 n= aming * even when users specify some "sub-optimal" string there. */ vcpus_str =3D virBitmapFormat(vcpus); - if (!vcpus_str) - return NULL; if (!(flags & VIR_DOMAIN_DEF_PARSE_INACTIVE)) alloc_id =3D 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 =3D virBitmapFormat(def->source.dimm.nodes))) - return -1; + bitmap =3D virBitmapFormat(def->source.dimm.nodes); virBufferAsprintf(&childBuf, "%s\n", bitm= ap); } @@ -25893,8 +25890,7 @@ virDomainMemorySourceDefFormat(virBuffer *buf, break; case VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM: if (def->source.virtio_mem.nodes) { - if (!(bitmap =3D virBitmapFormat(def->source.virtio_mem.nodes)= )) - return -1; + bitmap =3D virBitmapFormat(def->source.virtio_mem.nodes); virBufferAsprintf(&childBuf, "%s\n", bitm= ap); } @@ -25921,8 +25917,7 @@ virDomainMemorySourceDefFormat(virBuffer *buf, case VIR_DOMAIN_MEMORY_MODEL_SGX_EPC: if (def->source.sgx_epc.nodes) { - if (!(bitmap =3D virBitmapFormat(def->source.sgx_epc.nodes))) - return -1; + bitmap =3D virBitmapFormat(def->source.sgx_epc.nodes); virBufferAsprintf(&childBuf, "%s\n", bitm= ap); } @@ -26992,9 +26987,8 @@ virDomainHugepagesFormatBuf(virBuffer *buf, hugepage->size); if (hugepage->nodemask) { - g_autofree char *nodeset =3D NULL; - if (!(nodeset =3D virBitmapFormat(hugepage->nodemask))) - return -1; + g_autofree char *nodeset =3D virBitmapFormat(hugepage->nodemask); + virBufferAsprintf(buf, " nodeset=3D'%s'", nodeset); } @@ -27321,8 +27315,6 @@ virDomainResctrlMonDefFormatHelper(virDomainResctrl= MonDef *domresmon, } vcpus =3D virBitmapFormat(domresmon->vcpus); - if (!vcpus) - return -1; virBufferAsprintf(buf, "vcpus=3D'%s'/>\n", vcpus); @@ -27356,8 +27348,6 @@ virDomainCachetuneDefFormat(virBuffer *buf, return 0; vcpus =3D virBitmapFormat(resctrl->vcpus); - if (!vcpus) - return -1; virBufferAsprintf(&attrBuf, " vcpus=3D'%s'", vcpus); @@ -27415,8 +27405,6 @@ virDomainMemorytuneDefFormat(virBuffer *buf, return 0; vcpus =3D virBitmapFormat(resctrl->vcpus); - if (!vcpus) - return -1; virBufferAsprintf(&attrBuf, " vcpus=3D'%s'", vcpus); @@ -27545,15 +27533,14 @@ virDomainCpuDefFormat(virBuffer *buf, { virDomainVcpuDef *vcpu; size_t i; - g_autofree char *cpumask =3D NULL; virBufferAddLit(buf, "placement= _mode)); if (def->cpumask && !virBitmapIsAllSet(def->cpumask)) { - if ((cpumask =3D virBitmapFormat(def->cpumask)) =3D=3D NULL) - return -1; + g_autofree char *cpumask =3D virBitmapFormat(def->cpumask); + virBufferAsprintf(buf, " cpuset=3D'%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 =3D NULL; - char *nodeset =3D NULL; bool nodesetSpecified =3D false; size_t i =3D 0; @@ -298,10 +297,9 @@ virDomainNumatuneFormatXML(virBuffer *buf, virBufferAsprintf(buf, "memory.placement =3D=3D VIR_DOMAIN_NUMATUNE_PLACEMEN= T_STATIC) { - if (!(nodeset =3D virBitmapFormat(numatune->memory.nodeset))) - return -1; + char *nodeset =3D virBitmapFormat(numatune->memory.nodeset); + virBufferAsprintf(buf, "nodeset=3D'%s'/>\n", nodeset); - VIR_FREE(nodeset); } else if (numatune->memory.placement) { tmp =3D virDomainNumatunePlacementTypeToString(numatune->memor= y.placement); virBufferAsprintf(buf, "placement=3D'%s'/>\n", tmp); @@ -310,19 +308,18 @@ virDomainNumatuneFormatXML(virBuffer *buf, for (i =3D 0; i < numatune->nmem_nodes; i++) { virDomainNumaNode *mem_node =3D &numatune->mem_nodes[i]; + g_autofree char *nodeset =3D NULL; if (!mem_node->nodeset) continue; - if (!(nodeset =3D virBitmapFormat(mem_node->nodeset))) - return -1; + nodeset =3D virBitmapFormat(mem_node->nodeset); virBufferAsprintf(buf, "\n", i, virDomainNumatuneMemModeTypeToString(mem_node->m= ode), nodeset); - VIR_FREE(nodeset); } virBufferAdjustIndent(buf, -2); @@ -461,9 +458,8 @@ virDomainNumatuneMaybeFormatNodeset(virDomainNuma *numa= tune, cellid) < 0) return -1; - if (nodeset && - !(*mask =3D virBitmapFormat(nodeset))) - return -1; + if (nodeset) + *mask =3D virBitmapFormat(nodeset); return 0; } @@ -1010,8 +1006,6 @@ virDomainNumaDefFormatXML(virBuffer *buf, if (cpumask) { g_autofree char *cpustr =3D virBitmapFormat(cpumask); - if (!cpustr) - return -1; virBufferAsprintf(&attrBuf, " cpus=3D'%s'", cpustr); } virBufferAsprintf(&attrBuf, " memory=3D'%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 =3D virBitmapFormat(obj->classIdMap); size_t i; - if (!classIdStr) - return NULL; - virBufferAddLit(&buf, "\n"); virBufferAdjustIndent(&buf, 2); virBufferAsprintf(&buf, "\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 =3D virNumaGetHostMemoryNodeset())) goto error; - if (!(mem_mask =3D virBitmapFormat(all_nodes))) - goto error; + mem_mask =3D virBitmapFormat(all_nodes); if (virCgroupHasEmptyTasks(cgroup, VIR_CGROUP_CONTROLLER_CPUSET) <=3D = 0) goto error; @@ -648,8 +647,7 @@ virDomainCgroupEmulatorAllNodesAllow(virCgroup *cgroup, if (!(all_nodes =3D virNumaGetHostMemoryNodeset())) goto cleanup; - if (!(all_nodes_str =3D virBitmapFormat(all_nodes))) - goto cleanup; + all_nodes_str =3D virBitmapFormat(all_nodes); data =3D 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 =3D virBitmapFormat(nodes))) - goto cleanup; + nodeset =3D 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 !=3D NULL) && - ((cpus =3D virBitmapFormat(def->cpumask)) =3D=3D NULL)) { - return -1; - } + if (def->cpumask !=3D NULL) + cpus =3D 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 =3D virBitmapFormat(cpu))) - return -1; + cpumask =3D virBitmapFormat(cpu); for (tmpmask =3D cpumask; tmpmask; tmpmask =3D next) { if ((next =3D 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(vir= Buffer *buf, if (!priv->autoNodeset && !priv->autoCpuset) return 0; - if (priv->autoNodeset && - !((nodeset =3D virBitmapFormat(priv->autoNodeset)))) - return -1; + if (priv->autoNodeset) + nodeset =3D virBitmapFormat(priv->autoNodeset); - if (priv->autoCpuset && - !((cpuset =3D virBitmapFormat(priv->autoCpuset)))) - return -1; + if (priv->autoCpuset) + cpuset =3D virBitmapFormat(priv->autoCpuset); virBufferAddLit(buf, "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 =3D virBitmapFormat(nodeset))) - return -1; + nodeset_str =3D 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 wi= th * the free of 'res' */ - if (!(res->vcpus =3D virBitmapFormat(domresmon->vcpus))) - goto error; - + res->vcpus =3D virBitmapFormat(domresmon->vcpus); res->name =3D 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 =3D NULL; \ - if (!(tmp =3D virBitmapFormat(name))) \ - goto cleanup; \ + g_autofree char *tmp =3D 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 =3D virBitmapFormat(map); + g_autofree char *tmp =3D 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 =3D NULL; - - if (!(new_cpus =3D virBitmapFormat(cpumask))) - return -1; + g_autofree char *new_cpus =3D 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 =3D PrlVmCfg_SetCpuCount(sdkdom, virDomainDefGetVcpus(def)); prlsdkCheckRetGoto(pret, error); - if (!(mask =3D virBitmapFormat(def->cpumask))) - goto error; + mask =3D virBitmapFormat(def->cpumask); pret =3D PrlVmCfg_SetCpuMask(sdkdom, mask); prlsdkCheckRetGoto(pret, error); --=20 2.48.1