Replace all occurrences of if (VIR_STRDUP(a, b) < 0) /* effectively dead code */ with: a = g_strdup(b); Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx> --- src/qemu/qemu_agent.c | 51 +++++-------- src/qemu/qemu_alias.c | 9 +-- src/qemu/qemu_block.c | 46 +++++------- src/qemu/qemu_blockjob.c | 9 +-- src/qemu/qemu_capabilities.c | 85 +++++++++------------- src/qemu/qemu_cgroup.c | 5 +- src/qemu/qemu_checkpoint.c | 12 ++-- src/qemu/qemu_command.c | 15 ++-- src/qemu/qemu_conf.c | 55 +++++--------- src/qemu/qemu_dbus.c | 7 +- src/qemu/qemu_domain.c | 50 +++++-------- src/qemu/qemu_driver.c | 72 +++++++------------ src/qemu/qemu_firmware.c | 44 +++++------- src/qemu/qemu_hotplug.c | 9 +-- src/qemu/qemu_interface.c | 6 +- src/qemu/qemu_interop_config.c | 6 +- src/qemu/qemu_migration.c | 26 +++---- src/qemu/qemu_migration_cookie.c | 21 ++---- src/qemu/qemu_migration_params.c | 10 +-- src/qemu/qemu_monitor.c | 14 ++-- src/qemu/qemu_monitor_json.c | 120 +++++++++++-------------------- src/qemu/qemu_process.c | 57 ++++++--------- src/qemu/qemu_vhost_user.c | 6 +- 23 files changed, 260 insertions(+), 475 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index bd5b8035ca..4b914e6d3b 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -1750,8 +1750,7 @@ qemuAgentGetHostname(qemuAgentPtr mon, goto cleanup; } - if (VIR_STRDUP(*hostname, result) < 0) - goto cleanup; + *hostname = g_strdup(result); ret = 0; @@ -1911,22 +1910,21 @@ qemuAgentFSInfoToPublic(qemuAgentFSInfoPtr agent) virDomainFSInfoPtr ret = NULL; size_t i; - if (VIR_ALLOC(ret) < 0 || - VIR_STRDUP(ret->mountpoint, agent->mountpoint) < 0 || - VIR_STRDUP(ret->name, agent->name) < 0 || - VIR_STRDUP(ret->fstype, agent->fstype) < 0) + if (VIR_ALLOC(ret) < 0) goto error; + ret->mountpoint = g_strdup(agent->mountpoint); + ret->name = g_strdup(agent->name); + ret->fstype = g_strdup(agent->fstype); + if (agent->disks && VIR_ALLOC_N(ret->devAlias, agent->ndisks) < 0) goto error; ret->ndevAlias = agent->ndisks; - for (i = 0; i < ret->ndevAlias; i++) { - if (VIR_STRDUP(ret->devAlias[i], agent->disks[i]->alias) < 0) - goto error; - } + for (i = 0; i < ret->ndevAlias; i++) + ret->devAlias[i] = g_strdup(agent->disks[i]->alias); return ret; @@ -1980,15 +1978,11 @@ qemuAgentGetFSInfoInternalDisk(virJSONValuePtr jsondisks, return -1; disk = fsinfo->disks[i]; - if ((val = virJSONValueObjectGetString(jsondisk, "serial"))) { - if (VIR_STRDUP(disk->serial, val) < 0) - return -1; - } + if ((val = virJSONValueObjectGetString(jsondisk, "serial"))) + disk->serial = g_strdup(val); - if ((val = virJSONValueObjectGetString(jsondisk, "dev"))) { - if (VIR_STRDUP(disk->devnode, val) < 0) - return -1; - } + if ((val = virJSONValueObjectGetString(jsondisk, "dev"))) + disk->devnode = g_strdup(val); #define GET_DISK_ADDR(jsonObject, var, name) \ do { \ @@ -2025,8 +2019,7 @@ qemuAgentGetFSInfoInternalDisk(virJSONValuePtr jsondisks, unit))) continue; - if (VIR_STRDUP(disk->alias, diskDef->dst) < 0) - return -1; + disk->alias = g_strdup(diskDef->dst); } return 0; @@ -2106,8 +2099,7 @@ qemuAgentGetFSInfoInternal(qemuAgentPtr mon, goto cleanup; } - if (VIR_STRDUP(info_ret[i]->mountpoint, result) < 0) - goto cleanup; + info_ret[i]->mountpoint = g_strdup(result); if (!(result = virJSONValueObjectGetString(entry, "name"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -2115,8 +2107,7 @@ qemuAgentGetFSInfoInternal(qemuAgentPtr mon, goto cleanup; } - if (VIR_STRDUP(info_ret[i]->name, result) < 0) - goto cleanup; + info_ret[i]->name = g_strdup(result); if (!(result = virJSONValueObjectGetString(entry, "type"))) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -2124,8 +2115,7 @@ qemuAgentGetFSInfoInternal(qemuAgentPtr mon, goto cleanup; } - if (VIR_STRDUP(info_ret[i]->fstype, result) < 0) - goto cleanup; + info_ret[i]->fstype = g_strdup(result); /* 'used-bytes' and 'total-bytes' were added in qemu-ga 3.0 */ @@ -2404,12 +2394,10 @@ qemuAgentGetInterfaces(qemuAgentPtr mon, iface = ifaces_ret[ifaces_count - 1]; iface->naddrs = 0; - if (VIR_STRDUP(iface->name, ifname_s) < 0) - goto error; + iface->name = g_strdup(ifname_s); hwaddr = virJSONValueObjectGetString(tmp_iface, "hardware-address"); - if (VIR_STRDUP(iface->hwaddr, hwaddr) < 0) - goto error; + iface->hwaddr = g_strdup(hwaddr); } /* Has to be freed for each interface. */ @@ -2471,8 +2459,7 @@ qemuAgentGetInterfaces(qemuAgentPtr mon, " field for interface '%s'"), name); goto error; } - if (VIR_STRDUP(ip_addr->addr, addr) < 0) - goto error; + ip_addr->addr = g_strdup(addr); if (virJSONValueObjectGetNumberUint(ip_addr_obj, "prefix", &ip_addr->prefix) < 0) { diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c index d4d8eb4252..f11099ce90 100644 --- a/src/qemu/qemu_alias.c +++ b/src/qemu/qemu_alias.c @@ -231,8 +231,7 @@ qemuAssignDeviceDiskAlias(virDomainDefPtr def, case VIR_DOMAIN_DISK_BUS_IDE: case VIR_DOMAIN_DISK_BUS_SATA: case VIR_DOMAIN_DISK_BUS_SCSI: - if (VIR_STRDUP(diskPriv->qomName, disk->info.alias) < 0) - return -1; + diskPriv->qomName = g_strdup(disk->info.alias); break; case VIR_DOMAIN_DISK_BUS_VIRTIO: @@ -543,8 +542,7 @@ qemuAssignDeviceWatchdogAlias(virDomainWatchdogDefPtr watchdog) if (watchdog->info.alias) return 0; - if (VIR_STRDUP(watchdog->info.alias, "watchdog0") < 0) - return -1; + watchdog->info.alias = g_strdup("watchdog0"); return 0; } @@ -579,8 +577,7 @@ qemuAssignDeviceVsockAlias(virDomainVsockDefPtr vsock) { if (vsock->info.alias) return 0; - if (VIR_STRDUP(vsock->info.alias, "vsock0") < 0) - return -1; + vsock->info.alias = g_strdup("vsock0"); return 0; } diff --git a/src/qemu/qemu_block.c b/src/qemu/qemu_block.c index 515bcd3d59..c584d56e13 100644 --- a/src/qemu/qemu_block.c +++ b/src/qemu/qemu_block.c @@ -172,12 +172,11 @@ qemuBlockNodeNameGetBackingChainBacking(virJSONValuePtr next, if (VIR_ALLOC(data) < 0) return -1; - if (VIR_STRDUP(data->nodeformat, nodename) < 0 || - VIR_STRDUP(data->nodestorage, parentnodename) < 0 || - VIR_STRDUP(data->qemufilename, filename) < 0 || - VIR_STRDUP(data->drvformat, drvname) < 0 || - VIR_STRDUP(data->drvstorage, drvparent) < 0) - return -1; + data->nodeformat = g_strdup(nodename); + data->nodestorage = g_strdup(parentnodename); + data->qemufilename = g_strdup(filename); + data->drvformat = g_strdup(drvname); + data->drvstorage = g_strdup(drvparent); if (backing && qemuBlockNodeNameGetBackingChainBacking(backing, nodenamestable, @@ -302,9 +301,8 @@ qemuBlockDiskDetectNodes(virDomainDiskDefPtr disk, break; } else { - if (VIR_STRDUP(src->nodeformat, entry->nodeformat) < 0 || - VIR_STRDUP(src->nodestorage, entry->nodestorage) < 0) - goto cleanup; + src->nodeformat = g_strdup(entry->nodeformat); + src->nodestorage = g_strdup(entry->nodestorage); } entry = entry->backing; @@ -423,9 +421,7 @@ qemuBlockStorageSourceGetURI(virStorageSourcePtr src) if (src->hosts->transport == VIR_STORAGE_NET_HOST_TRANS_TCP) { uri->port = src->hosts->port; - if (VIR_STRDUP(uri->scheme, - virStorageNetProtocolTypeToString(src->protocol)) < 0) - return NULL; + uri->scheme = g_strdup(virStorageNetProtocolTypeToString(src->protocol)); } else { if (virAsprintf(&uri->scheme, "%s+%s", virStorageNetProtocolTypeToString(src->protocol), @@ -446,8 +442,7 @@ qemuBlockStorageSourceGetURI(virStorageSourcePtr src) } } - if (VIR_STRDUP(uri->server, src->hosts->name) < 0) - return NULL; + uri->server = g_strdup(src->hosts->name); return g_steal_pointer(&uri); } @@ -757,8 +752,7 @@ qemuBlockStorageSourceGetISCSIProps(virStorageSourcePtr src, * } */ - if (VIR_STRDUP(target, src->path) < 0) - return NULL; + target = g_strdup(src->path); /* Separate the target and lun */ if ((lunStr = strchr(target, '/'))) { @@ -1685,23 +1679,17 @@ qemuBlockStorageSourceDetachPrepare(virStorageSourcePtr src, } if (src->pr && - !virStoragePRDefIsManaged(src->pr) && - VIR_STRDUP(data->prmgrAlias, src->pr->mgralias) < 0) - goto cleanup; + !virStoragePRDefIsManaged(src->pr)) + data->prmgrAlias = g_strdup(src->pr->mgralias); - if (VIR_STRDUP(data->tlsAlias, src->tlsAlias) < 0) - goto cleanup; + data->tlsAlias = g_strdup(src->tlsAlias); if (srcpriv) { - if (srcpriv->secinfo && - srcpriv->secinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES && - VIR_STRDUP(data->authsecretAlias, srcpriv->secinfo->s.aes.alias) < 0) - goto cleanup; + if (srcpriv->secinfo && srcpriv->secinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES) + data->authsecretAlias = g_strdup(srcpriv->secinfo->s.aes.alias); - if (srcpriv->encinfo && - srcpriv->encinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES && - VIR_STRDUP(data->encryptsecretAlias, srcpriv->encinfo->s.aes.alias) < 0) - goto cleanup; + if (srcpriv->encinfo && srcpriv->encinfo->type == VIR_DOMAIN_SECRET_INFO_TYPE_AES) + data->encryptsecretAlias = g_strdup(srcpriv->encinfo->s.aes.alias); } ret = g_steal_pointer(&data); diff --git a/src/qemu/qemu_blockjob.c b/src/qemu/qemu_blockjob.c index 3506fa165b..6a7dd5a1d4 100644 --- a/src/qemu/qemu_blockjob.c +++ b/src/qemu/qemu_blockjob.c @@ -111,8 +111,7 @@ qemuBlockJobDataNew(qemuBlockJobType type, if (!(job = virObjectNew(qemuBlockJobDataClass))) return NULL; - if (VIR_STRDUP(job->name, name) < 0) - return NULL; + job->name = g_strdup(name); job->state = QEMU_BLOCKJOB_STATE_NEW; job->newstate = -1; @@ -483,8 +482,7 @@ qemuBlockJobRefreshJobs(virQEMUDriverPtr driver, * execute the finishing steps */ job->newstate = job->state; } else if (newstate == QEMU_BLOCKJOB_STATE_CONCLUDED) { - if (VIR_STRDUP(job->errmsg, jobinfo[i]->error) < 0) - goto cleanup; + job->errmsg = g_strdup(jobinfo[i]->error); if (job->errmsg) job->newstate = QEMU_BLOCKJOB_STATE_FAILED; @@ -1357,8 +1355,7 @@ qemuBlockJobEventProcessConcluded(qemuBlockJobDataPtr job, if (STRNEQ_NULLABLE(job->name, jobinfo[i]->id)) continue; - if (VIR_STRDUP(job->errmsg, jobinfo[i]->error) < 0) - rc = -1; + job->errmsg = g_strdup(jobinfo[i]->error); if (job->errmsg) job->newstate = QEMU_BLOCKJOB_STATE_FAILED; diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index 0377cea51a..e8d7cb84e2 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -793,10 +793,8 @@ virQEMUCapsInitGuest(virCapsPtr caps, /* RHEL doesn't follow the usual naming for QEMU binaries and ships * a single binary named qemu-kvm outside of $PATH instead */ - if (virQEMUCapsGuestIsNative(hostarch, guestarch) && !binary) { - if (VIR_STRDUP(binary, "/usr/libexec/qemu-kvm") < 0) - return -1; - } + if (virQEMUCapsGuestIsNative(hostarch, guestarch) && !binary) + binary = g_strdup("/usr/libexec/qemu-kvm"); /* Ignore binary if extracting version info fails */ if (binary) { @@ -1582,11 +1580,12 @@ virQEMUCapsSEVInfoCopy(virSEVCapabilityPtr *dst, { g_autoptr(virSEVCapability) tmp = NULL; - if (VIR_ALLOC(tmp) < 0 || - VIR_STRDUP(tmp->pdh, src->pdh) < 0 || - VIR_STRDUP(tmp->cert_chain, src->cert_chain) < 0) + if (VIR_ALLOC(tmp) < 0) return -1; + tmp->pdh = g_strdup(src->pdh); + tmp->cert_chain = g_strdup(src->cert_chain); + tmp->cbitpos = src->cbitpos; tmp->reduced_phys_bits = src->reduced_phys_bits; @@ -1606,8 +1605,7 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps) ret->usedQMP = qemuCaps->usedQMP; ret->kvmSupportsNesting = qemuCaps->kvmSupportsNesting; - if (VIR_STRDUP(ret->binary, qemuCaps->binary) < 0) - goto error; + ret->binary = g_strdup(qemuCaps->binary); ret->ctime = qemuCaps->ctime; @@ -1617,11 +1615,8 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps) ret->kvmVersion = qemuCaps->kvmVersion; ret->microcodeVersion = qemuCaps->microcodeVersion; - if (VIR_STRDUP(ret->package, qemuCaps->package) < 0) - goto error; - - if (VIR_STRDUP(ret->kernelVersion, qemuCaps->kernelVersion) < 0) - goto error; + ret->package = g_strdup(qemuCaps->package); + ret->kernelVersion = g_strdup(qemuCaps->kernelVersion); ret->arch = qemuCaps->arch; @@ -1645,9 +1640,8 @@ virQEMUCapsPtr virQEMUCapsNewCopy(virQEMUCapsPtr qemuCaps) goto error; ret->nmachineTypes = qemuCaps->nmachineTypes; for (i = 0; i < qemuCaps->nmachineTypes; i++) { - if (VIR_STRDUP(ret->machineTypes[i].name, qemuCaps->machineTypes[i].name) < 0 || - VIR_STRDUP(ret->machineTypes[i].alias, qemuCaps->machineTypes[i].alias) < 0) - goto error; + ret->machineTypes[i].name = g_strdup(qemuCaps->machineTypes[i].name); + ret->machineTypes[i].alias = g_strdup(qemuCaps->machineTypes[i].alias); ret->machineTypes[i].maxCpus = qemuCaps->machineTypes[i].maxCpus; ret->machineTypes[i].hotplugCpus = qemuCaps->machineTypes[i].hotplugCpus; ret->machineTypes[i].qemuDefault = qemuCaps->machineTypes[i].qemuDefault; @@ -1999,12 +1993,10 @@ int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps, goto error; (*machines)[i] = mach; if (qemuCaps->machineTypes[i].alias) { - if (VIR_STRDUP(mach->name, qemuCaps->machineTypes[i].alias) < 0 || - VIR_STRDUP(mach->canonical, qemuCaps->machineTypes[i].name) < 0) - goto error; + mach->name = g_strdup(qemuCaps->machineTypes[i].alias); + mach->canonical = g_strdup(qemuCaps->machineTypes[i].name); } else { - if (VIR_STRDUP(mach->name, qemuCaps->machineTypes[i].name) < 0) - goto error; + mach->name = g_strdup(qemuCaps->machineTypes[i].name); } mach->maxCpus = qemuCaps->machineTypes[i].maxCpus; } @@ -2039,8 +2031,7 @@ int virQEMUCapsGetMachineTypesCaps(virQEMUCapsPtr qemuCaps, VIR_FREE(mach); goto error; } - if (VIR_STRDUP(mach->name, machine->canonical) < 0) - goto error; + mach->name = g_strdup(machine->canonical); mach->maxCpus = machine->maxCpus; i++; } @@ -2358,9 +2349,8 @@ virQEMUCapsProbeQMPMachineTypes(virQEMUCapsPtr qemuCaps, mach = &(qemuCaps->machineTypes[qemuCaps->nmachineTypes++]); - if (VIR_STRDUP(mach->alias, machines[i]->alias) < 0 || - VIR_STRDUP(mach->name, machines[i]->name) < 0) - goto cleanup; + mach->alias = g_strdup(machines[i]->alias); + mach->name = g_strdup(machines[i]->name); mach->maxCpus = machines[i]->maxCpus; mach->hotplugCpus = machines[i]->hotplugCpus; @@ -2467,8 +2457,7 @@ virQEMUCapsFetchCPUDefinitions(qemuMonitorPtr mon, continue; VIR_FREE(cpus[i]->name); - if (VIR_STRDUP(cpus[i]->name, *name) < 0) - goto error; + cpus[i]->name = g_strdup(*name); } } } @@ -2550,9 +2539,11 @@ virQEMUCapsProbeQMPHostCPU(virQEMUCapsPtr qemuCaps, model = "host"; } - if (VIR_ALLOC(cpu) < 0 || VIR_STRDUP(cpu->model, model) < 0) + if (VIR_ALLOC(cpu) < 0) goto cleanup; + cpu->model = g_strdup(model); + /* Some x86_64 features defined in cpu_map.xml use spelling which differ * from the one preferred by QEMU. Static expansion would give us only the * preferred spelling. With new QEMU we always use the QEMU's canonical @@ -2661,9 +2652,7 @@ virQEMUCapsGetCPUFeatures(virQEMUCapsPtr qemuCaps, if (migratable && prop->migratable == VIR_TRISTATE_BOOL_NO) continue; - if (VIR_STRDUP(list[n++], - virQEMUCapsCPUFeatureFromQEMU(qemuCaps, prop->name)) < 0) - goto cleanup; + list[n++] = g_strdup(virQEMUCapsCPUFeatureFromQEMU(qemuCaps, prop->name)); } *features = g_steal_pointer(&list); @@ -2672,7 +2661,6 @@ virQEMUCapsGetCPUFeatures(virQEMUCapsPtr qemuCaps, else ret = 0; - cleanup: virStringListFree(list); return ret; } @@ -3022,8 +3010,8 @@ virQEMUCapsInitCPUModelS390(virQEMUCapsPtr qemuCaps, return 2; } - if (VIR_STRDUP(cpu->model, modelInfo->name) < 0 || - VIR_ALLOC_N(cpu->features, modelInfo->nprops) < 0) + cpu->model = g_strdup(modelInfo->name); + if (VIR_ALLOC_N(cpu->features, modelInfo->nprops) < 0) return -1; cpu->nfeatures_max = modelInfo->nprops; @@ -3037,8 +3025,7 @@ virQEMUCapsInitCPUModelS390(virQEMUCapsPtr qemuCaps, if (prop->type != QEMU_MONITOR_CPU_PROPERTY_BOOLEAN) continue; - if (VIR_STRDUP(feature->name, name) < 0) - return -1; + feature->name = g_strdup(name); if (!prop->value.boolean || (migratable && prop->migratable == VIR_TRISTATE_BOOL_NO)) @@ -4715,8 +4702,7 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch, if (!(qemuCaps = virQEMUCapsNew())) goto error; - if (VIR_STRDUP(qemuCaps->binary, binary) < 0) - goto error; + qemuCaps->binary = g_strdup(binary); /* We would also want to check faccessat if we cared about ACLs, * but we don't. */ @@ -4749,8 +4735,7 @@ virQEMUCapsNewForBinaryInternal(virArch hostArch, if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_KVM)) { qemuCaps->microcodeVersion = microcodeVersion; - if (VIR_STRDUP(qemuCaps->kernelVersion, kernelVersion) < 0) - goto error; + qemuCaps->kernelVersion = g_strdup(kernelVersion); qemuCaps->kvmSupportsNesting = virQEMUCapsKVMSupportsNesting(); } @@ -4791,8 +4776,7 @@ virQEMUCapsLoadFile(const char *filename, if (!qemuCaps) return NULL; - if (VIR_STRDUP(qemuCaps->binary, binary) < 0) - goto error; + qemuCaps->binary = g_strdup(binary); if (virQEMUCapsLoadCache(priv->hostArch, qemuCaps, filename) < 0) goto error; @@ -4875,8 +4859,7 @@ virQEMUCapsCacheNew(const char *libDir, goto error; virFileCacheSetPriv(cache, priv); - if (VIR_STRDUP(priv->libDir, libDir) < 0) - goto error; + priv->libDir = g_strdup(libDir); priv->hostArch = virArchFromHost(); @@ -5192,9 +5175,7 @@ virQEMUCapsFillDomainLoaderCaps(virDomainCapsLoaderPtr capsLoader, if (j != capsLoader->values.nvalues) continue; - if (VIR_STRDUP(capsLoader->values.values[capsLoader->values.nvalues], - filename) < 0) - return -1; + capsLoader->values.values[capsLoader->values.nvalues] = g_strdup(filename); capsLoader->values.nvalues++; } @@ -5590,11 +5571,9 @@ virQEMUCapsFillDomainFeatureSEVCaps(virQEMUCapsPtr qemuCaps, if (VIR_ALLOC(sev) < 0) return -1; - if (VIR_STRDUP(sev->pdh, cap->pdh) < 0) - return -1; + sev->pdh = g_strdup(cap->pdh); - if (VIR_STRDUP(sev->cert_chain, cap->cert_chain) < 0) - return -1; + sev->cert_chain = g_strdup(cap->cert_chain); sev->cbitpos = cap->cbitpos; sev->reduced_phys_bits = cap->reduced_phys_bits; diff --git a/src/qemu/qemu_cgroup.c b/src/qemu/qemu_cgroup.c index 5a58e77fa4..e49bb8fb7e 100644 --- a/src/qemu/qemu_cgroup.c +++ b/src/qemu/qemu_cgroup.c @@ -933,10 +933,7 @@ qemuInitCgroup(virDomainObjPtr vm, if (VIR_ALLOC(res) < 0) goto cleanup; - if (VIR_STRDUP(res->partition, "/machine") < 0) { - VIR_FREE(res); - goto cleanup; - } + res->partition = g_strdup("/machine"); vm->def->resource = res; } diff --git a/src/qemu/qemu_checkpoint.c b/src/qemu/qemu_checkpoint.c index 4b4ad8bb83..4a618f5236 100644 --- a/src/qemu/qemu_checkpoint.c +++ b/src/qemu/qemu_checkpoint.c @@ -409,9 +409,8 @@ qemuCheckpointCreateXML(virDomainPtr domain, other = virDomainCheckpointGetCurrent(vm->checkpoints); if (other) { - if (!redefine && - VIR_STRDUP(chk->def->parent_name, other->def->name) < 0) - goto endjob; + if (!redefine) + chk->def->parent_name = g_strdup(other->def->name); } /* actually do the checkpoint */ @@ -513,11 +512,8 @@ qemuCheckpointReparentChildren(void *payload, VIR_FREE(moment->def->parent_name); - if (rep->parent->def && - VIR_STRDUP(moment->def->parent_name, rep->parent->def->name) < 0) { - rep->err = -1; - return 0; - } + if (rep->parent->def) + moment->def->parent_name = g_strdup(rep->parent->def->name); rep->err = qemuCheckpointWriteMetadata(rep->vm, moment, rep->caps, rep->xmlopt, rep->dir); diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index b579b994f3..f24013f9eb 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -799,8 +799,7 @@ qemuBuildGeneralSecinfoURI(virURIPtr uri, secinfo->s.plain.secret) < 0) return -1; } else { - if (VIR_STRDUP(uri->user, secinfo->s.plain.username) < 0) - return -1; + uri->user = g_strdup(secinfo->s.plain.username); } break; @@ -1135,8 +1134,7 @@ qemuGetDriveSourceString(virStorageSourcePtr src, case VIR_STORAGE_TYPE_BLOCK: case VIR_STORAGE_TYPE_FILE: case VIR_STORAGE_TYPE_DIR: - if (VIR_STRDUP(*source, src->path) < 0) - return -1; + *source = g_strdup(src->path); break; @@ -2053,8 +2051,7 @@ qemuBuildDiskDeviceStr(const virDomainDef *def, * ourselves especially for cases when -blockdev will be used */ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_SCSI_DISK_DEVICE_ID)) { if (disk->serial) { - if (VIR_STRDUP(scsiVPDDeviceId, disk->serial) < 0) - goto error; + scsiVPDDeviceId = g_strdup(disk->serial); } else { if (!(scsiVPDDeviceId = qemuAliasDiskDriveFromDisk(disk))) goto error; @@ -3449,8 +3446,7 @@ qemuBuildMemoryBackendProps(virJSONValuePtr *backendProps, def->mem.source == VIR_DOMAIN_MEMORY_SOURCE_FILE) { if (mem->nvdimmPath) { - if (VIR_STRDUP(memPath, mem->nvdimmPath) < 0) - return -1; + memPath = g_strdup(mem->nvdimmPath); if (!priv->memPrealloc) prealloc = true; } else if (useHugepage) { @@ -7044,8 +7040,7 @@ qemuBuildCpuCommandLine(virCommandPtr cmd, return -1; } - if (VIR_STRDUP(cpu, default_model) < 0) - return -1; + cpu = g_strdup(default_model); } if (cpu) { diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c index 65cd959cf8..fae697a2ef 100644 --- a/src/qemu/qemu_conf.c +++ b/src/qemu/qemu_conf.c @@ -138,8 +138,7 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged) "%s/log/swtpm/libvirt/qemu", LOCALSTATEDIR) < 0) return NULL; - if (VIR_STRDUP(cfg->configBaseDir, SYSCONFDIR "/libvirt") < 0) - return NULL; + cfg->configBaseDir = g_strdup(SYSCONFDIR "/libvirt"); if (virAsprintf(&cfg->stateDir, "%s/libvirt/qemu", RUNSTATEDIR) < 0) @@ -242,15 +241,10 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged) * This will then be used as a fallback if the service specific * directory doesn't exist (although we don't check if this exists). */ - if (VIR_STRDUP(cfg->defaultTLSx509certdir, - SYSCONFDIR "/pki/qemu") < 0) - return NULL; + cfg->defaultTLSx509certdir = g_strdup(SYSCONFDIR "/pki/qemu"); - if (VIR_STRDUP(cfg->vncListen, VIR_LOOPBACK_IPV4_ADDR) < 0) - return NULL; - - if (VIR_STRDUP(cfg->spiceListen, VIR_LOOPBACK_IPV4_ADDR) < 0) - return NULL; + cfg->vncListen = g_strdup(VIR_LOOPBACK_IPV4_ADDR); + cfg->spiceListen = g_strdup(VIR_LOOPBACK_IPV4_ADDR); cfg->remotePortMin = QEMU_REMOTE_PORT_MIN; cfg->remotePortMax = QEMU_REMOTE_PORT_MAX; @@ -271,10 +265,9 @@ virQEMUDriverConfigPtr virQEMUDriverConfigNew(bool privileged) return NULL; } - if (VIR_STRDUP(cfg->bridgeHelperName, QEMU_BRIDGE_HELPER) < 0 || - VIR_STRDUP(cfg->prHelperName, QEMU_PR_HELPER) < 0 || - VIR_STRDUP(cfg->slirpHelperName, QEMU_SLIRP_HELPER) < 0) - return NULL; + cfg->bridgeHelperName = g_strdup(QEMU_BRIDGE_HELPER); + cfg->prHelperName = g_strdup(QEMU_PR_HELPER); + cfg->slirpHelperName = g_strdup(QEMU_SLIRP_HELPER); cfg->clearEmulatorCapabilities = true; @@ -386,10 +379,9 @@ virQEMUDriverConfigHugeTLBFSInit(virHugeTLBFSPtr hugetlbfs, const char *path, bool deflt) { - if (VIR_STRDUP(hugetlbfs->mnt_dir, path) < 0 || - virFileGetHugepageSize(path, &hugetlbfs->size) < 0) { + hugetlbfs->mnt_dir = g_strdup(path); + if (virFileGetHugepageSize(path, &hugetlbfs->size) < 0) return -1; - } hugetlbfs->deflt = deflt; return 0; @@ -1151,10 +1143,7 @@ virQEMUDriverConfigSetDefaults(virQEMUDriverConfigPtr cfg) if (!cfg->val## TLSx509certdir && \ !cfg->val## TLSx509secretUUID && \ cfg->defaultTLSx509secretUUID) { \ - if (VIR_STRDUP(cfg->val## TLSx509secretUUID, \ - cfg->defaultTLSx509secretUUID) < 0) { \ - return -1; \ - } \ + cfg->val## TLSx509secretUUID = g_strdup(cfg->defaultTLSx509secretUUID); \ } \ } while (0) @@ -1176,15 +1165,9 @@ virQEMUDriverConfigSetDefaults(virQEMUDriverConfigPtr cfg) if (cfg->val ## TLSx509certdir) \ break; \ if (virFileExists(SYSCONFDIR "/pki/libvirt-"#val)) { \ - if (VIR_STRDUP(cfg->val ## TLSx509certdir, \ - SYSCONFDIR "/pki/libvirt-"#val) < 0) { \ - return -1; \ - } \ + cfg->val ## TLSx509certdir = g_strdup(SYSCONFDIR "/pki/libvirt-"#val); \ } else { \ - if (VIR_STRDUP(cfg->val ## TLSx509certdir, \ - cfg->defaultTLSx509certdir) < 0) { \ - return -1; \ - } \ + cfg->val ## TLSx509certdir = g_strdup(cfg->defaultTLSx509certdir); \ } \ } while (0) @@ -1276,9 +1259,8 @@ virCapsPtr virQEMUDriverCreateCapabilities(virQEMUDriverPtr driver) virCapsHostSecModelPtr sm = &caps->host.secModels[i]; doi = qemuSecurityGetDOI(sec_managers[i]); model = qemuSecurityGetModel(sec_managers[i]); - if (VIR_STRDUP(sm->model, model) < 0 || - VIR_STRDUP(sm->doi, doi) < 0) - return NULL; + sm->model = g_strdup(model); + sm->doi = g_strdup(doi); for (j = 0; j < G_N_ELEMENTS(virtTypes); j++) { lbl = qemuSecurityGetBaseLabel(sec_managers[i], virtTypes[j]); @@ -1587,19 +1569,20 @@ qemuSharedDeviceEntryInsert(virQEMUDriverPtr driver, * recorded in the table. */ if (!qemuSharedDeviceEntryDomainExists(entry, name, NULL)) { - if (VIR_EXPAND_N(entry->domains, entry->ref, 1) < 0 || - VIR_STRDUP(entry->domains[entry->ref - 1], name) < 0) { + if (VIR_EXPAND_N(entry->domains, entry->ref, 1) < 0) { /* entry is owned by the hash table here */ entry = NULL; goto error; } + entry->domains[entry->ref - 1] = g_strdup(name); } } else { if (VIR_ALLOC(entry) < 0 || - VIR_ALLOC_N(entry->domains, 1) < 0 || - VIR_STRDUP(entry->domains[0], name) < 0) + VIR_ALLOC_N(entry->domains, 1) < 0) goto error; + entry->domains[0] = g_strdup(name); + entry->ref = 1; if (virHashAddEntry(driver->sharedDevices, key, entry) < 0) diff --git a/src/qemu/qemu_dbus.c b/src/qemu/qemu_dbus.c index f4205a74bb..faee122021 100644 --- a/src/qemu/qemu_dbus.c +++ b/src/qemu/qemu_dbus.c @@ -42,11 +42,8 @@ qemuDBusVMStateNew(const char *id, const char *addr) if (VIR_ALLOC(self) < 0) return NULL; - if (VIR_STRDUP(self->id, id) < 0) - return NULL; - - if (VIR_STRDUP(self->addr, addr) < 0) - return NULL; + self->id = g_strdup(id); + self->addr = g_strdup(addr); return g_steal_pointer(&self); } diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index ab13eebd39..9b201a8259 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -1407,14 +1407,12 @@ qemuDomainSecretPlainSetup(qemuDomainSecretInfoPtr secinfo, return -1; secinfo->type = VIR_DOMAIN_SECRET_INFO_TYPE_PLAIN; - if (VIR_STRDUP(secinfo->s.plain.username, username) < 0) - goto cleanup; + secinfo->s.plain.username = g_strdup(username); ret = virSecretGetSecretString(conn, seclookupdef, usageType, &secinfo->s.plain.secret, &secinfo->s.plain.secretlen); - cleanup: virObjectUnref(conn); return ret; } @@ -1456,8 +1454,7 @@ qemuDomainSecretAESSetup(qemuDomainObjPrivatePtr priv, return -1; secinfo->type = VIR_DOMAIN_SECRET_INFO_TYPE_AES; - if (VIR_STRDUP(secinfo->s.aes.username, username) < 0) - goto cleanup; + secinfo->s.aes.username = g_strdup(username); if (!(secinfo->s.aes.alias = qemuDomainGetSecretAESAlias(srcalias, isLuks))) goto cleanup; @@ -1865,8 +1862,7 @@ qemuDomainSecretGraphicsPrepare(virQEMUDriverConfigPtr cfg, if (!cfg->vncTLS) return 0; - if (VIR_STRDUP(gfxPriv->tlsAlias, "vnc-tls-creds0") < 0) - return -1; + gfxPriv->tlsAlias = g_strdup("vnc-tls-creds0"); if (cfg->vncTLSx509secretUUID) { gfxPriv->secinfo = qemuDomainSecretInfoTLSNew(priv, gfxPriv->tlsAlias, @@ -4352,8 +4348,7 @@ qemuCanonicalizeMachine(virDomainDefPtr def, virQEMUCapsPtr qemuCaps) if (STRNEQ(canon, def->os.machine)) { char *tmp; - if (VIR_STRDUP(tmp, canon) < 0) - return -1; + tmp = g_strdup(canon); VIR_FREE(def->os.machine); def->os.machine = tmp; } @@ -10409,8 +10404,7 @@ qemuDomainDiskGetBackendAlias(virDomainDiskDefPtr disk, else nodename = disk->src->nodeformat; - if (VIR_STRDUP(*backendAlias, nodename) < 0) - return -1; + *backendAlias = g_strdup(nodename); return 0; } @@ -12507,10 +12501,8 @@ qemuProcessPrepareStorageSourceTLSVxhs(virStorageSourcePtr src, src->tlsFromConfig = true; } - if (src->haveTLS == VIR_TRISTATE_BOOL_YES) { - if (VIR_STRDUP(src->tlsCertdir, cfg->vxhsTLSx509certdir) < 0) - return -1; - } + if (src->haveTLS == VIR_TRISTATE_BOOL_YES) + src->tlsCertdir = g_strdup(cfg->vxhsTLSx509certdir); return 0; } @@ -12536,8 +12528,7 @@ qemuProcessPrepareStorageSourceTLSNBD(virStorageSourcePtr src, return -1; } - if (VIR_STRDUP(src->tlsCertdir, cfg->nbdTLSx509certdir) < 0) - return -1; + src->tlsCertdir = g_strdup(cfg->nbdTLSx509certdir); } return 0; @@ -12876,15 +12867,14 @@ qemuDomainGetHostdevPath(virDomainDefPtr def, toAlloc = 2; if (VIR_ALLOC_N(tmpPaths, toAlloc) < 0 || - VIR_ALLOC_N(tmpPerms, toAlloc) < 0 || - VIR_STRDUP(tmpPaths[0], tmpPath) < 0) + VIR_ALLOC_N(tmpPerms, toAlloc) < 0) goto cleanup; + tmpPaths[0] = g_strdup(tmpPath); tmpNpaths = toAlloc; tmpPerms[0] = perm; if (includeVFIO) { - if (VIR_STRDUP(tmpPaths[1], QEMU_DEV_VFIO) < 0) - goto cleanup; + tmpPaths[1] = g_strdup(QEMU_DEV_VFIO); tmpPerms[1] = VIR_CGROUP_DEVICE_RW; } } @@ -13174,8 +13164,7 @@ qemuDomainCreateDeviceRecursive(const char *device, if (IS_RELATIVE_FILE_NAME(target)) { char *c = NULL, *tmp = NULL, *devTmp = NULL; - if (VIR_STRDUP(devTmp, device) < 0) - goto cleanup; + devTmp = g_strdup(device); if ((c = strrchr(devTmp, '/'))) *(c + 1) = '\0'; @@ -14152,8 +14141,7 @@ qemuDomainAttachDeviceMknodRecursive(virQEMUDriverPtr driver, if (IS_RELATIVE_FILE_NAME(target)) { char *c = NULL, *tmp = NULL, *fileTmp = NULL; - if (VIR_STRDUP(fileTmp, file) < 0) - goto cleanup; + fileTmp = g_strdup(file); if ((c = strrchr(fileTmp, '/'))) *(c + 1) = '\0'; @@ -14438,10 +14426,11 @@ qemuDomainNamespaceSetupDisk(virDomainObjPtr vm, } /* qemu-pr-helper might require access to /dev/mapper/control. */ - if (src->pr && - (VIR_STRDUP(dmPath, QEMU_DEVICE_MAPPER_CONTROL_PATH) < 0 || - VIR_APPEND_ELEMENT_COPY(paths, npaths, dmPath) < 0)) - goto cleanup; + if (src->pr) { + dmPath = g_strdup(QEMU_DEVICE_MAPPER_CONTROL_PATH); + if (VIR_APPEND_ELEMENT_COPY(paths, npaths, dmPath) < 0) + goto cleanup; + } if (qemuDomainNamespaceMknodPaths(vm, paths, npaths) < 0) goto cleanup; @@ -15116,8 +15105,7 @@ qemuDomainPrepareStorageSourcePR(virStorageSourcePtr src, VIR_FREE(src->pr->path); if (!(src->pr->path = qemuDomainGetManagedPRSocketPath(priv))) return -1; - if (VIR_STRDUP(src->pr->mgralias, qemuDomainGetManagedPRAlias()) < 0) - return -1; + src->pr->mgralias = g_strdup(qemuDomainGetManagedPRAlias()); } else { if (!(src->pr->mgralias = qemuDomainGetUnmanagedPRAlias(parentalias))) return -1; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 421a21818e..71947efa4e 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -1185,8 +1185,7 @@ qemuConnectURIProbe(char **uri) return 0; cfg = virQEMUDriverGetConfig(qemu_driver); - if (VIR_STRDUP(*uri, cfg->uri) < 0) - return -1; + *uri = g_strdup(cfg->uri); return 0; } @@ -7383,8 +7382,7 @@ static char *qemuConnectDomainXMLToNative(virConnectPtr conn, virMacAddr mac = net->mac; char *script = net->script; - if (VIR_STRDUP(model, virDomainNetGetModelString(net)) < 0) - goto cleanup; + model = g_strdup(virDomainNetGetModelString(net)); net->script = NULL; @@ -7761,9 +7759,8 @@ qemuDomainUndefineFlags(virDomainPtr dom, if (qemuDomainNVRAMPathFormat(cfg, vm->def, &nvram_path) < 0) goto endjob; } else { - if (vm->def->os.loader && - VIR_STRDUP(nvram_path, vm->def->os.loader->nvram) < 0) - goto endjob; + if (vm->def->os.loader) + nvram_path = g_strdup(vm->def->os.loader->nvram); } if (nvram_path && virFileExists(nvram_path)) { @@ -14639,10 +14636,7 @@ qemuDomainSnapshotCreateInactiveExternal(virQEMUDriverPtr driver, if (snapdisk->snapshot == VIR_DOMAIN_SNAPSHOT_LOCATION_EXTERNAL) { VIR_FREE(defdisk->src->path); - if (VIR_STRDUP(defdisk->src->path, snapdisk->src->path) < 0) { - /* we cannot rollback here in a sane way */ - goto cleanup; - } + defdisk->src->path = g_strdup(snapdisk->src->path); defdisk->src->format = snapdisk->src->format; if (virDomainSaveConfig(cfg->configDir, driver->caps, vm->def) < 0) @@ -15968,9 +15962,8 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain, current = virDomainSnapshotGetCurrent(vm->snapshots); if (current) { - if (!redefine && - VIR_STRDUP(snap->def->parent_name, current->def->name) < 0) - goto endjob; + if (!redefine) + snap->def->parent_name = g_strdup(current->def->name); } /* actually do the snapshot */ @@ -16902,11 +16895,8 @@ qemuDomainMomentReparentChildren(void *payload, VIR_FREE(moment->def->parent_name); - if (rep->parent->def && - VIR_STRDUP(moment->def->parent_name, rep->parent->def->name) < 0) { - rep->err = -1; - return 0; - } + if (rep->parent->def) + moment->def->parent_name = g_strdup(rep->parent->def->name); rep->err = rep->writeMetadata(rep->vm, moment, rep->caps, rep->xmlopt, rep->dir); @@ -18316,8 +18306,7 @@ qemuDomainBlockRebase(virDomainPtr dom, const char *path, const char *base, goto cleanup; dest->type = (flags & VIR_DOMAIN_BLOCK_REBASE_COPY_DEV) ? VIR_STORAGE_TYPE_BLOCK : VIR_STORAGE_TYPE_FILE; - if (VIR_STRDUP(dest->path, base) < 0) - goto cleanup; + dest->path = g_strdup(base); if (flags & VIR_DOMAIN_BLOCK_REBASE_COPY_RAW) dest->format = VIR_STORAGE_FILE_RAW; @@ -18896,9 +18885,8 @@ qemuDomainSetBlockIoTuneDefaults(virDomainBlockIoTuneInfoPtr newinfo, if (!(set_fields & QEMU_BLOCK_IOTUNE_SET_SIZE_IOPS)) newinfo->size_iops_sec = oldinfo->size_iops_sec; - if (!(set_fields & QEMU_BLOCK_IOTUNE_SET_GROUP_NAME) && - VIR_STRDUP(newinfo->group_name, oldinfo->group_name) < 0) - return -1; + if (!(set_fields & QEMU_BLOCK_IOTUNE_SET_GROUP_NAME)) + newinfo->group_name = g_strdup(oldinfo->group_name); /* The length field is handled a bit differently. If not defined/set, * QEMU will default these to 0 or 1 depending on whether something in @@ -19076,8 +19064,7 @@ qemuDomainSetBlockIoTune(virDomainPtr dom, /* NB: Cannot use macro since this is a value.s not a value.ul */ if (STREQ(param->field, VIR_DOMAIN_BLOCK_IOTUNE_GROUP_NAME)) { - if (VIR_STRDUP(info.group_name, param->value.s) < 0) - goto endjob; + info.group_name = g_strdup(param->value.s); set_fields |= QEMU_BLOCK_IOTUNE_SET_GROUP_NAME; if (virTypedParamsAddString(&eventParams, &eventNparams, &eventMaxparams, @@ -19374,8 +19361,7 @@ qemuDomainGetBlockIoTune(virDomainPtr dom, /* Group name needs to be copied since qemuMonitorGetBlockIoThrottle * allocates it as well */ - if (VIR_STRDUP(reply.group_name, disk->blkdeviotune.group_name) < 0) - goto endjob; + reply.group_name = g_strdup(disk->blkdeviotune.group_name); } #define BLOCK_IOTUNE_ASSIGN(name, var) \ @@ -19493,8 +19479,7 @@ qemuDomainGetDiskErrors(virDomainPtr dom, if (n == nerrors) break; - if (VIR_STRDUP(errors[n].disk, disk->dst) < 0) - goto endjob; + errors[n].disk = g_strdup(disk->dst); errors[n].error = info->io_status; n++; } @@ -20521,8 +20506,7 @@ qemuDomainGetResctrlMonData(virQEMUDriverPtr driver, if (!(res->vcpus = virBitmapFormat(domresmon->vcpus))) goto error; - if (VIR_STRDUP(res->name, virResctrlMonitorGetID(monitor)) < 0) - goto error; + res->name = g_strdup(virResctrlMonitorGetID(monitor)); if (virResctrlMonitorGetStats(monitor, (const char **)features, &res->stats, &res->nstats) < 0) @@ -21667,19 +21651,16 @@ qemuGetDHCPInterfaces(virDomainPtr dom, if (VIR_ALLOC_N(iface->addrs, iface->naddrs) < 0) goto error; - if (VIR_STRDUP(iface->name, vm->def->nets[i]->ifname) < 0) - goto error; + iface->name = g_strdup(vm->def->nets[i]->ifname); - if (VIR_STRDUP(iface->hwaddr, macaddr) < 0) - goto error; + iface->hwaddr = g_strdup(macaddr); } for (j = 0; j < n_leases; j++) { virNetworkDHCPLeasePtr lease = leases[j]; virDomainIPAddressPtr ip_addr = &iface->addrs[j]; - if (VIR_STRDUP(ip_addr->addr, lease->ipaddr) < 0) - goto error; + ip_addr->addr = g_strdup(lease->ipaddr); ip_addr->type = lease->type; ip_addr->prefix = lease->prefix; @@ -21739,18 +21720,15 @@ qemuARPGetInterfaces(virDomainObjPtr vm, if (VIR_ALLOC(iface) < 0) goto cleanup; - if (VIR_STRDUP(iface->name, vm->def->nets[i]->ifname) < 0) - goto cleanup; + iface->name = g_strdup(vm->def->nets[i]->ifname); - if (VIR_STRDUP(iface->hwaddr, macaddr) < 0) - goto cleanup; + iface->hwaddr = g_strdup(macaddr); if (VIR_ALLOC(iface->addrs) < 0) goto cleanup; iface->naddrs = 1; - if (VIR_STRDUP(iface->addrs->addr, entry.ipaddr) < 0) - goto cleanup; + iface->addrs->addr = g_strdup(entry.ipaddr); if (VIR_APPEND_ELEMENT(ifaces_ret, ifaces_count, iface) < 0) goto cleanup; @@ -21851,8 +21829,7 @@ qemuDomainRenameCallback(virDomainObjPtr vm, cfg = virQEMUDriverGetConfig(driver); - if (VIR_STRDUP(new_dom_name, new_name) < 0) - goto cleanup; + new_dom_name = g_strdup(new_name); if (!(new_dom_cfg_file = virDomainConfigFile(cfg->configDir, new_dom_name)) || @@ -22324,8 +22301,7 @@ qemuDomainSetBlockThreshold(virDomainPtr dom, goto endjob; } - if (VIR_STRDUP(nodename, src->nodestorage) < 0) - goto endjob; + nodename = g_strdup(src->nodestorage); qemuDomainObjEnterMonitor(driver, vm); rc = qemuMonitorSetBlockThreshold(priv->mon, nodename, threshold); diff --git a/src/qemu/qemu_firmware.c b/src/qemu/qemu_firmware.c index f614be6d14..670662fd4b 100644 --- a/src/qemu/qemu_firmware.c +++ b/src/qemu/qemu_firmware.c @@ -346,8 +346,7 @@ qemuFirmwareFlashFileParse(const char *path, return -1; } - if (VIR_STRDUP(flash->filename, filename) < 0) - return -1; + flash->filename = g_strdup(filename); if (!(format = virJSONValueObjectGetString(doc, "format"))) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -356,8 +355,7 @@ qemuFirmwareFlashFileParse(const char *path, return -1; } - if (VIR_STRDUP(flash->format, format) < 0) - return -1; + flash->format = g_strdup(format); return 0; } @@ -408,8 +406,7 @@ qemuFirmwareMappingKernelParse(const char *path, path); } - if (VIR_STRDUP(kernel->filename, filename) < 0) - return -1; + kernel->filename = g_strdup(filename); return 0; } @@ -428,8 +425,7 @@ qemuFirmwareMappingMemoryParse(const char *path, path); } - if (VIR_STRDUP(memory->filename, filename) < 0) - return -1; + memory->filename = g_strdup(filename); return 0; } @@ -547,8 +543,7 @@ qemuFirmwareTargetParse(const char *path, virJSONValuePtr machine = virJSONValueArrayGet(machines, j); g_autofree char *machineStr = NULL; - if (VIR_STRDUP(machineStr, virJSONValueGetString(machine)) < 0) - goto cleanup; + machineStr = g_strdup(virJSONValueGetString(machine)); VIR_APPEND_ELEMENT_INPLACE(t->machines, t->nmachines, machineStr); } @@ -1051,9 +1046,7 @@ qemuFirmwareEnableFeatures(virQEMUDriverPtr driver, } VIR_FREE(def->os.loader->path); - if (VIR_STRDUP(def->os.loader->path, - flash->executable.filename) < 0) - return -1; + def->os.loader->path = g_strdup(flash->executable.filename); if (STRNEQ(flash->nvram_template.format, "raw")) { virReportError(VIR_ERR_OPERATION_UNSUPPORTED, @@ -1063,9 +1056,7 @@ qemuFirmwareEnableFeatures(virQEMUDriverPtr driver, } VIR_FREE(def->os.loader->templt); - if (VIR_STRDUP(def->os.loader->templt, - flash->nvram_template.filename) < 0) - return -1; + def->os.loader->templt = g_strdup(flash->nvram_template.filename); if (qemuDomainNVRAMPathGenerate(cfg, def) < 0) return -1; @@ -1077,8 +1068,7 @@ qemuFirmwareEnableFeatures(virQEMUDriverPtr driver, case QEMU_FIRMWARE_DEVICE_KERNEL: VIR_FREE(def->os.kernel); - if (VIR_STRDUP(def->os.kernel, kernel->filename) < 0) - return -1; + def->os.kernel = g_strdup(kernel->filename); VIR_DEBUG("decided on kernel '%s'", def->os.kernel); @@ -1090,8 +1080,7 @@ qemuFirmwareEnableFeatures(virQEMUDriverPtr driver, return -1; def->os.loader->type = VIR_DOMAIN_LOADER_TYPE_ROM; - if (VIR_STRDUP(def->os.loader->path, memory->filename) < 0) - return -1; + def->os.loader->path = g_strdup(memory->filename); VIR_DEBUG("decided on loader '%s'", def->os.loader->path); @@ -1400,12 +1389,15 @@ qemuFirmwareGetSupported(const char *machine, break; } - if (j == *nfws && - (VIR_ALLOC(tmp) < 0 || - VIR_STRDUP(tmp->name, fwpath) < 0 || - VIR_STRDUP(tmp->nvram, nvrampath) < 0 || - VIR_APPEND_ELEMENT(*fws, *nfws, tmp) < 0)) - return -1; + if (j == *nfws) { + if (VIR_ALLOC(tmp) < 0) + return -1; + + tmp->name = g_strdup(fwpath); + tmp->nvram = g_strdup(nvrampath); + if (VIR_APPEND_ELEMENT(*fws, *nfws, tmp) < 0) + return -1; + } } } diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 5b42bbfd48..4da6457bdc 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -4243,8 +4243,7 @@ qemuDomainRemoveDiskDevice(virQEMUDriverPtr driver, if (blockdev) { - if (VIR_STRDUP(corAlias, diskPriv->nodeCopyOnRead) < 0) - goto cleanup; + corAlias = g_strdup(diskPriv->nodeCopyOnRead); if (diskPriv->blockjob) { /* the block job keeps reference to the disk chain */ @@ -4987,10 +4986,8 @@ qemuDomainRemoveDevice(virQEMUDriverPtr driver, * save the alias to use when sending a DEVICE_REMOVED event after * all other teardown is complete */ - if ((info = virDomainDeviceGetInfo(dev)) && - VIR_STRDUP(alias, info->alias) < 0) { - return -1; - } + if ((info = virDomainDeviceGetInfo(dev))) + alias = g_strdup(info->alias); info = NULL; switch ((virDomainDeviceType)dev->type) { diff --git a/src/qemu/qemu_interface.c b/src/qemu/qemu_interface.c index 6e3e634b30..70832e0c9a 100644 --- a/src/qemu/qemu_interface.c +++ b/src/qemu/qemu_interface.c @@ -457,8 +457,7 @@ qemuInterfaceEthernetConnect(virDomainDefPtr def, STRPREFIX(net->ifname, VIR_NET_GENERATED_TAP_PREFIX) || strchr(net->ifname, '%')) { VIR_FREE(net->ifname); - if (VIR_STRDUP(net->ifname, VIR_NET_GENERATED_TAP_PREFIX "%d") < 0) - goto cleanup; + net->ifname = g_strdup(VIR_NET_GENERATED_TAP_PREFIX "%d"); /* avoid exposing vnet%d in getXMLDesc or error outputs */ template_ifname = true; } @@ -563,8 +562,7 @@ qemuInterfaceBridgeConnect(virDomainDefPtr def, STRPREFIX(net->ifname, VIR_NET_GENERATED_TAP_PREFIX) || strchr(net->ifname, '%')) { VIR_FREE(net->ifname); - if (VIR_STRDUP(net->ifname, VIR_NET_GENERATED_TAP_PREFIX "%d") < 0) - goto cleanup; + net->ifname = g_strdup(VIR_NET_GENERATED_TAP_PREFIX "%d"); /* avoid exposing vnet%d in getXMLDesc or error outputs */ template_ifname = true; } diff --git a/src/qemu/qemu_interop_config.c b/src/qemu/qemu_interop_config.c index 7193d31dfd..d05ff56221 100644 --- a/src/qemu/qemu_interop_config.c +++ b/src/qemu/qemu_interop_config.c @@ -55,8 +55,7 @@ qemuBuildFileList(virHashTablePtr files, const char *dir) if (STRPREFIX(ent->d_name, ".")) continue; - if (VIR_STRDUP(filename, ent->d_name) < 0) - goto cleanup; + filename = g_strdup(ent->d_name); if (virAsprintf(&path, "%s/%s", dir, filename) < 0) goto cleanup; @@ -115,8 +114,7 @@ qemuInteropFetchConfigs(const char *name, * much sense to parse files in root's home directory. It * makes sense only for session daemon which runs under * regular user. */ - if (VIR_STRDUP(xdgConfig, getenv("XDG_CONFIG_HOME")) < 0) - return -1; + xdgConfig = g_strdup(getenv("XDG_CONFIG_HOME")); if (!xdgConfig) { g_autofree char *home = virGetUserDirectory(); diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c index fed95a285a..471cb1c5a6 100644 --- a/src/qemu/qemu_migration.c +++ b/src/qemu/qemu_migration.c @@ -192,8 +192,7 @@ qemuMigrationDstPrecreateDisk(virConnectPtr conn, return 0; } - if (VIR_STRDUP(basePath, disk->src->path) < 0) - goto cleanup; + basePath = g_strdup(disk->src->path); if (!(volName = strrchr(basePath, '/'))) { virReportError(VIR_ERR_INVALID_ARG, @@ -808,8 +807,7 @@ qemuMigrationSrcNBDStorageCopyBlockdev(virQEMUDriverPtr driver, if (!(copysrc->backingStore = virStorageSourceNew())) return -1; - if (VIR_STRDUP(copysrc->path, diskAlias) < 0) - return -1; + copysrc->path = g_strdup(diskAlias); if (VIR_ALLOC_N(copysrc->hosts, 1) < 0) return -1; @@ -817,11 +815,9 @@ qemuMigrationSrcNBDStorageCopyBlockdev(virQEMUDriverPtr driver, copysrc->nhosts = 1; copysrc->hosts->transport = VIR_STORAGE_NET_HOST_TRANS_TCP; copysrc->hosts->port = port; - if (VIR_STRDUP(copysrc->hosts->name, host) < 0) - return -1; + copysrc->hosts->name = g_strdup(host); - if (VIR_STRDUP(copysrc->tlsAlias, tlsAlias) < 0) - return -1; + copysrc->tlsAlias = g_strdup(tlsAlias); if (virAsprintf(©src->nodestorage, "migration-%s-storage", disk->dst) < 0 || virAsprintf(©src->nodeformat, "migration-%s-format", disk->dst) < 0) @@ -2218,8 +2214,7 @@ qemuMigrationDstPrepare(virDomainObjPtr vm, char *migrateFrom = NULL; if (tunnel) { - if (VIR_STRDUP(migrateFrom, "stdio") < 0) - goto cleanup; + migrateFrom = g_strdup("stdio"); } else { bool encloseAddress = false; bool hostIPv6Capable = false; @@ -2434,8 +2429,7 @@ qemuMigrationDstPrepareAny(virQEMUDriverPtr driver, *def = NULL; priv = vm->privateData; - if (VIR_STRDUP(priv->origname, origname) < 0) - goto cleanup; + priv->origname = g_strdup(origname); if (taint_hook) { /* Domain XML has been altered by a hook script. */ @@ -2780,8 +2774,7 @@ qemuMigrationDstPrepareDirect(virQEMUDriverPtr driver, if (virSocketAddrNumericFamily(migrateHost) == AF_INET6) encloseAddress = true; - if (VIR_STRDUP(hostname, migrateHost) < 0) - goto cleanup; + hostname = g_strdup(migrateHost); } else { if ((hostname = virGetHostname()) == NULL) goto cleanup; @@ -2902,10 +2895,7 @@ qemuMigrationAnyPrepareDef(virQEMUDriverPtr driver, if (dname) { name = def->name; - if (VIR_STRDUP(def->name, dname) < 0) { - virDomainDefFree(def); - def = NULL; - } + def->name = g_strdup(dname); } cleanup: diff --git a/src/qemu/qemu_migration_cookie.c b/src/qemu/qemu_migration_cookie.c index 244ad4fdf3..f625c7086b 100644 --- a/src/qemu/qemu_migration_cookie.c +++ b/src/qemu/qemu_migration_cookie.c @@ -214,8 +214,7 @@ qemuMigrationCookieGraphicsSpiceAlloc(virQEMUDriverPtr driver, !(mig->tlsSubject = qemuDomainExtractTLSSubject(cfg->spiceTLSx509certdir))) goto error; - if (VIR_STRDUP(mig->listen, listenAddr) < 0) - goto error; + mig->listen = g_strdup(listenAddr); virObjectUnref(cfg); return mig; @@ -293,8 +292,7 @@ qemuMigrationCookieNew(const virDomainDef *def, name = origname; else name = def->name; - if (VIR_STRDUP(mig->name, name) < 0) - goto error; + mig->name = g_strdup(name); memcpy(mig->uuid, def->uuid, VIR_UUID_BUFLEN); if (!(mig->localHostname = virGetHostname())) @@ -380,17 +378,13 @@ qemuMigrationCookieAddLockstate(qemuMigrationCookiePtr mig, } if (virDomainObjGetState(dom, NULL) == VIR_DOMAIN_PAUSED) { - if (VIR_STRDUP(mig->lockState, priv->lockState) < 0) - return -1; + mig->lockState = g_strdup(priv->lockState); } else { if (virDomainLockProcessInquire(driver->lockManager, dom, &mig->lockState) < 0) return -1; } - if (VIR_STRDUP(mig->lockDriver, virLockManagerPluginGetName(driver->lockManager)) < 0) { - VIR_FREE(mig->lockState); - return -1; - } + mig->lockDriver = g_strdup(virLockManagerPluginGetName(driver->lockManager)); mig->flags |= QEMU_MIGRATION_COOKIE_LOCKSTATE; mig->flagsMandatory |= QEMU_MIGRATION_COOKIE_LOCKSTATE; @@ -498,9 +492,7 @@ qemuMigrationCookieAddNBD(qemuMigrationCookiePtr mig, !(entry = virHashLookup(stats, disk->info.alias))) continue; - if (VIR_STRDUP(mig->nbd->disks[mig->nbd->ndisks].target, - disk->dst) < 0) - goto cleanup; + mig->nbd->disks[mig->nbd->ndisks].target = g_strdup(disk->dst); mig->nbd->disks[mig->nbd->ndisks].capacity = entry->capacity; mig->nbd->ndisks++; } @@ -1516,8 +1508,7 @@ qemuMigrationEatCookie(virQEMUDriverPtr driver, mig->persistent && STRNEQ(def->name, mig->persistent->name)) { VIR_FREE(mig->persistent->name); - if (VIR_STRDUP(mig->persistent->name, def->name) < 0) - goto error; + mig->persistent->name = g_strdup(def->name); } if (mig->flags & QEMU_MIGRATION_COOKIE_LOCKSTATE) { diff --git a/src/qemu/qemu_migration_params.c b/src/qemu/qemu_migration_params.c index 65f533e451..dca12033c0 100644 --- a/src/qemu/qemu_migration_params.c +++ b/src/qemu/qemu_migration_params.c @@ -658,8 +658,7 @@ qemuMigrationParamsFromJSON(virJSONValuePtr params) case QEMU_MIGRATION_PARAM_TYPE_STRING: if ((str = virJSONValueObjectGetString(params, name))) { - if (VIR_STRDUP(pv->value.s, str) < 0) - goto error; + pv->value.s = g_strdup(str); pv->set = true; } break; @@ -667,10 +666,6 @@ qemuMigrationParamsFromJSON(virJSONValuePtr params) } return migParams; - - error: - qemuMigrationParamsFree(migParams); - return NULL; } @@ -875,8 +870,7 @@ qemuMigrationParamsSetString(qemuMigrationParamsPtr migParams, if (qemuMigrationParamsCheckType(param, QEMU_MIGRATION_PARAM_TYPE_STRING) < 0) return -1; - if (VIR_STRDUP(migParams->params[param].value.s, value) < 0) - return -1; + migParams->params[param].value.s = g_strdup(value); migParams->params[param].set = true; diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 86d3800108..7891d7e4c1 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -2987,8 +2987,8 @@ qemuMonitorAddObject(qemuMonitorPtr mon, goto cleanup; } - if (alias && VIR_STRDUP(tmp, id) < 0) - goto cleanup; + if (alias) + tmp = g_strdup(id); ret = qemuMonitorJSONAddObject(mon, *props); *props = NULL; @@ -3635,15 +3635,13 @@ qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig) if (VIR_ALLOC_N(copy->props, orig->nprops) < 0) goto error; - if (VIR_STRDUP(copy->name, orig->name) < 0) - goto error; + copy->name = g_strdup(orig->name); copy->migratability = orig->migratability; copy->nprops = orig->nprops; for (i = 0; i < orig->nprops; i++) { - if (VIR_STRDUP(copy->props[i].name, orig->props[i].name) < 0) - goto error; + copy->props[i].name = g_strdup(orig->props[i].name); copy->props[i].migratable = orig->props[i].migratable; copy->props[i].type = orig->props[i].type; @@ -3653,9 +3651,7 @@ qemuMonitorCPUModelInfoCopy(const qemuMonitorCPUModelInfo *orig) break; case QEMU_MONITOR_CPU_PROPERTY_STRING: - if (VIR_STRDUP(copy->props[i].value.string, - orig->props[i].value.string) < 0) - goto error; + copy->props[i].value.string = g_strdup(orig->props[i].value.string); break; case QEMU_MONITOR_CPU_PROPERTY_NUMBER: diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index 602a0380d7..58f84f1b96 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -823,8 +823,7 @@ qemuMonitorJSONGuestPanicExtractInfoS390(virJSONValuePtr data) ret->data.s390.psw_mask = psw_mask; ret->data.s390.psw_addr = psw_addr; - if (VIR_STRDUP(ret->data.s390.reason, reason) < 0) - goto error; + ret->data.s390.reason = g_strdup(reason); return ret; @@ -1586,8 +1585,7 @@ qemuMonitorJSONHumanCommand(qemuMonitorPtr mon, const char *data; data = virJSONValueGetString(obj); - if (VIR_STRDUP(*reply_str, NULLSTR_EMPTY(data)) < 0) - goto cleanup; + *reply_str = g_strdup(NULLSTR_EMPTY(data)); } ret = 0; @@ -1932,8 +1930,7 @@ qemuMonitorJSONExtractCPUInfo(virJSONValuePtr data, cpus[i].qemu_id = cpuid; cpus[i].tid = thread; cpus[i].halted = halted; - if (VIR_STRDUP(cpus[i].qom_path, qom_path) < 0) - goto cleanup; + cpus[i].qom_path = g_strdup(qom_path); /* process optional architecture-specific data */ if (STREQ_NULLABLE(arch, "s390") || STREQ_NULLABLE(arch, "s390x")) @@ -2427,9 +2424,8 @@ qemuMonitorJSONBlockInfoAdd(virHashTablePtr table, *tmp = *info; tmp->nodename = NULL; - if (info->nodename && - VIR_STRDUP(tmp->nodename, info->nodename) < 0) - goto cleanup; + if (info->nodename) + tmp->nodename = g_strdup(info->nodename); if (virHashAddEntry(table, entryname, tmp) < 0) goto cleanup; @@ -3384,8 +3380,8 @@ qemuMonitorJSONGetMigrationStatsReply(virJSONValuePtr reply, case QEMU_MONITOR_MIGRATION_STATUS_ERROR: if (error) { tmp = virJSONValueObjectGetString(ret, "error-desc"); - if (tmp && VIR_STRDUP(*error, tmp) < 0) - return -1; + if (tmp) + *error = g_strdup(tmp); } break; @@ -3921,8 +3917,7 @@ qemuMonitorJSONQueryRxFilterParse(virJSONValuePtr msg, "in query-rx-filter response")); goto cleanup; } - if (VIR_STRDUP(fil->name, tmp) < 0) - goto cleanup; + fil->name = g_strdup(tmp); if ((!(tmp = virJSONValueObjectGetString(entry, "main-mac"))) || virMacAddrParse(tmp, &fil->mac) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -4151,9 +4146,8 @@ qemuMonitorJSONExtractChardevInfo(virJSONValuePtr reply, if (VIR_ALLOC(entry) < 0) goto cleanup; - if (STRPREFIX(type, "pty:") && - VIR_STRDUP(entry->ptyPath, type + strlen("pty:")) < 0) - goto cleanup; + if (STRPREFIX(type, "pty:")) + entry->ptyPath = g_strdup(type + strlen("pty:")); if (virJSONValueObjectGetBoolean(chardev, "frontend-open", &connected) == 0) { if (connected) @@ -4544,8 +4538,7 @@ qemuMonitorJSONDiskNameLookupOne(virJSONValuePtr image, return qemuMonitorJSONDiskNameLookupOne(backing, top->backingStore, target); } - if (VIR_STRDUP(ret, virJSONValueObjectGetString(image, "filename")) < 0) - return NULL; + ret = g_strdup(virJSONValueObjectGetString(image, "filename")); /* Sanity check - the name qemu gave us should resolve to the same file tracked by our target description. */ if (virStorageSourceIsLocalStorage(target) && @@ -5196,9 +5189,7 @@ qemuMonitorJSONBlockIoThrottleInfo(virJSONValuePtr io_throttle, GET_THROTTLE_STATS_OPTIONAL("iops_wr_max", write_iops_sec_max); GET_THROTTLE_STATS_OPTIONAL("iops_size", size_iops_sec); - if (VIR_STRDUP(reply->group_name, - virJSONValueObjectGetString(inserted, "group")) < 0) - goto cleanup; + reply->group_name = g_strdup(virJSONValueObjectGetString(inserted, "group")); GET_THROTTLE_STATS_OPTIONAL("bps_max_length", total_bytes_sec_max_length); GET_THROTTLE_STATS_OPTIONAL("bps_rd_max_length", read_bytes_sec_max_length); @@ -5418,8 +5409,7 @@ int qemuMonitorJSONGetVersion(qemuMonitorPtr mon, _("query-version reply was missing 'package' version")); goto cleanup; } - if (VIR_STRDUP(*package, tmp) < 0) - goto cleanup; + *package = g_strdup(tmp); } ret = 0; @@ -5476,8 +5466,7 @@ int qemuMonitorJSONGetMachines(qemuMonitorPtr mon, goto cleanup; } - if (VIR_STRDUP(info->name, tmp) < 0) - goto cleanup; + info->name = g_strdup(tmp); if (virJSONValueObjectHasKey(child, "is-default") && virJSONValueObjectGetBoolean(child, "is-default", &info->isDefault) < 0) { @@ -5492,8 +5481,7 @@ int qemuMonitorJSONGetMachines(qemuMonitorPtr mon, _("query-machines reply has malformed 'alias' data")); goto cleanup; } - if (VIR_STRDUP(info->alias, tmp) < 0) - goto cleanup; + info->alias = g_strdup(tmp); } if (virJSONValueObjectHasKey(child, "cpu-max") && virJSONValueObjectGetNumberUint(child, "cpu-max", &info->maxCpus) < 0) { @@ -5576,8 +5564,7 @@ qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon, goto cleanup; } - if (VIR_STRDUP(cpu->name, tmp) < 0) - goto cleanup; + cpu->name = g_strdup(tmp); if (virJSONValueObjectHasKey(child, "unavailable-features")) { virJSONValuePtr blockers; @@ -5614,8 +5601,7 @@ qemuMonitorJSONGetCPUDefinitions(qemuMonitorPtr mon, goto cleanup; } - if (VIR_STRDUP(cpu->blockers[j], virJSONValueGetString(blocker)) < 0) - goto cleanup; + cpu->blockers[j] = g_strdup(virJSONValueGetString(blocker)); } } } @@ -5653,8 +5639,7 @@ qemuMonitorJSONParseCPUModelProperty(const char *key, switch ((virJSONType)virJSONValueGetType(value)) { case VIR_JSON_TYPE_STRING: - if (VIR_STRDUP(prop->value.string, virJSONValueGetString(value)) < 0) - return -1; + prop->value.string = g_strdup(virJSONValueGetString(value)); prop->type = QEMU_MONITOR_CPU_PROPERTY_STRING; break; @@ -5677,8 +5662,7 @@ qemuMonitorJSONParseCPUModelProperty(const char *key, } machine_model->nprops++; - if (VIR_STRDUP(prop->name, key) < 0) - return -1; + prop->name = g_strdup(key); return 0; } @@ -5776,8 +5760,7 @@ qemuMonitorJSONParseCPUModel(const char *cpu_name, if (VIR_ALLOC(machine_model) < 0) goto cleanup; - if (VIR_STRDUP(machine_model->name, cpu_name) < 0) - goto cleanup; + machine_model->name = g_strdup(cpu_name); if (cpu_props) { size_t nprops = virJSONValueObjectKeysNumber(cpu_props); @@ -6001,8 +5984,7 @@ int qemuMonitorJSONGetCommands(qemuMonitorPtr mon, goto cleanup; } - if (VIR_STRDUP(commandlist[i], tmp) < 0) - goto cleanup; + commandlist[i] = g_strdup(tmp); } ret = n; @@ -6062,8 +6044,7 @@ int qemuMonitorJSONGetEvents(qemuMonitorPtr mon, goto cleanup; } - if (VIR_STRDUP(eventlist[i], tmp) < 0) - goto cleanup; + eventlist[i] = g_strdup(tmp); } ret = n; @@ -6179,8 +6160,7 @@ qemuMonitorJSONGetCommandLineOptionParameters(qemuMonitorPtr mon, goto cleanup; } - if (VIR_STRDUP(paramlist[i], tmp) < 0) - goto cleanup; + paramlist[i] = g_strdup(tmp); } ret = n; @@ -6283,8 +6263,7 @@ int qemuMonitorJSONGetObjectTypes(qemuMonitorPtr mon, goto cleanup; } - if (VIR_STRDUP(typelist[i], tmp) < 0) - goto cleanup; + typelist[i] = g_strdup(tmp); } ret = n; @@ -6347,8 +6326,7 @@ int qemuMonitorJSONGetObjectListPaths(qemuMonitorPtr mon, goto cleanup; } - if (VIR_STRDUP(info->name, tmp) < 0) - goto cleanup; + info->name = g_strdup(tmp); if (virJSONValueObjectHasKey(child, "type")) { if (!(tmp = virJSONValueObjectGetString(child, "type"))) { @@ -6356,8 +6334,7 @@ int qemuMonitorJSONGetObjectListPaths(qemuMonitorPtr mon, _("qom-list reply has malformed 'type' data")); goto cleanup; } - if (VIR_STRDUP(info->type, tmp) < 0) - goto cleanup; + info->type = g_strdup(tmp); } } @@ -6435,8 +6412,8 @@ int qemuMonitorJSONGetObjectProperty(qemuMonitorPtr mon, break; case QEMU_MONITOR_OBJECT_PROPERTY_STRING: tmp = virJSONValueGetString(data); - if (tmp && VIR_STRDUP(prop->val.str, tmp) < 0) - goto cleanup; + if (tmp) + prop->val.str = g_strdup(tmp); if (tmp) ret = 0; break; @@ -6505,8 +6482,7 @@ qemuMonitorJSONGetStringListProperty(qemuMonitorPtr mon, return -1; } - if (VIR_STRDUP(list[i], virJSONValueGetString(item)) < 0) - return -1; + list[i] = g_strdup(virJSONValueGetString(item)); } *strList = g_steal_pointer(&list); @@ -6617,8 +6593,7 @@ qemuMonitorJSONParsePropsList(virJSONValuePtr cmd, goto cleanup; } - if (VIR_STRDUP(proplist[count++], tmp) < 0) - goto cleanup; + proplist[count++] = g_strdup(tmp); } ret = count; @@ -6780,8 +6755,7 @@ qemuMonitorJSONGetMigrationCapabilities(qemuMonitorPtr mon, goto cleanup; } - if (VIR_STRDUP(list[i], name) < 1) - goto cleanup; + list[i] = g_strdup(name); } ret = n; @@ -7014,11 +6988,9 @@ qemuMonitorJSONGetSEVCapabilities(qemuMonitorPtr mon, if (VIR_ALLOC(capability) < 0) goto cleanup; - if (VIR_STRDUP(capability->pdh, pdh) < 0) - goto cleanup; + capability->pdh = g_strdup(pdh); - if (VIR_STRDUP(capability->cert_chain, cert_chain) < 0) - goto cleanup; + capability->cert_chain = g_strdup(cert_chain); capability->cbitpos = cbitpos; capability->reduced_phys_bits = reduced_phys_bits; @@ -7224,8 +7196,7 @@ qemuMonitorJSONGetStringArray(qemuMonitorPtr mon, const char *qmpCmd, goto cleanup; } - if (VIR_STRDUP(list[i], tmp) < 0) - goto cleanup; + list[i] = g_strdup(tmp); } ret = n; @@ -7458,8 +7429,7 @@ qemuMonitorJSONAttachCharDev(qemuMonitorPtr mon, goto cleanup; } - if (VIR_STRDUP(chr->data.file.path, path) < 0) - goto cleanup; + chr->data.file.path = g_strdup(path); } ret = 0; @@ -8465,8 +8435,7 @@ qemuMonitorJSONProcessHotpluggableCpusReply(virJSONValuePtr vcpu, return -1; } - if (VIR_STRDUP(entry->type, tmp) < 0) - return -1; + entry->type = g_strdup(tmp); if (virJSONValueObjectGetNumberUint(vcpu, "vcpus-count", &entry->vcpus) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, "%s", @@ -8503,14 +8472,11 @@ qemuMonitorJSONProcessHotpluggableCpusReply(virJSONValuePtr vcpu, /* qom path is not present unless the vCPU is online */ if ((tmp = virJSONValueObjectGetString(vcpu, "qom-path"))) { - if (VIR_STRDUP(entry->qom_path, tmp) < 0) - return -1; + entry->qom_path = g_strdup(tmp); /* alias is the part after last slash having a "vcpu" prefix */ - if ((tmp = strrchr(tmp, '/')) && STRPREFIX(tmp + 1, "vcpu")) { - if (VIR_STRDUP(entry->alias, tmp + 1) < 0) - return -1; - } + if ((tmp = strrchr(tmp, '/')) && STRPREFIX(tmp + 1, "vcpu")) + entry->alias = g_strdup(tmp + 1); } return 0; @@ -8921,8 +8887,7 @@ qemuMonitorJSONGetSEVMeasurement(qemuMonitorPtr mon) if (!(tmp = virJSONValueObjectGetString(data, "data"))) goto cleanup; - if (VIR_STRDUP(measurement, tmp) < 0) - goto cleanup; + measurement = g_strdup(tmp); cleanup: virJSONValueFree(cmd); @@ -9309,9 +9274,8 @@ qemuMonitorJSONGetJobInfoOne(virJSONValuePtr data) job->status = tmp; - if (VIR_STRDUP(job->id, id) < 0 || - VIR_STRDUP(job->error, errmsg) < 0) - return NULL; + job->id = g_strdup(id); + job->error = g_strdup(errmsg); ret = g_steal_pointer(&job); return ret; diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index 843e852591..7e0dc26658 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -967,8 +967,7 @@ qemuProcessHandleBlockJob(qemuMonitorPtr mon G_GNUC_UNUSED, goto cleanup; processEvent->eventType = QEMU_PROCESS_EVENT_BLOCK_JOB; - if (VIR_STRDUP(data, diskAlias) < 0) - goto cleanup; + data = g_strdup(diskAlias); processEvent->data = data; processEvent->vm = virObjectRef(vm); processEvent->action = type; @@ -1076,16 +1075,14 @@ qemuProcessHandleGraphics(qemuMonitorPtr mon G_GNUC_UNUSED, if (VIR_ALLOC(localAddr) < 0) goto error; localAddr->family = localFamily; - if (VIR_STRDUP(localAddr->service, localService) < 0 || - VIR_STRDUP(localAddr->node, localNode) < 0) - goto error; + localAddr->service = g_strdup(localService); + localAddr->node = g_strdup(localNode); if (VIR_ALLOC(remoteAddr) < 0) goto error; remoteAddr->family = remoteFamily; - if (VIR_STRDUP(remoteAddr->service, remoteService) < 0 || - VIR_STRDUP(remoteAddr->node, remoteNode) < 0) - goto error; + remoteAddr->service = g_strdup(remoteService); + remoteAddr->node = g_strdup(remoteNode); if (VIR_ALLOC(subject) < 0) goto error; @@ -1093,17 +1090,15 @@ qemuProcessHandleGraphics(qemuMonitorPtr mon G_GNUC_UNUSED, if (VIR_REALLOC_N(subject->identities, subject->nidentity+1) < 0) goto error; subject->nidentity++; - if (VIR_STRDUP(subject->identities[subject->nidentity-1].type, "x509dname") < 0 || - VIR_STRDUP(subject->identities[subject->nidentity-1].name, x509dname) < 0) - goto error; + subject->identities[subject->nidentity - 1].type = g_strdup("x509dname"); + subject->identities[subject->nidentity - 1].name = g_strdup(x509dname); } if (saslUsername) { if (VIR_REALLOC_N(subject->identities, subject->nidentity+1) < 0) goto error; subject->nidentity++; - if (VIR_STRDUP(subject->identities[subject->nidentity-1].type, "saslUsername") < 0 || - VIR_STRDUP(subject->identities[subject->nidentity-1].name, saslUsername) < 0) - goto error; + subject->identities[subject->nidentity - 1].type = g_strdup("saslUsername"); + subject->identities[subject->nidentity - 1].name = g_strdup(saslUsername); } virObjectLock(vm); @@ -1385,8 +1380,7 @@ qemuProcessHandleDeviceDeleted(qemuMonitorPtr mon G_GNUC_UNUSED, goto error; processEvent->eventType = QEMU_PROCESS_EVENT_DEVICE_DELETED; - if (VIR_STRDUP(data, devAlias) < 0) - goto error; + data = g_strdup(devAlias); processEvent->data = data; processEvent->vm = virObjectRef(vm); @@ -1559,8 +1553,7 @@ qemuProcessHandleNicRxFilterChanged(qemuMonitorPtr mon G_GNUC_UNUSED, goto error; processEvent->eventType = QEMU_PROCESS_EVENT_NIC_RX_FILTER_CHANGED; - if (VIR_STRDUP(data, devAlias) < 0) - goto error; + data = g_strdup(devAlias); processEvent->data = data; processEvent->vm = virObjectRef(vm); @@ -1598,8 +1591,7 @@ qemuProcessHandleSerialChanged(qemuMonitorPtr mon G_GNUC_UNUSED, goto error; processEvent->eventType = QEMU_PROCESS_EVENT_SERIAL_CHANGED; - if (VIR_STRDUP(data, devAlias) < 0) - goto error; + data = g_strdup(devAlias); processEvent->data = data; processEvent->action = connected; processEvent->vm = virObjectRef(vm); @@ -1839,10 +1831,11 @@ qemuProcessHandleRdmaGidStatusChanged(qemuMonitorPtr mon G_GNUC_UNUSED, VIR_DEBUG("netdev=%s,gid_status=%d,subnet_prefix=0x%llx,interface_id=0x%llx", netdev, gid_status, subnet_prefix, interface_id); - if (VIR_ALLOC(info) < 0 || - VIR_STRDUP(info->netdev, netdev) < 0) + if (VIR_ALLOC(info) < 0) goto cleanup; + info->netdev = g_strdup(netdev); + info->gid_status = gid_status; info->subnet_prefix = subnet_prefix; info->interface_id = interface_id; @@ -2133,8 +2126,7 @@ qemuProcessLookupPTYs(virDomainChrDefPtr *devices, } VIR_FREE(chr->source->data.file.path); - if (VIR_STRDUP(chr->source->data.file.path, entry->ptyPath) < 0) - goto cleanup; + chr->source->data.file.path = g_strdup(entry->ptyPath); } } @@ -4586,8 +4578,7 @@ qemuProcessIncomingDefNew(virQEMUCapsPtr qemuCaps, if (VIR_ALLOC(inc) < 0) return NULL; - if (VIR_STRDUP(inc->address, listenAddress) < 0) - goto error; + inc->address = g_strdup(listenAddress); inc->launchURI = qemuMigrationDstGetURI(migrateFrom, fd); if (!inc->launchURI) @@ -4595,8 +4586,7 @@ qemuProcessIncomingDefNew(virQEMUCapsPtr qemuCaps, if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_INCOMING_DEFER)) { inc->deferredURI = inc->launchURI; - if (VIR_STRDUP(inc->launchURI, "defer") < 0) - goto error; + inc->launchURI = g_strdup("defer"); } inc->fd = fd; @@ -4865,8 +4855,7 @@ qemuProcessGraphicsSetupNetworkAddress(virDomainGraphicsListenDefPtr glisten, /* TODO: reject configuration without network specified for network listen */ if (!glisten->network) { - if (VIR_STRDUP(glisten->address, listenAddr) < 0) - return -1; + glisten->address = g_strdup(listenAddr); return 0; } @@ -4933,8 +4922,7 @@ qemuProcessGraphicsSetupListen(virQEMUDriverPtr driver, glisten->fromConfig = true; glisten->type = VIR_DOMAIN_GRAPHICS_LISTEN_TYPE_SOCKET; } else if (listenAddr) { - if (VIR_STRDUP(glisten->address, listenAddr) < 0) - goto cleanup; + glisten->address = g_strdup(listenAddr); glisten->fromConfig = true; } } @@ -8477,9 +8465,8 @@ qemuProcessQMPNew(const char *binary, if (VIR_ALLOC(proc) < 0) goto cleanup; - if (VIR_STRDUP(proc->binary, binary) < 0 || - VIR_STRDUP(proc->libDir, libDir) < 0) - goto cleanup; + proc->binary = g_strdup(binary); + proc->libDir = g_strdup(libDir); proc->runUid = runUid; proc->runGid = runGid; diff --git a/src/qemu/qemu_vhost_user.c b/src/qemu/qemu_vhost_user.c index dfef6f20a3..789d29ce43 100644 --- a/src/qemu/qemu_vhost_user.c +++ b/src/qemu/qemu_vhost_user.c @@ -172,8 +172,7 @@ qemuVhostUserBinaryParse(const char *path, VIR_DEBUG("vhost-user description path '%s' binary : %s", path, binary); - if (VIR_STRDUP(vu->binary, binary) < 0) - return -1; + vu->binary = g_strdup(binary); return 0; } @@ -389,8 +388,7 @@ qemuVhostUserFillDomainGPU(virQEMUDriverPtr driver, goto end; VIR_FREE(video->driver->vhost_user_binary); - if (VIR_STRDUP(video->driver->vhost_user_binary, vu->binary) < 0) - goto end; + video->driver->vhost_user_binary = g_strdup(vu->binary); break; } -- 2.21.0 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list