提交 652cdbe3 编写于 作者: J Ján Tomko

bhyve: use g_strdup instead of VIR_STRDUP

Replace all occurrences of
  if (VIR_STRDUP(a, b) < 0)
     /* effectively dead code */
with:
  a = g_strdup(b);
Signed-off-by: NJán Tomko <jtomko@redhat.com>
Reviewed-by: NMichal Privoznik <mprivozn@redhat.com>
上级 7b48bb8c
......@@ -58,12 +58,10 @@ bhyveBuildNetArgStr(virConnectPtr conn,
virDomainNetType actualType = virDomainNetGetActualType(net);
if (net->model == VIR_DOMAIN_NET_MODEL_VIRTIO) {
if (VIR_STRDUP(nic_model, "virtio-net") < 0)
return -1;
nic_model = g_strdup("virtio-net");
} else if (net->model == VIR_DOMAIN_NET_MODEL_E1000) {
if ((bhyveDriverGetCaps(conn) & BHYVE_CAP_NET_E1000) != 0) {
if (VIR_STRDUP(nic_model, "e1000") < 0)
return -1;
nic_model = g_strdup("e1000");
} else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("NIC model 'e1000' is not supported "
......@@ -77,8 +75,7 @@ bhyveBuildNetArgStr(virConnectPtr conn,
}
if (actualType == VIR_DOMAIN_NET_TYPE_BRIDGE) {
if (VIR_STRDUP(brname, virDomainNetGetActualBridgeName(net)) < 0)
goto cleanup;
brname = g_strdup(virDomainNetGetActualBridgeName(net));
} else {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
_("Network type %d is not supported"),
......@@ -90,8 +87,7 @@ bhyveBuildNetArgStr(virConnectPtr conn,
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");
}
if (!dryRun) {
......@@ -117,8 +113,7 @@ bhyveBuildNetArgStr(virConnectPtr conn,
if (virNetDevSetOnline(net->ifname, true) != 0)
goto cleanup;
} else {
if (VIR_STRDUP(realifname, "tap0") < 0)
goto cleanup;
realifname = g_strdup("tap0");
}
......
......@@ -56,8 +56,7 @@ virBhyveDriverConfigNew(void)
if (!(cfg = virObjectNew(virBhyveDriverConfigClass)))
return NULL;
if (VIR_STRDUP(cfg->firmwareDir, DATADIR "/uefi-firmware") < 0)
goto error;
cfg->firmwareDir = g_strdup(DATADIR "/uefi-firmware");
return cfg;
......
......@@ -470,8 +470,7 @@ bhyveDomainGetOSType(virDomainPtr dom)
if (virDomainGetOSTypeEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
if (VIR_STRDUP(ret, virDomainOSTypeToString(vm->def->os.type)) < 0)
goto cleanup;
ret = g_strdup(virDomainOSTypeToString(vm->def->os.type));
cleanup:
virDomainObjEndAPI(&vm);
......
......@@ -299,16 +299,8 @@ bhyveParseBhyveLPCArg(virDomainDefPtr def,
goto error;
}
if (VIR_STRDUP(chr->source->data.nmdm.master, param) < 0) {
virDomainChrDefFree(chr);
goto error;
}
if (VIR_STRDUP(chr->source->data.nmdm.slave, chr->source->data.file.path)
< 0) {
virDomainChrDefFree(chr);
goto error;
}
chr->source->data.nmdm.master = g_strdup(param);
chr->source->data.nmdm.slave = g_strdup(chr->source->data.file.path);
/* If the last character of the master is 'A', the slave will be 'B'
* and vice versa */
......@@ -456,13 +448,11 @@ bhyveParsePCIDisk(virDomainDefPtr def,
if (bus == VIR_DOMAIN_DISK_BUS_VIRTIO) {
idx = *nvirtiodisk;
*nvirtiodisk += 1;
if (VIR_STRDUP(disk->dst, "vda") < 0)
goto error;
disk->dst = g_strdup("vda");
} else if (bus == VIR_DOMAIN_DISK_BUS_SATA) {
idx = *nahcidisk;
*nahcidisk += 1;
if (VIR_STRDUP(disk->dst, "sda") < 0)
goto error;
disk->dst = g_strdup("sda");
}
if (idx > 'z' - 'a') {
......@@ -507,8 +497,7 @@ bhyveParsePCINet(virDomainDefPtr def,
* guess the actual bridge name from the command line,
* try to come up with some reasonable defaults */
net->type = VIR_DOMAIN_NET_TYPE_BRIDGE;
if (VIR_STRDUP(net->data.bridge.brname, "virbr0") < 0)
goto error;
net->data.bridge.brname = g_strdup("virbr0");
net->model = model;
net->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI;
......@@ -738,8 +727,7 @@ bhyveParseBhyveCommandLine(virDomainDefPtr def,
}
if (def->name == NULL) {
if (VIR_STRDUP(def->name, argv[argc]) < 0)
goto error;
def->name = g_strdup(argv[argc]);
} else if (STRNEQ(def->name, argv[argc])) {
/* the vm name of the loader and the bhyverun command differ, throw an
* error here */
......@@ -819,15 +807,12 @@ bhyveParseBhyveLoadCommandLine(virDomainDefPtr def,
if (arguments != 3) {
/* Set os.bootloader since virDomainDefFormatInternal will only format
* the bootloader arguments if os->bootloader is set. */
if (VIR_STRDUP(def->os.bootloader, argv[0]) < 0)
goto error;
def->os.bootloader = g_strdup(argv[0]);
def->os.bootloaderArgs = virStringListJoin((const char**) &argv[1], " ");
}
if (def->name == NULL) {
if (VIR_STRDUP(def->name, argv[argc]) < 0)
goto error;
def->name = g_strdup(argv[argc]);
} else if (STRNEQ(def->name, argv[argc])) {
/* the vm name of the loader and the bhyverun command differ, throw an
* error here */
......@@ -849,9 +834,7 @@ bhyveParseCustomLoaderCommandLine(virDomainDefPtr def,
if (!argv)
goto error;
if (VIR_STRDUP(def->os.bootloader, argv[0]) < 0)
goto error;
def->os.bootloader = g_strdup(argv[0]);
def->os.bootloaderArgs = virStringListJoin((const char**) &argv[1], " ");
return 0;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册