[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL 28/32] char: change qemu_chr_fe_add_watch to return u
From: |
Paolo Bonzini |
Subject: |
[Qemu-devel] [PULL 28/32] char: change qemu_chr_fe_add_watch to return unsigned |
Date: |
Tue, 28 Jun 2016 19:33:58 +0200 |
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 <address@hidden>
Reviewed-by: Dr. David Alan Gilbert <address@hidden>
Signed-off-by: Paolo Bonzini <address@hidden>
---
hw/char/cadence_uart.c | 9 ++++++---
include/sysemu/char.h | 16 ++++++++++++++--
net/vhost-user.c | 2 +-
qemu-char.c | 8 ++++----
4 files changed, 25 insertions(+), 10 deletions(-)
diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c
index 844542f..e3bc52f 100644
--- a/hw/char/cadence_uart.c
+++ b/hw/char/cadence_uart.c
@@ -295,9 +295,12 @@ static gboolean cadence_uart_xmit(GIOChannel *chan,
GIOCondition cond,
}
if (s->tx_count) {
- int r = qemu_chr_fe_add_watch(s->chr, G_IO_OUT|G_IO_HUP,
- cadence_uart_xmit, s);
- assert(r);
+ guint r = qemu_chr_fe_add_watch(s->chr, G_IO_OUT|G_IO_HUP,
+ cadence_uart_xmit, s);
+ if (!r) {
+ s->tx_count = 0;
+ return FALSE;
+ }
}
uart_update_status(s);
diff --git a/include/sysemu/char.h b/include/sysemu/char.h
index 1eb2d0f..57df10a 100644
--- a/include/sysemu/char.h
+++ b/include/sysemu/char.h
@@ -221,8 +221,20 @@ void qemu_chr_fe_event(CharDriverState *s, int event);
void qemu_chr_fe_printf(CharDriverState *s, const char *fmt, ...)
GCC_FMT_ATTR(2, 3);
-int qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond,
- GIOFunc func, void *user_data);
+/**
+ * @qemu_chr_fe_add_watch:
+ *
+ * If the backend is connected, create and add a #GSource that fires
+ * when the given condition (typically G_IO_OUT|G_IO_HUP or G_IO_HUP)
+ * is active; return the #GSource's tag. If it is disconnected,
+ * return 0.
+ *
+ * @cond the condition to poll for
+ * @func the function to call when the condition happens
+ * @user_data the opaque pointer to pass to @func
+ */
+guint qemu_chr_fe_add_watch(CharDriverState *s, GIOCondition cond,
+ GIOFunc func, void *user_data);
/**
* @qemu_chr_fe_write:
diff --git a/net/vhost-user.c b/net/vhost-user.c
index d72ce9b..636899a 100644
--- a/net/vhost-user.c
+++ b/net/vhost-user.c
@@ -22,7 +22,7 @@ typedef struct VhostUserState {
NetClientState nc;
CharDriverState *chr;
VHostNetState *vhost_net;
- int watch;
+ guint watch;
uint64_t acked_features;
} VhostUserState;
diff --git a/qemu-char.c b/qemu-char.c
index 016badb..4aeafe8 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);
--
2.7.4
- [Qemu-devel] [PULL 22/32] socket: add listen feature, (continued)
- [Qemu-devel] [PULL 22/32] socket: add listen feature, Paolo Bonzini, 2016/06/28
- [Qemu-devel] [PULL 23/32] socket: unlink unix socket on remove, Paolo Bonzini, 2016/06/28
- [Qemu-devel] [PULL 24/32] iscsi: fix assertion in is_sector_request_lun_aligned, Paolo Bonzini, 2016/06/28
- [Qemu-devel] [PULL 26/32] serial: simplify tsr_retry reset, Paolo Bonzini, 2016/06/28
- [Qemu-devel] [PULL 20/32] target-*: Don't redefine cpu_exec(), Paolo Bonzini, 2016/06/28
- [Qemu-devel] [PULL 25/32] serial: make tsr_retry unsigned, Paolo Bonzini, 2016/06/28
- [Qemu-devel] [PULL 29/32] serial: remove watch on reset, Paolo Bonzini, 2016/06/28
- [Qemu-devel] [PULL 27/32] serial: separate serial_xmit and serial_watch_cb, Paolo Bonzini, 2016/06/28
- [Qemu-devel] [PULL 30/32] serial: reinstate watch after migration, Paolo Bonzini, 2016/06/28
- [Qemu-devel] [PULL 32/32] ich9: implement SCI_IRQ_SEL register, Paolo Bonzini, 2016/06/28
- [Qemu-devel] [PULL 28/32] char: change qemu_chr_fe_add_watch to return unsigned,
Paolo Bonzini <=
- [Qemu-devel] [PULL 31/32] ich9: implement ACPI_EN register, Paolo Bonzini, 2016/06/28
- Re: [Qemu-devel] [PULL 00/32] Misc patches for QEMU soft freeze, Peter Maydell, 2016/06/29