Hi On Mon, Mar 22, 2021 at 3:31 AM Lukas Straub <lukasstra...@web.de> wrote:
> 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 <lukasstra...@web.de> > --- > chardev/char.c | 42 ++++++++++++++++++++++++------------------ > 1 file changed, 24 insertions(+), 18 deletions(-) > > diff --git a/chardev/char.c b/chardev/char.c > index 97cafd6849..1584865027 100644 > --- a/chardev/char.c > +++ b/chardev/char.c > @@ -972,7 +972,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) { > @@ -982,22 +984,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; > } > > @@ -1006,6 +992,7 @@ Chardev *qemu_chardev_new(const char *id, const char > *typename, > GMainContext *gcontext, > Error **errp) > { > + Chardev *chr; > g_autofree char *genid = NULL; > > if (!id) { > @@ -1013,7 +1000,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); > You could have added a "register" argument to avoid duplication of code imho. But since there are only 2 callers, I guess it's fine to inline it. Reviewed-by: Marc-André Lureau <marcandre.lur...@redhat.com> + 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, > @@ -1034,6 +1033,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); > -- > 2.30.2 > > -- Marc-André Lureau