aboutsummaryrefslogtreecommitdiff
path: root/hw
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2016-10-22 10:55:22 +0300
committerPaolo Bonzini <pbonzini@redhat.com>2017-01-27 18:07:59 +0100
commitd5cafc733d21167fce7fcc3b45530ecb1f878e09 (patch)
treeaa1a5e2357814a467a8c5f4cba3bfd58c8007b8d /hw
parent41ac54b253f41df924c350ef63564df8e1d8ad88 (diff)
bt: use qemu_chr_alloc()
Use common allocator for CharDriverState. Rename the now untouched parent field. 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 <marcandre.lureau@redhat.com> Reviewed-by: Eric Blake <eblake@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'hw')
-rw-r--r--hw/bt/hci-csr.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/hw/bt/hci-csr.c b/hw/bt/hci-csr.c
index bf2deb0497..e2c78b8720 100644
--- a/hw/bt/hci-csr.c
+++ b/hw/bt/hci-csr.c
@@ -26,9 +26,10 @@
#include "hw/irq.h"
#include "sysemu/bt.h"
#include "hw/bt.h"
+#include "qapi/error.h"
struct csrhci_s {
- CharDriverState chr;
+ CharDriverState parent;
int enable;
qemu_irq *pins;
int pin_state;
@@ -78,7 +79,8 @@ enum {
static inline void csrhci_fifo_wake(struct csrhci_s *s)
{
- CharBackend *be = s->chr.be;
+ CharDriverState *chr = (CharDriverState *)s;
+ CharBackend *be = chr->be;
if (!s->enable || !s->out_len)
return;
@@ -468,10 +470,15 @@ CharDriverState *uart_hci_init(void)
.chr_write = csrhci_write,
.chr_ioctl = csrhci_ioctl,
};
- struct csrhci_s *s = (struct csrhci_s *)
- g_malloc0(sizeof(struct csrhci_s));
+ Error *err = NULL;
+ ChardevCommon common = { 0, };
+ CharDriverState *chr = qemu_chr_alloc(&hci_driver, &common, &err);
+ struct csrhci_s *s = (struct csrhci_s *)chr;
- s->chr.driver = &hci_driver;
+ if (err) {
+ error_report_err(err);
+ return NULL;
+ }
s->hci = qemu_next_hci();
s->hci->opaque = s;
@@ -482,5 +489,5 @@ CharDriverState *uart_hci_init(void)
s->pins = qemu_allocate_irqs(csrhci_pins, s, __csrhci_pins);
csrhci_reset(s);
- return &s->chr;
+ return chr;
}