Patchwork kill VirtIOSerialDevice

login
register
mail settings
Submitter Gerd Hoffmann
Date Jan. 27, 2011, 2:23 p.m.
Message ID <1296138225-29408-1-git-send-email-kraxel@redhat.com>
Download mbox | patch
Permalink /patch/80701/
State New
Headers show

Comments

Gerd Hoffmann - Jan. 27, 2011, 2:23 p.m.
VirtIOSerialDevice is like VirtIOSerialPort with just the first two
fields, which makes it pretty pointless.  Using VirtIOSerialPort
directly works equally well and is less confusing.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/virtio-console.c    |   13 +++----------
 hw/virtio-serial-bus.c |   15 ++++++---------
 hw/virtio-serial.h     |    9 ++-------
 3 files changed, 11 insertions(+), 26 deletions(-)

Patch

diff --git a/hw/virtio-console.c b/hw/virtio-console.c
index caea11f..5ec7fcc 100644
--- a/hw/virtio-console.c
+++ b/hw/virtio-console.c
@@ -59,13 +59,10 @@  static void chr_event(void *opaque, int event)
 }
 
 /* Virtio Console Ports */
-static int virtconsole_initfn(VirtIOSerialDevice *dev)
+static int virtconsole_initfn(VirtIOSerialPort *port)
 {
-    VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, &dev->qdev);
     VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
 
-    port->info = dev->info;
-
     port->is_console = true;
 
     if (vcon->chr) {
@@ -76,9 +73,8 @@  static int virtconsole_initfn(VirtIOSerialDevice *dev)
     return 0;
 }
 
-static int virtconsole_exitfn(VirtIOSerialDevice *dev)
+static int virtconsole_exitfn(VirtIOSerialPort *port)
 {
-    VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, &dev->qdev);
     VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
 
     if (vcon->chr) {
@@ -110,13 +106,10 @@  static void virtconsole_register(void)
 device_init(virtconsole_register)
 
 /* Generic Virtio Serial Ports */
-static int virtserialport_initfn(VirtIOSerialDevice *dev)
+static int virtserialport_initfn(VirtIOSerialPort *port)
 {
-    VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, &dev->qdev);
     VirtConsole *vcon = DO_UPCAST(VirtConsole, port, port);
 
-    port->info = dev->info;
-
     if (vcon->chr) {
         qemu_chr_add_handlers(vcon->chr, chr_can_read, chr_read, chr_event,
                               vcon);
diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index b728040..94f5c8e 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -578,8 +578,7 @@  static VirtIOSerialBus *virtser_bus_new(DeviceState *dev)
 
 static void virtser_bus_dev_print(Monitor *mon, DeviceState *qdev, int indent)
 {
-    VirtIOSerialDevice *dev = DO_UPCAST(VirtIOSerialDevice, qdev, qdev);
-    VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, &dev->qdev);
+    VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev);
 
     monitor_printf(mon, "%*s dev-prop-int: id: %u\n",
                    indent, "", port->id);
@@ -641,9 +640,8 @@  static void remove_port(VirtIOSerial *vser, uint32_t port_id)
 
 static int virtser_port_qdev_init(DeviceState *qdev, DeviceInfo *base)
 {
-    VirtIOSerialDevice *dev = DO_UPCAST(VirtIOSerialDevice, qdev, qdev);
+    VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev);
     VirtIOSerialPortInfo *info = DO_UPCAST(VirtIOSerialPortInfo, qdev, base);
-    VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, &dev->qdev);
     VirtIOSerialBus *bus = DO_UPCAST(VirtIOSerialBus, qbus, qdev->parent_bus);
     int ret;
     bool plugging_port0;
@@ -681,8 +679,8 @@  static int virtser_port_qdev_init(DeviceState *qdev, DeviceInfo *base)
         return -1;
     }
 
-    dev->info = info;
-    ret = info->init(dev);
+    port->info = info;
+    ret = info->init(port);
     if (ret) {
         return ret;
     }
@@ -709,8 +707,7 @@  static int virtser_port_qdev_init(DeviceState *qdev, DeviceInfo *base)
 
 static int virtser_port_qdev_exit(DeviceState *qdev)
 {
-    VirtIOSerialDevice *dev = DO_UPCAST(VirtIOSerialDevice, qdev, qdev);
-    VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, &dev->qdev);
+    VirtIOSerialPort *port = DO_UPCAST(VirtIOSerialPort, dev, qdev);
     VirtIOSerial *vser = port->vser;
 
     remove_port(port->vser, port->id);
@@ -718,7 +715,7 @@  static int virtser_port_qdev_exit(DeviceState *qdev)
     QTAILQ_REMOVE(&vser->ports, port, next);
 
     if (port->info->exit)
-        port->info->exit(dev);
+        port->info->exit(port);
 
     return 0;
 }
diff --git a/hw/virtio-serial.h b/hw/virtio-serial.h
index ff08c40..22d6ff8 100644
--- a/hw/virtio-serial.h
+++ b/hw/virtio-serial.h
@@ -62,11 +62,6 @@  typedef struct VirtIOSerialBus VirtIOSerialBus;
 typedef struct VirtIOSerialPort VirtIOSerialPort;
 typedef struct VirtIOSerialPortInfo VirtIOSerialPortInfo;
 
-typedef struct VirtIOSerialDevice {
-    DeviceState qdev;
-    VirtIOSerialPortInfo *info;
-} VirtIOSerialDevice;
-
 /*
  * This is the state that's shared between all the ports.  Some of the
  * state is configurable via command-line options. Some of it can be
@@ -119,12 +114,12 @@  struct VirtIOSerialPortInfo {
      * The per-port (or per-app) init function that's called when a
      * new device is found on the bus.
      */
-    int (*init)(VirtIOSerialDevice *dev);
+    int (*init)(VirtIOSerialPort *dev);
     /*
      * Per-port exit function that's called when a port gets
      * hot-unplugged or removed.
      */
-    int (*exit)(VirtIOSerialDevice *dev);
+    int (*exit)(VirtIOSerialPort *dev);
 
     /* Callbacks for guest events */
         /* Guest opened device. */