diff mbox

fix endianess when changing memory with balloon.

Message ID 1348259353-31417-1-git-send-email-victor@itoso.org
State New
Headers show

Commit Message

Victor Toso Sept. 21, 2012, 8:29 p.m. UTC
Signed-off-by: Victor Toso <victor@itoso.org>
---
 hw/virtio-balloon.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/hw/virtio-balloon.c b/hw/virtio-balloon.c
index dd1a650..9e0cd88 100644
--- a/hw/virtio-balloon.c
+++ b/hw/virtio-balloon.c
@@ -193,12 +193,15 @@  static void virtio_balloon_stat(void *opaque, BalloonInfo *info)
 static void virtio_balloon_to_target(void *opaque, ram_addr_t target)
 {
     VirtIOBalloon *dev = opaque;
+    uint32_t num_pages;
 
     if (target > ram_size) {
         target = ram_size;
     }
     if (target) {
-        dev->num_pages = (ram_size - target) >> VIRTIO_BALLOON_PFN_SHIFT;
+        num_pages = (ram_size - target) >> VIRTIO_BALLOON_PFN_SHIFT;
+        dev->num_pages = virtio_is_big_endian() ?
+            cpu_to_be32(num_pages): cpu_to_le32(num_pages);
         virtio_notify_config(&dev->vdev);
     }
 }