aboutsummaryrefslogtreecommitdiff
path: root/chardev
diff options
context:
space:
mode:
authorLukas Straub <lukasstraub2@web.de>2021-03-30 20:13:25 +0200
committerMarc-André Lureau <marcandre.lureau@redhat.com>2021-04-01 15:27:44 +0400
commit789fd6934e1511d7e487c6277ab762189ddd05b3 (patch)
tree47d922b4f1cb1c6aae9fa9cf32fe8d5160c341f4 /chardev
parente0150291ec87234e1c3d01eb9ad4c6315f5306c4 (diff)
chardev/char.c: Move object_property_try_add_child out of chardev_new
Move object_property_try_add_child out of chardev_new into it's callers. This is a preparation for the next patches to fix yank with the chardev-change case. Signed-off-by: Lukas Straub <lukasstraub2@web.de> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Tested-by: Li Zhang <li.zhang@cloud.ionos.com> Message-Id: <b2a5092ec681737bc3a21ea16f3c00848b277521.1617127849.git.lukasstraub2@web.de>
Diffstat (limited to 'chardev')
-rw-r--r--chardev/char.c42
1 files changed, 24 insertions, 18 deletions
diff --git a/chardev/char.c b/chardev/char.c
index 140d6d9d36..48f321b3e1 100644
--- a/chardev/char.c
+++ b/chardev/char.c
@@ -975,7 +975,9 @@ static Chardev *chardev_new(const char *id, const char *typename,
qemu_char_open(chr, backend, &be_opened, &local_err);
if (local_err) {
- goto end;
+ error_propagate(errp, local_err);
+ object_unref(obj);
+ return NULL;
}
if (!chr->filename) {
@@ -985,22 +987,6 @@ static Chardev *chardev_new(const char *id, const char *typename,
qemu_chr_be_event(chr, CHR_EVENT_OPENED);
}
- if (id) {
- object_property_try_add_child(get_chardevs_root(), id, obj,
- &local_err);
- if (local_err) {
- goto end;
- }
- object_unref(obj);
- }
-
-end:
- if (local_err) {
- error_propagate(errp, local_err);
- object_unref(obj);
- return NULL;
- }
-
return chr;
}
@@ -1009,6 +995,7 @@ Chardev *qemu_chardev_new(const char *id, const char *typename,
GMainContext *gcontext,
Error **errp)
{
+ Chardev *chr;
g_autofree char *genid = NULL;
if (!id) {
@@ -1016,7 +1003,19 @@ Chardev *qemu_chardev_new(const char *id, const char *typename,
id = genid;
}
- return chardev_new(id, typename, backend, gcontext, errp);
+ chr = chardev_new(id, typename, backend, gcontext, errp);
+ if (!chr) {
+ return NULL;
+ }
+
+ if (!object_property_try_add_child(get_chardevs_root(), id, OBJECT(chr),
+ errp)) {
+ object_unref(OBJECT(chr));
+ return NULL;
+ }
+ object_unref(OBJECT(chr));
+
+ return chr;
}
ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
@@ -1037,6 +1036,13 @@ ChardevReturn *qmp_chardev_add(const char *id, ChardevBackend *backend,
return NULL;
}
+ if (!object_property_try_add_child(get_chardevs_root(), id, OBJECT(chr),
+ errp)) {
+ object_unref(OBJECT(chr));
+ return NULL;
+ }
+ object_unref(OBJECT(chr));
+
ret = g_new0(ChardevReturn, 1);
if (CHARDEV_IS_PTY(chr)) {
ret->pty = g_strdup(chr->filename + 4);