Patchwork [50/61] virtio-serial : cleanup : init and exit functions.

login
register
mail settings
Submitter fred.konrad@greensocs.com
Date Jan. 7, 2013, 6:41 p.m.
Message ID <1357584074-10852-51-git-send-email-fred.konrad@greensocs.com>
Download mbox | patch
Permalink /patch/210065/
State New
Headers show

Comments

fred.konrad@greensocs.com - Jan. 7, 2013, 6:41 p.m.
From: KONRAD Frederic <fred.konrad@greensocs.com>

This remove old init and exit function as they are no longer needed.
This shouldn't been applyied before virtio-serial-pci and
virtio-serial-s390 refactoring.

Signed-off-by: KONRAD Frederic <fred.konrad@greensocs.com>
---
 hw/virtio-serial-bus.c | 94 ++++++++++++--------------------------------------
 1 file changed, 22 insertions(+), 72 deletions(-)

Patch

diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index 5186191..f1c7d75 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -904,51 +904,39 @@  static int virtser_port_qdev_exit(DeviceState *qdev)
     return 0;
 }
 
-static VirtIODevice *virtio_serial_common_init(DeviceState *dev,
-                                               virtio_serial_conf *conf,
-                                               VirtIODevice **pvdev)
+static int virtio_serial_device_init(VirtIODevice *vdev)
 {
-    VirtIOSerial *vser;
-    VirtIODevice *vdev = *pvdev;
+    DeviceState *qdev = DEVICE(vdev);
+    VirtIOSerial *vser = VIRTIO_SERIAL(vdev);
     uint32_t i, max_supported_ports;
 
-    if (!conf->max_virtserial_ports)
-        return NULL;
+    if (!vser->serial.max_virtserial_ports) {
+        return -1;
+    }
 
     /* Each port takes 2 queues, and one pair is for the control queue */
     max_supported_ports = VIRTIO_PCI_QUEUE_MAX / 2 - 1;
 
-    if (conf->max_virtserial_ports > max_supported_ports) {
+    if (vser->serial.max_virtserial_ports > max_supported_ports) {
         error_report("maximum ports supported: %u", max_supported_ports);
-        return NULL;
+        return -1;
     }
 
-    /*
-     * We have two cases here : the old virtio-serial-pci device, and the
-     * refactored virtio-serial.
-     */
-    if (vdev == NULL) {
-        /* virtio-serial-pci */
-        vdev = virtio_common_init("virtio-serial", VIRTIO_ID_CONSOLE,
-                                  sizeof(struct virtio_console_config),
-                                  sizeof(VirtIOSerial));
-        vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
-    } else {
-        /* virtio-serial */
-        virtio_init(vdev, "virtio-serial", VIRTIO_ID_CONSOLE,
-                    sizeof(struct virtio_console_config));
-        vser = VIRTIO_SERIAL(vdev);
-    }
+
+    virtio_init(vdev, "virtio-serial", VIRTIO_ID_CONSOLE,
+                sizeof(struct virtio_console_config));
 
     /* Spawn a new virtio-serial bus on which the ports will ride as devices */
-    qbus_create_inplace(&vser->bus.qbus, TYPE_VIRTIO_SERIAL_BUS, dev, NULL);
+    qbus_create_inplace(&vser->bus.qbus, TYPE_VIRTIO_SERIAL_BUS, qdev, NULL);
     vser->bus.qbus.allow_hotplug = 1;
     vser->bus.vser = vser;
     QTAILQ_INIT(&vser->ports);
 
-    vser->bus.max_nr_ports = conf->max_virtserial_ports;
-    vser->ivqs = g_malloc(conf->max_virtserial_ports * sizeof(VirtQueue *));
-    vser->ovqs = g_malloc(conf->max_virtserial_ports * sizeof(VirtQueue *));
+    vser->bus.max_nr_ports = vser->serial.max_virtserial_ports;
+    vser->ivqs = g_malloc(vser->serial.max_virtserial_ports
+                          * sizeof(VirtQueue *));
+    vser->ovqs = g_malloc(vser->serial.max_virtserial_ports
+                          * sizeof(VirtQueue *));
 
     /* Add a queue for host to guest transfers for port 0 (backward compat) */
     vser->ivqs[0] = virtio_add_queue(vdev, 128, handle_input);
@@ -973,8 +961,8 @@  static VirtIODevice *virtio_serial_common_init(DeviceState *dev,
         vser->ovqs[i] = virtio_add_queue(vdev, 128, handle_output);
     }
 
-    vser->config.max_nr_ports = tswap32(conf->max_virtserial_ports);
-    vser->ports_map = g_malloc0(((conf->max_virtserial_ports + 31) / 32)
+    vser->config.max_nr_ports = tswap32(vser->serial.max_virtserial_ports);
+    vser->ports_map = g_malloc0(((vser->serial.max_virtserial_ports + 31) / 32)
         * sizeof(vser->ports_map[0]));
     /*
      * Reserve location 0 for a console port for backward compat
@@ -988,7 +976,7 @@  static VirtIODevice *virtio_serial_common_init(DeviceState *dev,
     vser->vdev.set_status = set_status;
     vser->vdev.reset = vser_reset;
 
-    vser->qdev = dev;
+    vser->qdev = qdev;
 
     vser->post_load = NULL;
 
@@ -996,38 +984,10 @@  static VirtIODevice *virtio_serial_common_init(DeviceState *dev,
      * Register for the savevm section with the virtio-console name
      * to preserve backward compat
      */
-    register_savevm(dev, "virtio-console", -1, 3, virtio_serial_save,
+    register_savevm(qdev, "virtio-console", -1, 3, virtio_serial_save,
                     virtio_serial_load, vser);
 
-    return vdev;
-}
-
-/*
- * The two following functions will be cleaned up at the end.
- */
-
-VirtIODevice *virtio_serial_init(DeviceState *dev, virtio_serial_conf *conf)
-{
-    VirtIODevice *vdev = NULL;
-    return virtio_serial_common_init(dev, conf, &vdev);
-}
-
-void virtio_serial_exit(VirtIODevice *vdev)
-{
-    VirtIOSerial *vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
-
-    unregister_savevm(vser->qdev, "virtio-console", vser);
-
-    g_free(vser->ivqs);
-    g_free(vser->ovqs);
-    g_free(vser->ports_map);
-    if (vser->post_load) {
-        g_free(vser->post_load->connected);
-        qemu_del_timer(vser->post_load->timer);
-        qemu_free_timer(vser->post_load->timer);
-        g_free(vser->post_load);
-    }
-    virtio_cleanup(vdev);
+    return 0;
 }
 
 static void virtio_serial_port_class_init(ObjectClass *klass, void *data)
@@ -1055,16 +1015,6 @@  void virtio_serial_set_conf(DeviceState *dev, virtio_serial_conf *serial)
     memcpy(&(s->serial), serial, sizeof(virtio_serial_conf));
 }
 
-static int virtio_serial_device_init(VirtIODevice *vdev)
-{
-    DeviceState *qdev = DEVICE(vdev);
-    VirtIOSerial *vser = VIRTIO_SERIAL(vdev);
-    if (virtio_serial_common_init(qdev, &(vser->serial), &vdev) == NULL) {
-        return -1;
-    }
-    return 0;
-}
-
 static int virtio_serial_device_exit(DeviceState *dev)
 {
     VirtIOSerial *vser = VIRTIO_SERIAL(dev);