Patchwork [PATCHv2,2/5] virtio-net: remove layout assumptions

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

Comments

Michael S. Tsirkin - March 18, 2010, 9:42 a.m.
Use container_of so we do not depend on vdev being first member.

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

Patch

diff --git a/hw/virtio-net.c b/hw/virtio-net.c
index d962a75..ca843f8 100644
--- a/hw/virtio-net.c
+++ b/hw/virtio-net.c
@@ -64,7 +64,7 @@  typedef struct VirtIONet
 
 static VirtIONet *to_virtio_net(VirtIODevice *vdev)
 {
-    return (VirtIONet *)vdev;
+    return container_of(vdev, VirtIONet, vdev);
 }
 
 static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)
@@ -873,7 +873,7 @@  VirtIODevice *virtio_net_init(DeviceState *dev, NICConf *conf)
 
 void virtio_net_exit(VirtIODevice *vdev)
 {
-    VirtIONet *n = DO_UPCAST(VirtIONet, vdev, vdev);
+    VirtIONet *n = to_virtio_net(vdev);
 
     qemu_purge_queued_packets(&n->nic->nc);