peterdelevoryas / rpms / qemu

Forked from rpms/qemu 2 years ago
Clone

Blame 0102-char-Add-a-QemuChrHandlers-struct-to-initialise-char.patch

6986e1
From 687d91769e40878f3b8ebb9bdd8ee256a40c97cd Mon Sep 17 00:00:00 2001
22d63f
From: Amit Shah <amit.shah@redhat.com>
22d63f
Date: Mon, 21 Mar 2011 20:31:45 +0100
22d63f
Subject: [PATCH] char: Add a QemuChrHandlers struct to initialise chardev
22d63f
 handlers
22d63f
22d63f
Instead of passing each handler in the qemu_add_handlers() function,
22d63f
create a struct of handlers that can be passed to the function instead.
22d63f
22d63f
Signed-off-by: Amit Shah <amit.shah@redhat.com>
22d63f
Signed-off-by: Cole Robinson <crobinso@redhat.com>
22d63f
---
22d63f
 backends/rng-egd.c      | 12 +++++++++---
22d63f
 gdbstub.c               |  9 +++++++--
22d63f
 hw/cadence_uart.c       |  9 +++++++--
22d63f
 hw/ccid-card-passthru.c | 11 +++++++----
22d63f
 hw/debugcon.c           |  2 +-
22d63f
 hw/escc.c               |  9 +++++++--
22d63f
 hw/etraxfs_ser.c        | 13 +++++++++----
22d63f
 hw/exynos4210_uart.c    |  9 +++++++--
22d63f
 hw/grlib_apbuart.c      | 12 +++++++-----
22d63f
 hw/imx_serial.c         |  9 +++++++--
22d63f
 hw/ivshmem.c            | 28 ++++++++++++++++++++++------
22d63f
 hw/lm32_juart.c         |  8 +++++++-
22d63f
 hw/lm32_uart.c          |  8 +++++++-
22d63f
 hw/mcf_uart.c           |  9 +++++++--
22d63f
 hw/milkymist-uart.c     |  8 +++++++-
22d63f
 hw/pl011.c              |  9 +++++++--
22d63f
 hw/pxa2xx.c             | 13 +++++++++----
22d63f
 hw/qdev-properties.c    |  2 +-
22d63f
 hw/s390x/sclpconsole.c  |  9 +++++++--
22d63f
 hw/serial.c             | 11 ++++++++---
22d63f
 hw/sh_serial.c          | 12 +++++++++---
22d63f
 hw/spapr_vty.c          |  8 ++++++--
22d63f
 hw/strongarm.c          | 12 +++++++-----
22d63f
 hw/usb/dev-serial.c     | 11 ++++++++---
22d63f
 hw/usb/redirect.c       |  9 +++++++--
22d63f
 hw/virtio-console.c     |  9 +++++++--
22d63f
 hw/xen_console.c        | 16 +++++++++++-----
22d63f
 hw/xilinx_uartlite.c    | 11 +++++++++--
22d63f
 monitor.c               | 18 ++++++++++++++----
22d63f
 net/slirp.c             |  8 ++++++--
22d63f
 qemu-char.c             | 32 ++++++++++++++++++++++----------
22d63f
 qemu-char.h             | 13 +++++++++----
22d63f
 qtest.c                 |  9 ++++++++-
22d63f
 33 files changed, 273 insertions(+), 95 deletions(-)
22d63f
22d63f
diff --git a/backends/rng-egd.c b/backends/rng-egd.c
22d63f
index ad84737..30194be 100644
22d63f
--- a/backends/rng-egd.c
22d63f
+++ b/backends/rng-egd.c
22d63f
@@ -133,6 +133,13 @@ static void rng_egd_cancel_requests(RngBackend *b)
22d63f
     rng_egd_free_requests(s);
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers rng_egd_handlers = {
22d63f
+    .fd_can_read = rng_egd_chr_can_read,
22d63f
+    .fd_read = rng_egd_chr_read,
22d63f
+    .fd_event = NULL,
22d63f
+};
22d63f
+
22d63f
+
22d63f
 static void rng_egd_opened(RngBackend *b, Error **errp)
22d63f
 {
22d63f
     RngEgd *s = RNG_EGD(b);
22d63f
@@ -150,8 +157,7 @@ static void rng_egd_opened(RngBackend *b, Error **errp)
22d63f
     }
22d63f
 
22d63f
     /* FIXME we should resubmit pending requests when the CDS reconnects. */
22d63f
-    qemu_chr_add_handlers(s->chr, rng_egd_chr_can_read, rng_egd_chr_read,
22d63f
-                          NULL, s);
22d63f
+    qemu_chr_add_handlers(s->chr, &rng_egd_handlers, s);
22d63f
 }
22d63f
 
22d63f
 static void rng_egd_set_chardev(Object *obj, const char *value, Error **errp)
22d63f
@@ -190,7 +196,7 @@ static void rng_egd_finalize(Object *obj)
22d63f
     RngEgd *s = RNG_EGD(obj);
22d63f
 
22d63f
     if (s->chr) {
22d63f
-        qemu_chr_add_handlers(s->chr, NULL, NULL, NULL, NULL);
22d63f
+        qemu_chr_add_handlers(s->chr, NULL, NULL);
22d63f
     }
22d63f
 
22d63f
     g_free(s->chr_name);
22d63f
diff --git a/gdbstub.c b/gdbstub.c
22d63f
index d02ec75..5d93d20 100644
22d63f
--- a/gdbstub.c
22d63f
+++ b/gdbstub.c
22d63f
@@ -2973,6 +2973,12 @@ static void gdb_sigterm_handler(int signal)
22d63f
 }
22d63f
 #endif
22d63f
 
22d63f
+static const QemuChrHandlers gdb_handlers = {
22d63f
+    .fd_can_read = gdb_chr_can_receive,
22d63f
+    .fd_read = gdb_chr_receive,
22d63f
+    .fd_event = gdb_chr_event,
22d63f
+};
22d63f
+
22d63f
 int gdbserver_start(const char *device)
22d63f
 {
22d63f
     GDBState *s;
22d63f
@@ -3002,8 +3008,7 @@ int gdbserver_start(const char *device)
22d63f
         if (!chr)
22d63f
             return -1;
22d63f
 
22d63f
-        qemu_chr_add_handlers(chr, gdb_chr_can_receive, gdb_chr_receive,
22d63f
-                              gdb_chr_event, NULL);
22d63f
+        qemu_chr_add_handlers(chr, &gdb_handlers, NULL);
22d63f
     }
22d63f
 
22d63f
     s = gdbserver_state;
22d63f
diff --git a/hw/cadence_uart.c b/hw/cadence_uart.c
22d63f
index 686e617..36ad620 100644
22d63f
--- a/hw/cadence_uart.c
22d63f
+++ b/hw/cadence_uart.c
22d63f
@@ -438,6 +438,12 @@ static void cadence_uart_reset(UartState *s)
22d63f
     s->rx_wpos = 0;
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers cadence_uart_handlers = {
22d63f
+    .fd_can_read = uart_can_receive,
22d63f
+    .fd_read = uart_receive,
22d63f
+    .fd_event = uart_event,
22d63f
+};
22d63f
+
22d63f
 static int cadence_uart_init(SysBusDevice *dev)
22d63f
 {
22d63f
     UartState *s = FROM_SYSBUS(UartState, dev);
22d63f
@@ -459,8 +465,7 @@ static int cadence_uart_init(SysBusDevice *dev)
22d63f
     cadence_uart_reset(s);
22d63f
 
22d63f
     if (s->chr) {
22d63f
-        qemu_chr_add_handlers(s->chr, uart_can_receive, uart_receive,
22d63f
-                              uart_event, s);
22d63f
+        qemu_chr_add_handlers(s->chr, &cadence_uart_handlers, s);
22d63f
     }
22d63f
 
22d63f
     return 0;
22d63f
diff --git a/hw/ccid-card-passthru.c b/hw/ccid-card-passthru.c
22d63f
index bd6c777..fb32107 100644
22d63f
--- a/hw/ccid-card-passthru.c
22d63f
+++ b/hw/ccid-card-passthru.c
22d63f
@@ -274,6 +274,12 @@ static const uint8_t *passthru_get_atr(CCIDCardState *base, uint32_t *len)
22d63f
     return card->atr;
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers passthru_handlers = {
22d63f
+    .fd_can_read = ccid_card_vscard_can_read,
22d63f
+    .fd_read = ccid_card_vscard_read,
22d63f
+    .fd_event = ccid_card_vscard_event,
22d63f
+};
22d63f
+
22d63f
 static int passthru_initfn(CCIDCardState *base)
22d63f
 {
22d63f
     PassthruState *card = DO_UPCAST(PassthruState, base, base);
22d63f
@@ -282,10 +288,7 @@ static int passthru_initfn(CCIDCardState *base)
22d63f
     card->vscard_in_hdr = 0;
22d63f
     if (card->cs) {
22d63f
         DPRINTF(card, D_INFO, "initing chardev\n");
22d63f
-        qemu_chr_add_handlers(card->cs,
22d63f
-            ccid_card_vscard_can_read,
22d63f
-            ccid_card_vscard_read,
22d63f
-            ccid_card_vscard_event, card);
22d63f
+        qemu_chr_add_handlers(card->cs, &passthru_handlers, card);
22d63f
         ccid_card_vscard_send_init(card);
22d63f
     } else {
22d63f
         error_report("missing chardev");
22d63f
diff --git a/hw/debugcon.c b/hw/debugcon.c
22d63f
index 14ab326..7887fd2 100644
22d63f
--- a/hw/debugcon.c
22d63f
+++ b/hw/debugcon.c
22d63f
@@ -73,7 +73,7 @@ static void debugcon_init_core(DebugconState *s)
22d63f
         exit(1);
22d63f
     }
22d63f
 
22d63f
-    qemu_chr_add_handlers(s->chr, NULL, NULL, NULL, s);
22d63f
+    qemu_chr_add_handlers(s->chr, NULL, s);
22d63f
 }
22d63f
 
22d63f
 static int debugcon_isa_initfn(ISADevice *dev)
22d63f
diff --git a/hw/escc.c b/hw/escc.c
22d63f
index a356613..3f26f45 100644
22d63f
--- a/hw/escc.c
22d63f
+++ b/hw/escc.c
22d63f
@@ -867,6 +867,12 @@ void slavio_serial_ms_kbd_init(hwaddr base, qemu_irq irq,
22d63f
     sysbus_mmio_map(s, 0, base);
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers serial_handlers = {
22d63f
+    .fd_can_read = serial_can_receive,
22d63f
+    .fd_read = serial_receive1,
22d63f
+    .fd_event = serial_event,
22d63f
+};
22d63f
+
22d63f
 static int escc_init1(SysBusDevice *dev)
22d63f
 {
22d63f
     SerialState *s = FROM_SYSBUS(SerialState, dev);
22d63f
@@ -879,8 +885,7 @@ static int escc_init1(SysBusDevice *dev)
22d63f
         s->chn[i].chn = 1 - i;
22d63f
         s->chn[i].clock = s->frequency / 2;
22d63f
         if (s->chn[i].chr) {
22d63f
-            qemu_chr_add_handlers(s->chn[i].chr, serial_can_receive,
22d63f
-                                  serial_receive1, serial_event, &s->chn[i]);
22d63f
+            qemu_chr_add_handlers(s->chn[i].chr, &serial_handlers, &s->chn[i]);
22d63f
         }
22d63f
     }
22d63f
     s->chn[0].otherchn = &s->chn[1];
22d63f
diff --git a/hw/etraxfs_ser.c b/hw/etraxfs_ser.c
22d63f
index ee0d72b..64552cc 100644
22d63f
--- a/hw/etraxfs_ser.c
22d63f
+++ b/hw/etraxfs_ser.c
22d63f
@@ -208,6 +208,12 @@ static void etraxfs_ser_reset(DeviceState *d)
22d63f
 
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers serial_handlers = {
22d63f
+    .fd_can_read = serial_can_receive,
22d63f
+    .fd_read = serial_receive,
22d63f
+    .fd_event = serial_event,
22d63f
+};
22d63f
+
22d63f
 static int etraxfs_ser_init(SysBusDevice *dev)
22d63f
 {
22d63f
     struct etrax_serial *s = FROM_SYSBUS(typeof (*s), dev);
22d63f
@@ -217,10 +223,9 @@ static int etraxfs_ser_init(SysBusDevice *dev)
22d63f
     sysbus_init_mmio(dev, &s->mmio);
22d63f
 
22d63f
     s->chr = qemu_char_get_next_serial();
22d63f
-    if (s->chr)
22d63f
-        qemu_chr_add_handlers(s->chr,
22d63f
-                      serial_can_receive, serial_receive,
22d63f
-                      serial_event, s);
22d63f
+    if (s->chr) {
22d63f
+        qemu_chr_add_handlers(s->chr, &serial_handlers, s);
22d63f
+    }
22d63f
     return 0;
22d63f
 }
22d63f
 
22d63f
diff --git a/hw/exynos4210_uart.c b/hw/exynos4210_uart.c
22d63f
index 20dcd9f..f2949aa 100644
22d63f
--- a/hw/exynos4210_uart.c
22d63f
+++ b/hw/exynos4210_uart.c
22d63f
@@ -625,6 +625,12 @@ DeviceState *exynos4210_uart_create(hwaddr addr,
22d63f
     return dev;
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers exynos4210_handlers = {
22d63f
+    .fd_can_read = exynos4210_uart_can_receive,
22d63f
+    .fd_read     = exynos4210_uart_receive,
22d63f
+    .fd_event    = exynos4210_uart_event,
22d63f
+};
22d63f
+
22d63f
 static int exynos4210_uart_init(SysBusDevice *dev)
22d63f
 {
22d63f
     Exynos4210UartState *s = FROM_SYSBUS(Exynos4210UartState, dev);
22d63f
@@ -636,8 +642,7 @@ static int exynos4210_uart_init(SysBusDevice *dev)
22d63f
 
22d63f
     sysbus_init_irq(dev, &s->irq);
22d63f
 
22d63f
-    qemu_chr_add_handlers(s->chr, exynos4210_uart_can_receive,
22d63f
-                          exynos4210_uart_receive, exynos4210_uart_event, s);
22d63f
+    qemu_chr_add_handlers(s->chr, &exynos4210_handlers, s);
22d63f
 
22d63f
     return 0;
22d63f
 }
22d63f
diff --git a/hw/grlib_apbuart.c b/hw/grlib_apbuart.c
22d63f
index 0865764..fb0e703 100644
22d63f
--- a/hw/grlib_apbuart.c
22d63f
+++ b/hw/grlib_apbuart.c
22d63f
@@ -222,15 +222,17 @@ static const MemoryRegionOps grlib_apbuart_ops = {
22d63f
     .endianness = DEVICE_NATIVE_ENDIAN,
22d63f
 };
22d63f
 
22d63f
+static const QemuChrHandlers grlib_handlers = {
22d63f
+    .fd_can_read = grlib_apbuart_can_receive,
22d63f
+    .fd_read = grlib_apbuart_receive,
22d63f
+    .fd_event = grlib_apbuart_event,
22d63f
+};
22d63f
+
22d63f
 static int grlib_apbuart_init(SysBusDevice *dev)
22d63f
 {
22d63f
     UART *uart = FROM_SYSBUS(typeof(*uart), dev);
22d63f
 
22d63f
-    qemu_chr_add_handlers(uart->chr,
22d63f
-                          grlib_apbuart_can_receive,
22d63f
-                          grlib_apbuart_receive,
22d63f
-                          grlib_apbuart_event,
22d63f
-                          uart);
22d63f
+    qemu_chr_add_handlers(uart->chr, &grlib_handlers, uart);
22d63f
 
22d63f
     sysbus_init_irq(dev, &uart->irq);
22d63f
 
22d63f
diff --git a/hw/imx_serial.c b/hw/imx_serial.c
22d63f
index dcd125f..5347ec8 100644
22d63f
--- a/hw/imx_serial.c
22d63f
+++ b/hw/imx_serial.c
22d63f
@@ -381,6 +381,12 @@ static const struct MemoryRegionOps imx_serial_ops = {
22d63f
     .endianness = DEVICE_NATIVE_ENDIAN,
22d63f
 };
22d63f
 
22d63f
+static const QemuChrHandlers imx_handlers = {
22d63f
+    .fd_can_read = imx_can_receive,
22d63f
+    .fd_read = imx_receive,
22d63f
+    .fd_event = imx_event,
22d63f
+};
22d63f
+
22d63f
 static int imx_serial_init(SysBusDevice *dev)
22d63f
 {
22d63f
     IMXSerialState *s = FROM_SYSBUS(IMXSerialState, dev);
22d63f
@@ -391,8 +397,7 @@ static int imx_serial_init(SysBusDevice *dev)
22d63f
     sysbus_init_irq(dev, &s->irq);
22d63f
 
22d63f
     if (s->chr) {
22d63f
-        qemu_chr_add_handlers(s->chr, imx_can_receive, imx_receive,
22d63f
-                              imx_event, s);
22d63f
+        qemu_chr_add_handlers(s->chr, &imx_handlers, s);
22d63f
     } else {
22d63f
         DPRINTF("No char dev for uart at 0x%lx\n",
22d63f
                 (unsigned long)s->iomem.ram_addr);
22d63f
diff --git a/hw/ivshmem.c b/hw/ivshmem.c
22d63f
index f6dbb21..0e56a97 100644
22d63f
--- a/hw/ivshmem.c
22d63f
+++ b/hw/ivshmem.c
22d63f
@@ -274,6 +274,18 @@ static void fake_irqfd(void *opaque, const uint8_t *buf, int size) {
22d63f
     msix_notify(pdev, entry->vector);
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers ivshmem_handlers = {
22d63f
+    .fd_can_read = ivshmem_can_receive,
22d63f
+    .fd_read = ivshmem_receive,
22d63f
+    .fd_event = ivshmem_event,
22d63f
+};
22d63f
+
22d63f
+static const QemuChrHandlers ivshmem_msi_handlers = {
22d63f
+    .fd_can_read = ivshmem_can_receive,
22d63f
+    .fd_read = fake_irqfd,
22d63f
+    .fd_event = ivshmem_event,
22d63f
+};
22d63f
+
22d63f
 static CharDriverState* create_eventfd_chr_device(void * opaque, EventNotifier *n,
22d63f
                                                   int vector)
22d63f
 {
22d63f
@@ -294,11 +306,10 @@ static CharDriverState* create_eventfd_chr_device(void * opaque, EventNotifier *
22d63f
         s->eventfd_table[vector].pdev = &s->dev;
22d63f
         s->eventfd_table[vector].vector = vector;
22d63f
 
22d63f
-        qemu_chr_add_handlers(chr, ivshmem_can_receive, fake_irqfd,
22d63f
-                      ivshmem_event, &s->eventfd_table[vector]);
22d63f
+        qemu_chr_add_handlers(chr, &ivshmem_msi_handlers,
22d63f
+                              &s->eventfd_table[vector]);
22d63f
     } else {
22d63f
-        qemu_chr_add_handlers(chr, ivshmem_can_receive, ivshmem_receive,
22d63f
-                      ivshmem_event, s);
22d63f
+        qemu_chr_add_handlers(chr, &ivshmem_handlers, s);
22d63f
     }
22d63f
 
22d63f
     return chr;
22d63f
@@ -632,6 +643,12 @@ static void ivshmem_write_config(PCIDevice *pci_dev, uint32_t address,
22d63f
     msix_write_config(pci_dev, address, val, len);
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers ivshmem_server_handlers = {
22d63f
+    .fd_can_read = ivshmem_can_receive,
22d63f
+    .fd_read = ivshmem_read,
22d63f
+    .fd_event = ivshmem_event,
22d63f
+};
22d63f
+
22d63f
 static int pci_ivshmem_init(PCIDevice *dev)
22d63f
 {
22d63f
     IVShmemState *s = DO_UPCAST(IVShmemState, dev, dev);
22d63f
@@ -722,8 +739,7 @@ static int pci_ivshmem_init(PCIDevice *dev)
22d63f
 
22d63f
         s->eventfd_chr = g_malloc0(s->vectors * sizeof(CharDriverState *));
22d63f
 
22d63f
-        qemu_chr_add_handlers(s->server_chr, ivshmem_can_receive, ivshmem_read,
22d63f
-                     ivshmem_event, s);
22d63f
+        qemu_chr_add_handlers(s->server_chr, &ivshmem_server_handlers, s);
22d63f
     } else {
22d63f
         /* just map the file immediately, we're not using a server */
22d63f
         int fd;
22d63f
diff --git a/hw/lm32_juart.c b/hw/lm32_juart.c
22d63f
index f07ed39..d4daeb8 100644
22d63f
--- a/hw/lm32_juart.c
22d63f
+++ b/hw/lm32_juart.c
22d63f
@@ -110,13 +110,19 @@ static void juart_reset(DeviceState *d)
22d63f
     s->jrx = 0;
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers juart_handlers = {
22d63f
+    .fd_can_read = juart_can_rx,
22d63f
+    .fd_read = juart_rx,
22d63f
+    .fd_event = juart_event,
22d63f
+};
22d63f
+
22d63f
 static int lm32_juart_init(SysBusDevice *dev)
22d63f
 {
22d63f
     LM32JuartState *s = FROM_SYSBUS(typeof(*s), dev);
22d63f
 
22d63f
     s->chr = qemu_char_get_next_serial();
22d63f
     if (s->chr) {
22d63f
-        qemu_chr_add_handlers(s->chr, juart_can_rx, juart_rx, juart_event, s);
22d63f
+        qemu_chr_add_handlers(s->chr, &juart_handlers, s);
22d63f
     }
22d63f
 
22d63f
     return 0;
22d63f
diff --git a/hw/lm32_uart.c b/hw/lm32_uart.c
22d63f
index adb9287..e581bea 100644
22d63f
--- a/hw/lm32_uart.c
22d63f
+++ b/hw/lm32_uart.c
22d63f
@@ -243,6 +243,12 @@ static void uart_reset(DeviceState *d)
22d63f
     s->regs[R_LSR] = LSR_THRE | LSR_TEMT;
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers uart_handlers = {
22d63f
+    .fd_can_read = uart_can_rx,
22d63f
+    .fd_read = uart_rx,
22d63f
+    .fd_event = uart_event,
22d63f
+};
22d63f
+
22d63f
 static int lm32_uart_init(SysBusDevice *dev)
22d63f
 {
22d63f
     LM32UartState *s = FROM_SYSBUS(typeof(*s), dev);
22d63f
@@ -254,7 +260,7 @@ static int lm32_uart_init(SysBusDevice *dev)
22d63f
 
22d63f
     s->chr = qemu_char_get_next_serial();
22d63f
     if (s->chr) {
22d63f
-        qemu_chr_add_handlers(s->chr, uart_can_rx, uart_rx, uart_event, s);
22d63f
+        qemu_chr_add_handlers(s->chr, &uart_handlers, s);
22d63f
     }
22d63f
 
22d63f
     return 0;
22d63f
diff --git a/hw/mcf_uart.c b/hw/mcf_uart.c
22d63f
index d1655f8..8ead254 100644
22d63f
--- a/hw/mcf_uart.c
22d63f
+++ b/hw/mcf_uart.c
22d63f
@@ -272,6 +272,12 @@ static void mcf_uart_receive(void *opaque, const uint8_t *buf, int size)
22d63f
     mcf_uart_push_byte(s, buf[0]);
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers mcf_uart_handlers = {
22d63f
+    .fd_can_read = mcf_uart_can_receive,
22d63f
+    .fd_read = mcf_uart_receive,
22d63f
+    .fd_event = mcf_uart_event,
22d63f
+};
22d63f
+
22d63f
 void *mcf_uart_init(qemu_irq irq, CharDriverState *chr)
22d63f
 {
22d63f
     mcf_uart_state *s;
22d63f
@@ -280,8 +286,7 @@ void *mcf_uart_init(qemu_irq irq, CharDriverState *chr)
22d63f
     s->chr = chr;
22d63f
     s->irq = irq;
22d63f
     if (chr) {
22d63f
-        qemu_chr_add_handlers(chr, mcf_uart_can_receive, mcf_uart_receive,
22d63f
-                              mcf_uart_event, s);
22d63f
+        qemu_chr_add_handlers(chr, &mcf_uart_handlers, s);
22d63f
     }
22d63f
     mcf_uart_reset(s);
22d63f
     return s;
22d63f
diff --git a/hw/milkymist-uart.c b/hw/milkymist-uart.c
22d63f
index aefa8c7..0c924f2 100644
22d63f
--- a/hw/milkymist-uart.c
22d63f
+++ b/hw/milkymist-uart.c
22d63f
@@ -189,6 +189,12 @@ static void milkymist_uart_reset(DeviceState *d)
22d63f
     s->regs[R_STAT] = STAT_THRE;
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers uart_handlers = {
22d63f
+    .fd_can_read = uart_can_rx,
22d63f
+    .fd_read = uart_rx,
22d63f
+    .fd_event = uart_event,
22d63f
+};
22d63f
+
22d63f
 static int milkymist_uart_init(SysBusDevice *dev)
22d63f
 {
22d63f
     MilkymistUartState *s = FROM_SYSBUS(typeof(*s), dev);
22d63f
@@ -201,7 +207,7 @@ static int milkymist_uart_init(SysBusDevice *dev)
22d63f
 
22d63f
     s->chr = qemu_char_get_next_serial();
22d63f
     if (s->chr) {
22d63f
-        qemu_chr_add_handlers(s->chr, uart_can_rx, uart_rx, uart_event, s);
22d63f
+        qemu_chr_add_handlers(s->chr, &uart_handlers, s);
22d63f
     }
22d63f
 
22d63f
     return 0;
22d63f
diff --git a/hw/pl011.c b/hw/pl011.c
22d63f
index 1f7ce2f..7f44c55 100644
22d63f
--- a/hw/pl011.c
22d63f
+++ b/hw/pl011.c
22d63f
@@ -261,6 +261,12 @@ static const VMStateDescription vmstate_pl011 = {
22d63f
     }
22d63f
 };
22d63f
 
22d63f
+static const QemuChrHandlers pl011_handlers = {
22d63f
+    .fd_can_read = pl011_can_receive,
22d63f
+    .fd_read = pl011_receive,
22d63f
+    .fd_event = pl011_event,
22d63f
+};
22d63f
+
22d63f
 static int pl011_init(SysBusDevice *dev, const unsigned char *id)
22d63f
 {
22d63f
     pl011_state *s = FROM_SYSBUS(pl011_state, dev);
22d63f
@@ -276,8 +282,7 @@ static int pl011_init(SysBusDevice *dev, const unsigned char *id)
22d63f
     s->cr = 0x300;
22d63f
     s->flags = 0x90;
22d63f
     if (s->chr) {
22d63f
-        qemu_chr_add_handlers(s->chr, pl011_can_receive, pl011_receive,
22d63f
-                              pl011_event, s);
22d63f
+        qemu_chr_add_handlers(s->chr, &pl011_handlers, s);
22d63f
     }
22d63f
     vmstate_register(&dev->qdev, -1, &vmstate_pl011, s);
22d63f
     return 0;
22d63f
diff --git a/hw/pxa2xx.c b/hw/pxa2xx.c
22d63f
index e616979..f9ca062 100644
22d63f
--- a/hw/pxa2xx.c
22d63f
+++ b/hw/pxa2xx.c
22d63f
@@ -1962,6 +1962,12 @@ static int pxa2xx_fir_load(QEMUFile *f, void *opaque, int version_id)
22d63f
     return 0;
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers pxa2xx_handlers = {
22d63f
+    .fd_can_read = pxa2xx_fir_is_empty,
22d63f
+    .fd_read = pxa2xx_fir_rx,
22d63f
+    .fd_event = pxa2xx_fir_event,
22d63f
+};
22d63f
+
22d63f
 static PXA2xxFIrState *pxa2xx_fir_init(MemoryRegion *sysmem,
22d63f
                 hwaddr base,
22d63f
                 qemu_irq irq, qemu_irq rx_dma, qemu_irq tx_dma,
22d63f
@@ -1980,10 +1986,9 @@ static PXA2xxFIrState *pxa2xx_fir_init(MemoryRegion *sysmem,
22d63f
     memory_region_init_io(&s->iomem, &pxa2xx_fir_ops, s, "pxa2xx-fir", 0x1000);
22d63f
     memory_region_add_subregion(sysmem, base, &s->iomem);
22d63f
 
22d63f
-    if (chr)
22d63f
-        qemu_chr_add_handlers(chr, pxa2xx_fir_is_empty,
22d63f
-                        pxa2xx_fir_rx, pxa2xx_fir_event, s);
22d63f
-
22d63f
+    if (chr) {
22d63f
+        qemu_chr_add_handlers(chr, &pxa2xx_handlers, s);
22d63f
+    }
22d63f
     register_savevm(NULL, "pxa2xx_fir", 0, 0, pxa2xx_fir_save,
22d63f
                     pxa2xx_fir_load, s);
22d63f
 
22d63f
diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c
22d63f
index 81d901c..9e2b893 100644
22d63f
--- a/hw/qdev-properties.c
22d63f
+++ b/hw/qdev-properties.c
22d63f
@@ -550,7 +550,7 @@ static void release_chr(Object *obj, const char *name, void *opaque)
22d63f
     CharDriverState **ptr = qdev_get_prop_ptr(dev, prop);
22d63f
 
22d63f
     if (*ptr) {
22d63f
-        qemu_chr_add_handlers(*ptr, NULL, NULL, NULL, NULL);
22d63f
+        qemu_chr_add_handlers(*ptr, NULL, NULL);
22d63f
     }
22d63f
 }
22d63f
 
22d63f
diff --git a/hw/s390x/sclpconsole.c b/hw/s390x/sclpconsole.c
22d63f
index 0ec5623..b3d1d6b 100644
22d63f
--- a/hw/s390x/sclpconsole.c
22d63f
+++ b/hw/s390x/sclpconsole.c
22d63f
@@ -240,6 +240,12 @@ static void trigger_ascii_console_data(void *env, int n, int level)
22d63f
     sclp_service_interrupt(0);
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers sclp_chr_handlers = {
22d63f
+    .fd_can_read = chr_can_read,
22d63f
+    .fd_read = chr_read,
22d63f
+    .fd_event = chr_event,
22d63f
+};
22d63f
+
22d63f
 /* qemu object creation and initialization functions */
22d63f
 
22d63f
 /* tell character layer our call-back functions */
22d63f
@@ -256,8 +262,7 @@ static int console_init(SCLPEvent *event)
22d63f
     console_available = true;
22d63f
     event->event_type = SCLP_EVENT_ASCII_CONSOLE_DATA;
22d63f
     if (scon->chr) {
22d63f
-        qemu_chr_add_handlers(scon->chr, chr_can_read,
22d63f
-                              chr_read, chr_event, scon);
22d63f
+        qemu_chr_add_handlers(scon->chr, &sclp_chr_handlers, scon);
22d63f
     }
22d63f
     scon->irq_read_vt220 = *qemu_allocate_irqs(trigger_ascii_console_data,
22d63f
                                                NULL, 1);
22d63f
diff --git a/hw/serial.c b/hw/serial.c
22d63f
index 60283ea..9134d01 100644
22d63f
--- a/hw/serial.c
22d63f
+++ b/hw/serial.c
22d63f
@@ -676,6 +676,12 @@ static void serial_reset(void *opaque)
22d63f
     qemu_irq_lower(s->irq);
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers serial_handlers = {
22d63f
+    .fd_can_read = serial_can_receive1,
22d63f
+    .fd_read = serial_receive1,
22d63f
+    .fd_event = serial_event,
22d63f
+};
22d63f
+
22d63f
 void serial_init_core(SerialState *s)
22d63f
 {
22d63f
     if (!s->chr) {
22d63f
@@ -690,13 +696,12 @@ void serial_init_core(SerialState *s)
22d63f
 
22d63f
     qemu_register_reset(serial_reset, s);
22d63f
 
22d63f
-    qemu_chr_add_handlers(s->chr, serial_can_receive1, serial_receive1,
22d63f
-                          serial_event, s);
22d63f
+    qemu_chr_add_handlers(s->chr, &serial_handlers, s);
22d63f
 }
22d63f
 
22d63f
 void serial_exit_core(SerialState *s)
22d63f
 {
22d63f
-    qemu_chr_add_handlers(s->chr, NULL, NULL, NULL, NULL);
22d63f
+    qemu_chr_add_handlers(s->chr, NULL, NULL);
22d63f
     qemu_unregister_reset(serial_reset, s);
22d63f
 }
22d63f
 
22d63f
diff --git a/hw/sh_serial.c b/hw/sh_serial.c
22d63f
index 9da5d08..260185d 100644
22d63f
--- a/hw/sh_serial.c
22d63f
+++ b/hw/sh_serial.c
22d63f
@@ -352,6 +352,12 @@ static const MemoryRegionOps sh_serial_ops = {
22d63f
     .endianness = DEVICE_NATIVE_ENDIAN,
22d63f
 };
22d63f
 
22d63f
+static const QemuChrHandlers sh_serial_handlers = {
22d63f
+    .fd_can_read = sh_serial_can_receive1,
22d63f
+    .fd_read = sh_serial_receive1,
22d63f
+    .fd_event = sh_serial_event,
22d63f
+};
22d63f
+
22d63f
 void sh_serial_init(MemoryRegion *sysmem,
22d63f
                     hwaddr base, int feat,
22d63f
                     uint32_t freq, CharDriverState *chr,
22d63f
@@ -396,9 +402,9 @@ void sh_serial_init(MemoryRegion *sysmem,
22d63f
 
22d63f
     s->chr = chr;
22d63f
 
22d63f
-    if (chr)
22d63f
-        qemu_chr_add_handlers(chr, sh_serial_can_receive1, sh_serial_receive1,
22d63f
-			      sh_serial_event, s);
22d63f
+    if (chr) {
22d63f
+        qemu_chr_add_handlers(chr, &sh_serial_handlers, s);
22d63f
+    }
22d63f
 
22d63f
     s->eri = eri_source;
22d63f
     s->rxi = rxi_source;
22d63f
diff --git a/hw/spapr_vty.c b/hw/spapr_vty.c
22d63f
index 14f862f..9fbe7dd 100644
22d63f
--- a/hw/spapr_vty.c
22d63f
+++ b/hw/spapr_vty.c
22d63f
@@ -54,6 +54,11 @@ void vty_putchars(VIOsPAPRDevice *sdev, uint8_t *buf, int len)
22d63f
     qemu_chr_fe_write(dev->chardev, buf, len);
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers vty_handlers = {
22d63f
+    .fd_can_read = vty_can_receive,
22d63f
+    .fd_read = vty_receive,
22d63f
+};
22d63f
+
22d63f
 static int spapr_vty_init(VIOsPAPRDevice *sdev)
22d63f
 {
22d63f
     VIOsPAPRVTYDevice *dev = (VIOsPAPRVTYDevice *)sdev;
22d63f
@@ -63,8 +68,7 @@ static int spapr_vty_init(VIOsPAPRDevice *sdev)
22d63f
         exit(1);
22d63f
     }
22d63f
 
22d63f
-    qemu_chr_add_handlers(dev->chardev, vty_can_receive,
22d63f
-                          vty_receive, NULL, dev);
22d63f
+    qemu_chr_add_handlers(dev->chardev, &vty_handlers, dev);
22d63f
 
22d63f
     return 0;
22d63f
 }
22d63f
diff --git a/hw/strongarm.c b/hw/strongarm.c
22d63f
index 4385515..3567218 100644
22d63f
--- a/hw/strongarm.c
22d63f
+++ b/hw/strongarm.c
22d63f
@@ -1199,6 +1199,12 @@ static const MemoryRegionOps strongarm_uart_ops = {
22d63f
     .endianness = DEVICE_NATIVE_ENDIAN,
22d63f
 };
22d63f
 
22d63f
+static const QemuChrHandlers strongarm_uart_handlers = {
22d63f
+    .fd_can_read = strongarm_uart_can_receive,
22d63f
+    .fd_read = strongarm_uart_receive,
22d63f
+    .fd_event = strongarm_uart_event,
22d63f
+};
22d63f
+
22d63f
 static int strongarm_uart_init(SysBusDevice *dev)
22d63f
 {
22d63f
     StrongARMUARTState *s = FROM_SYSBUS(StrongARMUARTState, dev);
22d63f
@@ -1211,11 +1217,7 @@ static int strongarm_uart_init(SysBusDevice *dev)
22d63f
     s->tx_timer = qemu_new_timer_ns(vm_clock, strongarm_uart_tx, s);
22d63f
 
22d63f
     if (s->chr) {
22d63f
-        qemu_chr_add_handlers(s->chr,
22d63f
-                        strongarm_uart_can_receive,
22d63f
-                        strongarm_uart_receive,
22d63f
-                        strongarm_uart_event,
22d63f
-                        s);
22d63f
+        qemu_chr_add_handlers(s->chr, &strongarm_uart_handlers, s);
22d63f
     }
22d63f
 
22d63f
     return 0;
22d63f
diff --git a/hw/usb/dev-serial.c b/hw/usb/dev-serial.c
22d63f
index 99b19df..7307ad2 100644
22d63f
--- a/hw/usb/dev-serial.c
22d63f
+++ b/hw/usb/dev-serial.c
22d63f
@@ -414,7 +414,7 @@ static void usb_serial_handle_destroy(USBDevice *dev)
22d63f
 {
22d63f
     USBSerialState *s = (USBSerialState *)dev;
22d63f
 
22d63f
-    qemu_chr_add_handlers(s->cs, NULL, NULL, NULL, NULL);
22d63f
+    qemu_chr_add_handlers(s->cs, NULL, NULL);
22d63f
 }
22d63f
 
22d63f
 static int usb_serial_can_read(void *opaque)
22d63f
@@ -478,6 +478,12 @@ static void usb_serial_event(void *opaque, int event)
22d63f
     }
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers usb_serial_handlers = {
22d63f
+    .fd_can_read = usb_serial_can_read,
22d63f
+    .fd_read = usb_serial_read,
22d63f
+    .fd_event = usb_serial_event,
22d63f
+};
22d63f
+
22d63f
 static int usb_serial_initfn(USBDevice *dev)
22d63f
 {
22d63f
     USBSerialState *s = DO_UPCAST(USBSerialState, dev, dev);
22d63f
@@ -491,8 +497,7 @@ static int usb_serial_initfn(USBDevice *dev)
22d63f
         return -1;
22d63f
     }
22d63f
 
22d63f
-    qemu_chr_add_handlers(s->cs, usb_serial_can_read, usb_serial_read,
22d63f
-                          usb_serial_event, s);
22d63f
+    qemu_chr_add_handlers(s->cs, &usb_serial_handlers, s);
22d63f
     usb_serial_handle_reset(dev);
22d63f
 
22d63f
     if (s->cs->opened && !dev->attached) {
22d63f
diff --git a/hw/usb/redirect.c b/hw/usb/redirect.c
22d63f
index 490c90f..c921d2d 100644
22d63f
--- a/hw/usb/redirect.c
22d63f
+++ b/hw/usb/redirect.c
22d63f
@@ -1037,6 +1037,12 @@ static void usbredir_chardev_event(void *opaque, int event)
22d63f
     }
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers usbredir_chr_handlers = {
22d63f
+    .fd_can_read = usbredir_chardev_can_read,
22d63f
+    .fd_read = usbredir_chardev_read,
22d63f
+    .fd_event = usbredir_chardev_event,
22d63f
+};
22d63f
+
22d63f
 /*
22d63f
  * init + destroy
22d63f
  */
22d63f
@@ -1088,8 +1094,7 @@ static int usbredir_initfn(USBDevice *udev)
22d63f
 
22d63f
     /* Let the backend know we are ready */
22d63f
     qemu_chr_fe_open(dev->cs);
22d63f
-    qemu_chr_add_handlers(dev->cs, usbredir_chardev_can_read,
22d63f
-                          usbredir_chardev_read, usbredir_chardev_event, dev);
22d63f
+    qemu_chr_add_handlers(dev->cs, &usbredir_chr_handlers, dev);
22d63f
 
22d63f
     qemu_add_vm_change_state_handler(usbredir_vm_state_change, dev);
22d63f
     add_boot_device_path(dev->bootindex, &udev->qdev, NULL);
22d63f
diff --git a/hw/virtio-console.c b/hw/virtio-console.c
22d63f
index cffee3d..066590c 100644
22d63f
--- a/hw/virtio-console.c
22d63f
+++ b/hw/virtio-console.c
22d63f
@@ -106,6 +106,12 @@ static void chr_event(void *opaque, int event)
22d63f
     }
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers chr_handlers = {
22d63f
+    .fd_can_read = chr_can_read,
22d63f
+    .fd_read = chr_read,
22d63f
+    .fd_event = chr_event,
22d63f
+};
22d63f
+
22d63f
 static int virtconsole_initfn(VirtIOSerialPort *port)
22d63f
 {
22d63f
     VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
22d63f
@@ -117,8 +123,7 @@ static int virtconsole_initfn(VirtIOSerialPort *port)
22d63f
     }
22d63f
 
22d63f
     if (vcon->chr) {
22d63f
-        qemu_chr_add_handlers(vcon->chr, chr_can_read, chr_read, chr_event,
22d63f
-                              vcon);
22d63f
+        qemu_chr_add_handlers(vcon->chr, &chr_handlers, vcon);
22d63f
     }
22d63f
 
22d63f
     return 0;
22d63f
diff --git a/hw/xen_console.c b/hw/xen_console.c
22d63f
index 9426d73..e9fcadc 100644
22d63f
--- a/hw/xen_console.c
22d63f
+++ b/hw/xen_console.c
22d63f
@@ -211,6 +211,11 @@ out:
22d63f
     return ret;
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers xencons_handlers = {
22d63f
+    .fd_can_read = xencons_can_receive,
22d63f
+    .fd_read = xencons_receive,
22d63f
+};
22d63f
+
22d63f
 static int con_initialise(struct XenDevice *xendev)
22d63f
 {
22d63f
     struct XenConsole *con = container_of(xendev, struct XenConsole, xendev);
22d63f
@@ -231,9 +236,9 @@ static int con_initialise(struct XenDevice *xendev)
22d63f
 	return -1;
22d63f
 
22d63f
     xen_be_bind_evtchn(&con->xendev);
22d63f
-    if (con->chr)
22d63f
-        qemu_chr_add_handlers(con->chr, xencons_can_receive, xencons_receive,
22d63f
-                              NULL, con);
22d63f
+    if (con->chr) {
22d63f
+        qemu_chr_add_handlers(con->chr, &xencons_handlers, con);
22d63f
+    }
22d63f
 
22d63f
     xen_be_printf(xendev, 1, "ring mfn %d, remote port %d, local port %d, limit %zd\n",
22d63f
 		  con->ring_ref,
22d63f
@@ -250,8 +255,9 @@ static void con_disconnect(struct XenDevice *xendev)
22d63f
     if (!xendev->dev) {
22d63f
         return;
22d63f
     }
22d63f
-    if (con->chr)
22d63f
-        qemu_chr_add_handlers(con->chr, NULL, NULL, NULL, NULL);
22d63f
+    if (con->chr) {
22d63f
+        qemu_chr_add_handlers(con->chr, NULL, NULL);
22d63f
+    }
22d63f
     xen_be_unbind_evtchn(&con->xendev);
22d63f
 
22d63f
     if (con->sring) {
22d63f
diff --git a/hw/xilinx_uartlite.c b/hw/xilinx_uartlite.c
22d63f
index d20fc41..6605fb1 100644
22d63f
--- a/hw/xilinx_uartlite.c
22d63f
+++ b/hw/xilinx_uartlite.c
22d63f
@@ -195,6 +195,12 @@ static void uart_event(void *opaque, int event)
22d63f
 
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers uart_handlers = {
22d63f
+    .fd_can_read = uart_can_rx,
22d63f
+    .fd_read = uart_rx,
22d63f
+    .fd_event = uart_event,
22d63f
+};
22d63f
+
22d63f
 static int xilinx_uartlite_init(SysBusDevice *dev)
22d63f
 {
22d63f
     struct xlx_uartlite *s = FROM_SYSBUS(typeof (*s), dev);
22d63f
@@ -207,8 +213,9 @@ static int xilinx_uartlite_init(SysBusDevice *dev)
22d63f
     sysbus_init_mmio(dev, &s->mmio);
22d63f
 
22d63f
     s->chr = qemu_char_get_next_serial();
22d63f
-    if (s->chr)
22d63f
-        qemu_chr_add_handlers(s->chr, uart_can_rx, uart_rx, uart_event, s);
22d63f
+    if (s->chr) {
22d63f
+        qemu_chr_add_handlers(s->chr, &uart_handlers, s);
22d63f
+    }
22d63f
     return 0;
22d63f
 }
22d63f
 
22d63f
diff --git a/monitor.c b/monitor.c
22d63f
index c0e32d6..ce0c90a 100644
22d63f
--- a/monitor.c
22d63f
+++ b/monitor.c
22d63f
@@ -4685,6 +4685,18 @@ static void sortcmdlist(void)
22d63f
  * End:
22d63f
  */
22d63f
 
22d63f
+static const QemuChrHandlers monitor_handlers = {
22d63f
+    .fd_can_read = monitor_can_read,
22d63f
+    .fd_read = monitor_read,
22d63f
+    .fd_event = monitor_event,
22d63f
+};
22d63f
+
22d63f
+static const QemuChrHandlers monitor_control_handlers = {
22d63f
+    .fd_can_read = monitor_can_read,
22d63f
+    .fd_read = monitor_control_read,
22d63f
+    .fd_event = monitor_control_event,
22d63f
+};
22d63f
+
22d63f
 void monitor_init(CharDriverState *chr, int flags)
22d63f
 {
22d63f
     static int is_first_init = 1;
22d63f
@@ -4707,14 +4719,12 @@ void monitor_init(CharDriverState *chr, int flags)
22d63f
     if (monitor_ctrl_mode(mon)) {
22d63f
         mon->mc = g_malloc0(sizeof(MonitorControl));
22d63f
         /* Control mode requires special handlers */
22d63f
-        qemu_chr_add_handlers(chr, monitor_can_read, monitor_control_read,
22d63f
-                              monitor_control_event, mon);
22d63f
+        qemu_chr_add_handlers(chr, &monitor_control_handlers, mon);
22d63f
         qemu_chr_fe_set_echo(chr, true);
22d63f
 
22d63f
         json_message_parser_init(&mon->mc->parser, handle_qmp_command);
22d63f
     } else {
22d63f
-        qemu_chr_add_handlers(chr, monitor_can_read, monitor_read,
22d63f
-                              monitor_event, mon);
22d63f
+        qemu_chr_add_handlers(chr, &monitor_handlers, mon);
22d63f
     }
22d63f
 
22d63f
     QLIST_INSERT_HEAD(&mon_list, mon, entry);
22d63f
diff --git a/net/slirp.c b/net/slirp.c
22d63f
index afb52c3..07ae92f 100644
22d63f
--- a/net/slirp.c
22d63f
+++ b/net/slirp.c
22d63f
@@ -594,6 +594,11 @@ static void guestfwd_read(void *opaque, const uint8_t *buf, int size)
22d63f
     slirp_socket_recv(fwd->slirp, fwd->server, fwd->port, buf, size);
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers guestfwd_handlers = {
22d63f
+    .fd_can_read = guestfwd_can_read,
22d63f
+    .fd_read = guestfwd_read,
22d63f
+};
22d63f
+
22d63f
 static int slirp_guestfwd(SlirpState *s, const char *config_str,
22d63f
                           int legacy_format)
22d63f
 {
22d63f
@@ -659,8 +664,7 @@ static int slirp_guestfwd(SlirpState *s, const char *config_str,
22d63f
         fwd->port = port;
22d63f
         fwd->slirp = s->slirp;
22d63f
 
22d63f
-        qemu_chr_add_handlers(fwd->hd, guestfwd_can_read, guestfwd_read,
22d63f
-                              NULL, fwd);
22d63f
+        qemu_chr_add_handlers(fwd->hd, &guestfwd_handlers, fwd);
22d63f
     }
22d63f
     return 0;
22d63f
 
22d63f
diff --git a/qemu-char.c b/qemu-char.c
22d63f
index 77776dc..97247fb 100644
22d63f
--- a/qemu-char.c
22d63f
+++ b/qemu-char.c
22d63f
@@ -193,19 +193,26 @@ void qemu_chr_fe_printf(CharDriverState *s, const char *fmt, ...)
22d63f
     va_end(ap);
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers null_handlers = {
22d63f
+    /* All handlers are initialised to NULL */
22d63f
+};
22d63f
+
22d63f
 void qemu_chr_add_handlers(CharDriverState *s,
22d63f
-                           IOCanReadHandler *fd_can_read,
22d63f
-                           IOReadHandler *fd_read,
22d63f
-                           IOEventHandler *fd_event,
22d63f
-                           void *opaque)
22d63f
+                           const QemuChrHandlers *handlers, void *opaque)
22d63f
 {
22d63f
-    if (!opaque && !fd_can_read && !fd_read && !fd_event) {
22d63f
+    if (!s) {
22d63f
+        return;
22d63f
+    }
22d63f
+    if (!opaque && !handlers) {
22d63f
         /* chr driver being released. */
22d63f
         ++s->avail_connections;
22d63f
     }
22d63f
-    s->chr_can_read = fd_can_read;
22d63f
-    s->chr_read = fd_read;
22d63f
-    s->chr_event = fd_event;
22d63f
+    if (!handlers) {
22d63f
+        handlers = &null_handlers;
22d63f
+    }
22d63f
+    s->chr_can_read = handlers->fd_can_read;
22d63f
+    s->chr_read = handlers->fd_read;
22d63f
+    s->chr_event = handlers->fd_event;
22d63f
     s->handler_opaque = opaque;
22d63f
     if (s->chr_update_read_handler)
22d63f
         s->chr_update_read_handler(s);
22d63f
@@ -443,6 +450,12 @@ static void mux_chr_event(void *opaque, int event)
22d63f
         mux_chr_send_event(d, i, event);
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers mux_chr_handlers = {
22d63f
+    .fd_can_read = mux_chr_can_read,
22d63f
+    .fd_read = mux_chr_read,
22d63f
+    .fd_event = mux_chr_event,
22d63f
+};
22d63f
+
22d63f
 static void mux_chr_update_read_handler(CharDriverState *chr)
22d63f
 {
22d63f
     MuxDriver *d = chr->opaque;
22d63f
@@ -457,8 +470,7 @@ static void mux_chr_update_read_handler(CharDriverState *chr)
22d63f
     d->chr_event[d->mux_cnt] = chr->chr_event;
22d63f
     /* Fix up the real driver with mux routines */
22d63f
     if (d->mux_cnt == 0) {
22d63f
-        qemu_chr_add_handlers(d->drv, mux_chr_can_read, mux_chr_read,
22d63f
-                              mux_chr_event, chr);
22d63f
+        qemu_chr_add_handlers(d->drv, &mux_chr_handlers, chr);
22d63f
     }
22d63f
     if (d->focus != -1) {
22d63f
         mux_chr_send_event(d, d->focus, CHR_EVENT_MUX_OUT);
22d63f
diff --git a/qemu-char.h b/qemu-char.h
22d63f
index a121e04..ff206cb 100644
22d63f
--- a/qemu-char.h
22d63f
+++ b/qemu-char.h
22d63f
@@ -223,10 +223,15 @@ void qemu_chr_be_write(CharDriverState *s, uint8_t *buf, int len);
22d63f
  */
22d63f
 void qemu_chr_be_event(CharDriverState *s, int event);
22d63f
 
22d63f
-void qemu_chr_add_handlers(CharDriverState *s,
22d63f
-                           IOCanReadHandler *fd_can_read,
22d63f
-                           IOReadHandler *fd_read,
22d63f
-                           IOEventHandler *fd_event,
22d63f
+
22d63f
+typedef struct QemuChrHandlers {
22d63f
+    IOCanReadHandler *fd_can_read;
22d63f
+    IOReadHandler *fd_read;
22d63f
+    IOHandler *fd_write_unblocked;
22d63f
+    IOEventHandler *fd_event;
22d63f
+} QemuChrHandlers;
22d63f
+
22d63f
+void qemu_chr_add_handlers(CharDriverState *s, const QemuChrHandlers *handlers,
22d63f
                            void *opaque);
22d63f
 
22d63f
 void qemu_chr_generic_open(CharDriverState *s);
22d63f
diff --git a/qtest.c b/qtest.c
22d63f
index fbfab4e..4ab5b69 100644
22d63f
--- a/qtest.c
22d63f
+++ b/qtest.c
22d63f
@@ -416,6 +416,13 @@ static void qtest_event(void *opaque, int event)
22d63f
     }
22d63f
 }
22d63f
 
22d63f
+static const QemuChrHandlers test_handlers = {
22d63f
+    .fd_can_read = qtest_can_read,
22d63f
+    .fd_read = qtest_read,
22d63f
+    .fd_event = qtest_event,
22d63f
+};
22d63f
+
22d63f
+
22d63f
 int qtest_init(void)
22d63f
 {
22d63f
     CharDriverState *chr;
22d63f
@@ -425,7 +432,7 @@ int qtest_init(void)
22d63f
     configure_icount("0");
22d63f
     chr = qemu_chr_new("qtest", qtest_chrdev, NULL);
22d63f
 
22d63f
-    qemu_chr_add_handlers(chr, qtest_can_read, qtest_read, qtest_event, chr);
22d63f
+    qemu_chr_add_handlers(chr, &test_handlers, chr);
22d63f
     qemu_chr_fe_set_echo(chr, true);
22d63f
 
22d63f
     inbuf = g_string_new("");
22d63f
-- 
6986e1
1.8.1
22d63f