From 6f1de6b70d857d5e316ae6fd908f52818b827b08 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 20 Jun 2016 15:02:40 +0200 Subject: char: change qemu_chr_fe_add_watch to return unsigned g_source_attach can return any value between 1 and UINT_MAX if you let QEMU run long enough. However, qemu_chr_fe_add_watch can also return a negative errno value when the device is disconnected or does not support chr_add_watch. Change it to return zero to avoid overloading these values. Fix the cadence_uart which asserts in this case (easily obtained with "-serial pty"). Tested-by: Bret Ketchum Reviewed-by: Dr. David Alan Gilbert Signed-off-by: Paolo Bonzini --- qemu-char.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'qemu-char.c') diff --git a/qemu-char.c b/qemu-char.c index 84f49ac..8575c54 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -3966,19 +3966,19 @@ void qemu_chr_fe_event(struct CharDriverState *chr, int event) } } -int qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond, - GIOFunc func, void *user_data) +guint qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond, + GIOFunc func, void *user_data) { GSource *src; guint tag; if (s->chr_add_watch == NULL) { - return -ENOSYS; + return 0; } src = s->chr_add_watch(s, cond); if (!src) { - return -EINVAL; + return 0; } g_source_set_callback(src, (GSourceFunc)func, user_data, NULL); -- cgit v1.1 From c1111a24a3358ecd2f17be7c8b117cfe8bc5e5f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Thu, 16 Jun 2016 21:28:50 +0200 Subject: char: clean up remaining chardevs when leaving MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This helps to remove various chardev resources leaks when leaving qemu. Signed-off-by: Marc-André Lureau Message-Id: <1466105332-10285-2-git-send-email-marcandre.lureau@redhat.com> Signed-off-by: Paolo Bonzini --- qemu-char.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'qemu-char.c') diff --git a/qemu-char.c b/qemu-char.c index 8575c54..b73969dd 100644 --- a/qemu-char.c +++ b/qemu-char.c @@ -4549,6 +4549,15 @@ void qmp_chardev_remove(const char *id, Error **errp) qemu_chr_delete(chr); } +static void qemu_chr_cleanup(void) +{ + CharDriverState *chr, *tmp; + + QTAILQ_FOREACH_SAFE(chr, &chardevs, next, tmp) { + qemu_chr_delete(chr); + } +} + static void register_types(void) { register_char_driver("null", CHARDEV_BACKEND_KIND_NULL, NULL, @@ -4595,6 +4604,8 @@ static void register_types(void) * is specified */ qemu_add_machine_init_done_notifier(&muxes_realize_notify); + + atexit(qemu_chr_cleanup); } type_init(register_types); -- cgit v1.1