Patchwork [PATCHv2,4/5] virtio-balloon: remove layout assumptions

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

Comments

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

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

Patch

diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index f8ccc00..21687e3 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -43,7 +43,7 @@  typedef struct VirtIOBalloon
 
 static VirtIOBalloon *to_virtio_balloon(VirtIODevice *vdev)
 {
-    return (VirtIOBalloon *)vdev;
+    return container_of(vdev, VirtIOBalloon, vdev);
 }
 
 static void balloon_page(void *addr, int deflate)
@@ -165,7 +165,7 @@  static void complete_stats_request(VirtIOBalloon *vb)
 
 static void virtio_balloon_receive_stats(VirtIODevice *vdev, VirtQueue *vq)
 {
-    VirtIOBalloon *s = DO_UPCAST(VirtIOBalloon, vdev, vdev);
+    VirtIOBalloon *s = to_virtio_balloon(vdev);
     VirtQueueElement *elem = &s->stats_vq_elem;
     VirtIOBalloonStat stat;
     size_t offset = 0;