From 41ac54b253f41df924c350ef63564df8e1d8ad88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Date: Fri, 21 Oct 2016 23:44:44 +0300 Subject: char: allocate CharDriverState as a single object MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use a single allocation for CharDriverState, this avoids extra allocations & pointers, and is a step towards more object-oriented CharDriver. Gtk console is a bit peculiar, gd_vc_chr_set_echo() used to have a temporary VirtualConsole to save the echo bit. Instead now, we consider whether vcd->console is set or not, and restore the echo bit saved in VCDriverState when calling gd_vc_vte_init(). The casts added are temporary, they are replaced with QOM type-safe macros in a later patch in this series. Signed-off-by: Marc-André Lureau Reviewed-by: Eric Blake Signed-off-by: Paolo Bonzini --- hw/bt/hci-csr.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'hw') diff --git a/hw/bt/hci-csr.c b/hw/bt/hci-csr.c index 9c3fb3c8f9..bf2deb0497 100644 --- a/hw/bt/hci-csr.c +++ b/hw/bt/hci-csr.c @@ -28,11 +28,11 @@ #include "hw/bt.h" struct csrhci_s { + CharDriverState chr; int enable; qemu_irq *pins; int pin_state; int modem_state; - CharDriverState chr; #define FIFO_LEN 4096 int out_start; int out_len; @@ -314,7 +314,7 @@ static void csrhci_ready_for_next_inpkt(struct csrhci_s *s) static int csrhci_write(struct CharDriverState *chr, const uint8_t *buf, int len) { - struct csrhci_s *s = (struct csrhci_s *) chr->opaque; + struct csrhci_s *s = (struct csrhci_s *)chr; int total = 0; if (!s->enable) @@ -387,7 +387,7 @@ static void csrhci_out_hci_packet_acl(void *opaque, static int csrhci_ioctl(struct CharDriverState *chr, int cmd, void *arg) { QEMUSerialSetParams *ssp; - struct csrhci_s *s = (struct csrhci_s *) chr->opaque; + struct csrhci_s *s = (struct csrhci_s *) chr; int prev_state = s->modem_state; switch (cmd) { @@ -455,7 +455,7 @@ static void csrhci_pins(void *opaque, int line, int level) qemu_irq *csrhci_pins_get(CharDriverState *chr) { - struct csrhci_s *s = (struct csrhci_s *) chr->opaque; + struct csrhci_s *s = (struct csrhci_s *) chr; return s->pins; } @@ -463,6 +463,7 @@ qemu_irq *csrhci_pins_get(CharDriverState *chr) CharDriverState *uart_hci_init(void) { static const CharDriver hci_driver = { + .instance_size = sizeof(struct csrhci_s), .kind = -1, .chr_write = csrhci_write, .chr_ioctl = csrhci_ioctl, @@ -470,7 +471,6 @@ CharDriverState *uart_hci_init(void) struct csrhci_s *s = (struct csrhci_s *) g_malloc0(sizeof(struct csrhci_s)); - s->chr.opaque = s; s->chr.driver = &hci_driver; s->hci = qemu_next_hci(); -- cgit v1.2.3