Patchwork [PATCHv2,3/5] virtio-serial: remove struct layout assumptions

login
register
mail settings
Submitter Michael S. Tsirkin
Date March 18, 2010, 9:42 a.m.
Message ID <b6f9e998d89ea08caba9892c804d9c9b1bf963ca.1268905075.git.mst@redhat.com>
Download mbox | patch
Permalink /patch/48016/
State New
Headers show

Comments

Michael S. Tsirkin - March 18, 2010, 9:42 a.m.
Use container_of and remove assumption that vdev
is 1st member of structure.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 hw/virtio-serial-bus.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

Patch

diff --git a/hw/virtio-serial-bus.c b/hw/virtio-serial-bus.c
index cf6f979..cba60f1 100644
--- a/hw/virtio-serial-bus.c
+++ b/hw/virtio-serial-bus.c
@@ -282,7 +282,7 @@  static void control_out(VirtIODevice *vdev, VirtQueue *vq)
     VirtQueueElement elem;
     VirtIOSerial *vser;
 
-    vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
+    vser = container_of(vdev, VirtIOSerial, vdev);
 
     while (virtqueue_pop(vq, &elem)) {
         handle_control_message(vser, elem.out_sg[0].iov_base);
@@ -297,7 +297,7 @@  static void handle_output(VirtIODevice *vdev, VirtQueue *vq)
     VirtIOSerial *vser;
     VirtQueueElement elem;
 
-    vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
+    vser = container_of(vdev, VirtIOSerial, vdev);
 
     while (virtqueue_pop(vq, &elem)) {
         VirtIOSerialPort *port;
@@ -335,7 +335,7 @@  static void handle_input(VirtIODevice *vdev, VirtQueue *vq)
 
 static uint32_t get_features(VirtIODevice *vdev, uint32_t features)
 {
-    VirtIOSerial *vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
+    VirtIOSerial *vser = container_of(vdev, VirtIOSerial, vdev);
     if (vser->bus->max_nr_ports > 1) {
         features |= (1 << VIRTIO_CONSOLE_F_MULTIPORT);
     }
@@ -347,7 +347,7 @@  static void get_config(VirtIODevice *vdev, uint8_t *config_data)
 {
     VirtIOSerial *vser;
 
-    vser = DO_UPCAST(VirtIOSerial, vdev, vdev);
+    vser = container_of(vdev, VirtIOSerial, vdev);
     memcpy(config_data, &vser->config, sizeof(struct virtio_console_config));
 }