aboutsummaryrefslogtreecommitdiff
path: root/hw/char/spapr_vty.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2013-04-07 19:08:16 +0000
committerAlexander Graf <agraf@suse.de>2013-04-26 23:02:41 +0200
commitfd506b4f61cd22793f8c54a9adf5c69345792501 (patch)
treedc56e93e2f809255420ccf8b7248d8cd40ff7962 /hw/char/spapr_vty.c
parent9b00ea4906a618756bcd10f09d432780eab87782 (diff)
pseries: Convert VIO code to QOM style type safe(ish) casts
Curerntly the pseries VIO device code contains quite a few explicit uses of DO_UPCAST and plain C casts. This is (obviously) type unsafe, and not the conventional way of doing things in the QOM model. This patch converts the code to use the QOM convention of per-type macros to do verified casts with OBJECT_CHECK(). Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Alexander Graf <agraf@suse.de>
Diffstat (limited to 'hw/char/spapr_vty.c')
-rw-r--r--hw/char/spapr_vty.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/hw/char/spapr_vty.c b/hw/char/spapr_vty.c
index afcec1f182..2993848889 100644
--- a/hw/char/spapr_vty.c
+++ b/hw/char/spapr_vty.c
@@ -12,16 +12,20 @@ typedef struct VIOsPAPRVTYDevice {
uint8_t buf[VTERM_BUFSIZE];
} VIOsPAPRVTYDevice;
+#define TYPE_VIO_SPAPR_VTY_DEVICE "spapr-vty"
+#define VIO_SPAPR_VTY_DEVICE(obj) \
+ OBJECT_CHECK(VIOsPAPRVTYDevice, (obj), TYPE_VIO_SPAPR_VTY_DEVICE)
+
static int vty_can_receive(void *opaque)
{
- VIOsPAPRVTYDevice *dev = (VIOsPAPRVTYDevice *)opaque;
+ VIOsPAPRVTYDevice *dev = VIO_SPAPR_VTY_DEVICE(opaque);
return (dev->in - dev->out) < VTERM_BUFSIZE;
}
static void vty_receive(void *opaque, const uint8_t *buf, int size)
{
- VIOsPAPRVTYDevice *dev = (VIOsPAPRVTYDevice *)opaque;
+ VIOsPAPRVTYDevice *dev = VIO_SPAPR_VTY_DEVICE(opaque);
int i;
if ((dev->in == dev->out) && size) {
@@ -36,7 +40,7 @@ static void vty_receive(void *opaque, const uint8_t *buf, int size)
static int vty_getchars(VIOsPAPRDevice *sdev, uint8_t *buf, int max)
{
- VIOsPAPRVTYDevice *dev = (VIOsPAPRVTYDevice *)sdev;
+ VIOsPAPRVTYDevice *dev = VIO_SPAPR_VTY_DEVICE(sdev);
int n = 0;
while ((n < max) && (dev->out != dev->in)) {
@@ -48,7 +52,7 @@ static int vty_getchars(VIOsPAPRDevice *sdev, uint8_t *buf, int max)
void vty_putchars(VIOsPAPRDevice *sdev, uint8_t *buf, int len)
{
- VIOsPAPRVTYDevice *dev = (VIOsPAPRVTYDevice *)sdev;
+ VIOsPAPRVTYDevice *dev = VIO_SPAPR_VTY_DEVICE(sdev);
/* FIXME: should check the qemu_chr_fe_write() return value */
qemu_chr_fe_write(dev->chardev, buf, len);
@@ -56,7 +60,7 @@ void vty_putchars(VIOsPAPRDevice *sdev, uint8_t *buf, int len)
static int spapr_vty_init(VIOsPAPRDevice *sdev)
{
- VIOsPAPRVTYDevice *dev = (VIOsPAPRVTYDevice *)sdev;
+ VIOsPAPRVTYDevice *dev = VIO_SPAPR_VTY_DEVICE(sdev);
if (!dev->chardev) {
fprintf(stderr, "spapr-vty: Can't create vty without a chardev!\n");
@@ -151,7 +155,7 @@ static void spapr_vty_class_init(ObjectClass *klass, void *data)
}
static const TypeInfo spapr_vty_info = {
- .name = "spapr-vty",
+ .name = TYPE_VIO_SPAPR_VTY_DEVICE,
.parent = TYPE_VIO_SPAPR_DEVICE,
.instance_size = sizeof(VIOsPAPRVTYDevice),
.class_init = spapr_vty_class_init,
@@ -177,7 +181,7 @@ VIOsPAPRDevice *spapr_vty_get_default(VIOsPAPRBus *bus)
continue;
}
- sdev = DO_UPCAST(VIOsPAPRDevice, qdev, iter);
+ sdev = VIO_SPAPR_DEVICE(iter);
/* First VTY we've found, so it is selected for now */
if (!selected) {