Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
src/qemu/qemu_alias.c | 16 ++++++++++++++++
src/qemu/qemu_alias.h | 3 +++
src/qemu/qemu_command.c | 2 +-
src/qemu/qemu_hotplug.c | 14 +++++++-------
4 files changed, 27 insertions(+), 8 deletions(-)
diff --git a/src/qemu/qemu_alias.c b/src/qemu/qemu_alias.c
index cc83fec..9737158 100644
--- a/src/qemu/qemu_alias.c
+++ b/src/qemu/qemu_alias.c
@@ -606,3 +606,19 @@ qemuAliasTLSObjFromChardevAlias(const char *chardev_alias)
return ret;
}
+
+
+/* qemuAliasChardevFromDevAlias:
+ * @devAlias: pointer do device alias
+ *
+ * Generate and return a string to be used as chardev alias.
+ */
+char *
+qemuAliasChardevFromDevAlias(const char *devAlias)
+{
+ char *ret;
+
+ ignore_value(virAsprintf(&ret, "char%s", devAlias));
+
+ return ret;
+}
diff --git a/src/qemu/qemu_alias.h b/src/qemu/qemu_alias.h
index 11d9fde..d298a4d 100644
--- a/src/qemu/qemu_alias.h
+++ b/src/qemu/qemu_alias.h
@@ -83,4 +83,7 @@ char *qemuDomainGetSecretAESAlias(const char *srcalias,
char *qemuAliasTLSObjFromChardevAlias(const char *chardev_alias)
ATTRIBUTE_NONNULL(1);
+char *qemuAliasChardevFromDevAlias(const char *devAlias)
+ ATTRIBUTE_NONNULL(1);
+
#endif /* __QEMU_ALIAS_H__*/
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 21fd85c..f5ed490 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5484,7 +5484,7 @@ qemuBuildRNGBackendProps(virDomainRNGDefPtr rng,
*type = "rng-egd";
- if (virAsprintf(&charBackendAlias, "char%s", rng->info.alias)
< 0)
+ if (!(charBackendAlias = qemuAliasChardevFromDevAlias(rng->info.alias)))
goto cleanup;
if (virJSONValueObjectCreate(props, "s:chardev", charBackendAlias,
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index c2ba935..af87581 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -1058,7 +1058,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
goto cleanup;
}
- if (virAsprintf(&charDevAlias, "char%s", net->info.alias) <
0)
+ if (!(charDevAlias = qemuAliasChardevFromDevAlias(net->info.alias)))
goto cleanup;
break;
@@ -1487,7 +1487,7 @@ int qemuDomainAttachRedirdevDevice(virQEMUDriverPtr driver,
if (qemuAssignDeviceRedirdevAlias(def, redirdev, -1) < 0)
goto cleanup;
- if (virAsprintf(&charAlias, "char%s", redirdev->info.alias) < 0)
+ if (!(charAlias = qemuAliasChardevFromDevAlias(redirdev->info.alias)))
goto cleanup;
if (!(devstr = qemuBuildRedirdevDevStr(def, redirdev, priv->qemuCaps)))
@@ -1723,7 +1723,7 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
if (qemuBuildChrDeviceStr(&devstr, vmdef, chr, priv->qemuCaps) < 0)
goto cleanup;
- if (virAsprintf(&charAlias, "char%s", chr->info.alias) < 0)
+ if (!(charAlias = qemuAliasChardevFromDevAlias(chr->info.alias)))
goto cleanup;
if (qemuDomainChrPreInsert(vmdef, chr) < 0)
@@ -1858,7 +1858,7 @@ qemuDomainAttachRNGDevice(virQEMUDriverPtr driver,
if (virAsprintf(&objAlias, "obj%s", rng->info.alias) < 0)
goto cleanup;
- if (virAsprintf(&charAlias, "char%s", rng->info.alias) < 0)
+ if (!(charAlias = qemuAliasChardevFromDevAlias(rng->info.alias)))
goto cleanup;
qemuDomainObjEnterMonitor(driver, vm);
@@ -3370,7 +3370,7 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver,
net->info.alias, vm, vm->def->name);
if (virAsprintf(&hostnet_name, "host%s", net->info.alias) < 0 ||
- virAsprintf(&charDevAlias, "char%s", net->info.alias) < 0)
+ !(charDevAlias = qemuAliasChardevFromDevAlias(net->info.alias)))
goto cleanup;
@@ -3477,7 +3477,7 @@ qemuDomainRemoveChrDevice(virQEMUDriverPtr driver,
VIR_DEBUG("Removing character device %s from domain %p %s",
chr->info.alias, vm, vm->def->name);
- if (virAsprintf(&charAlias, "char%s", chr->info.alias) < 0)
+ if (!(charAlias = qemuAliasChardevFromDevAlias(chr->info.alias)))
goto cleanup;
qemuDomainObjEnterMonitor(driver, vm);
@@ -3522,7 +3522,7 @@ qemuDomainRemoveRNGDevice(virQEMUDriverPtr driver,
if (virAsprintf(&objAlias, "obj%s", rng->info.alias) < 0)
goto cleanup;
- if (virAsprintf(&charAlias, "char%s", rng->info.alias) < 0)
+ if (!(charAlias = qemuAliasChardevFromDevAlias(rng->info.alias)))
goto cleanup;
qemuDomainObjEnterMonitor(driver, vm);
--
2.10.1