From: Lukas Straub <lukasstraub2@web.de>
To: qemu-devel <qemu-devel@nongnu.org>
Cc: Marc-Andre Lureau <marcandre.lureau@gmail.com>
Subject: [PATCH v6 1/4] chardev/char.c: Move object_property_try_add_child out of chardev_new
Date: Mon, 29 Mar 2021 18:38:35 +0200 [thread overview]
Message-ID: <b2a5092ec681737bc3a21ea16f3c00848b277521.1617035720.git.lukasstraub2@web.de> (raw)
In-Reply-To: <cover.1617035720.git.lukasstraub2@web.de>
[-- Attachment #1: Type: text/plain, Size: 2844 bytes --]
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>
---
chardev/char.c | 42 ++++++++++++++++++++++++------------------
1 file 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);
--
2.30.2
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2021-03-29 16:41 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-29 16:38 [PATCH v6 0/4] yank: Add chardev tests and fixes Lukas Straub
2021-03-29 16:38 ` Lukas Straub [this message]
2021-03-29 16:38 ` [PATCH v6 2/4] chardev/char.c: Always pass id to chardev_new Lukas Straub
2021-03-29 16:38 ` [PATCH v6 3/4] chardev: Fix yank with the chardev-change case Lukas Straub
2021-03-29 16:38 ` [PATCH v6 4/4] tests: Add tests for " Lukas Straub
2021-03-29 17:09 ` [PATCH v6 0/4] yank: Add chardev tests and fixes no-reply
2021-03-29 18:19 ` Marc-André Lureau
2021-03-29 18:50 ` Lukas Straub
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b2a5092ec681737bc3a21ea16f3c00848b277521.1617035720.git.lukasstraub2@web.de \
--to=lukasstraub2@web.de \
--cc=marcandre.lureau@gmail.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).