aboutsummaryrefslogtreecommitdiff
path: root/chardev
diff options
context:
space:
mode:
Diffstat (limited to 'chardev')
-rw-r--r--chardev/char.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/chardev/char.c b/chardev/char.c
index 4f598f8175..87237568df 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -37,6 +37,7 @@
#include "qemu/help_option.h"
#include "qemu/module.h"
#include "qemu/option.h"
+#include "qemu/id.h"
#include "chardev/char-mux.h"
@@ -949,10 +950,10 @@ void qemu_chr_set_feature(Chardev *chr,
return set_bit(feature, chr->features);
}
-Chardev *qemu_chardev_new(const char *id, const char *typename,
- ChardevBackend *backend,
- GMainContext *gcontext,
- Error **errp)
+static Chardev *chardev_new(const char *id, const char *typename,
+ ChardevBackend *backend,
+ GMainContext *gcontext,
+ Error **errp)
{
Object *obj;
Chardev *chr = NULL;
@@ -996,6 +997,21 @@ end:
return chr;
}
+Chardev *qemu_chardev_new(const char *id, const char *typename,
+ ChardevBackend *backend,
+ GMainContext *gcontext,
+ Error **errp)
+{
+ g_autofree char *genid = NULL;
+
+ if (!id) {
+ genid = id_generate(ID_CHR);
+ id = genid;
+ }
+
+ return chardev_new(id, typename, backend, gcontext, errp);
+}
+
ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
Error **errp)
{
@@ -1008,8 +1024,8 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
return NULL;
}
- chr = qemu_chardev_new(id, object_class_get_name(OBJECT_CLASS(cc)),
- backend, NULL, errp);
+ chr = chardev_new(id, object_class_get_name(OBJECT_CLASS(cc)),
+ backend, NULL, errp);
if (!chr) {
return NULL;
}
@@ -1066,8 +1082,8 @@ ChardevReturn *qmp_chardev_change(const char *id, ChardevBackend *backend,
return NULL;
}
- chr_new = qemu_chardev_new(NULL, object_class_get_name(OBJECT_CLASS(cc)),
- backend, chr->gcontext, errp);
+ chr_new = chardev_new(NULL, object_class_get_name(OBJECT_CLASS(cc)),
+ backend, chr->gcontext, errp);
if (!chr_new) {
return NULL;
}