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>
This commit is contained in:
Lukas Straub 2021-03-30 20:13:25 +02:00 committed by Marc-André Lureau
parent e0150291ec
commit 789fd6934e

View File

@ -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);