]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
virtio_balloon: Fix endian bug
authorDavid Gibson <david@gibson.dropbear.id.au>
Thu, 12 Apr 2012 05:36:34 +0000 (15:36 +1000)
committerMichael S. Tsirkin <mst@redhat.com>
Sun, 15 Apr 2012 08:51:05 +0000 (11:51 +0300)
Although virtio config space fields are usually in guest-native endian,
the spec for the virtio balloon device explicitly states that both fields
in its config space are little-endian.

However, the current virtio_balloon driver does not have a suitable endian
swap for the 'num_pages' field, although it does have one for the 'actual'
field.  This patch corrects the bug, adding sparse annotation while we're
at it.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
drivers/virtio/virtio_balloon.c

index 05f0a80818a2b1c202e2d5104ced13b9802287d0..9e95ca602006a2a6954387a7df7daf070422320a 100644 (file)
@@ -234,11 +234,14 @@ static void virtballoon_changed(struct virtio_device *vdev)
 
 static inline s64 towards_target(struct virtio_balloon *vb)
 {
-       u32 v;
+       __le32 v;
+       s64 target;
+
        vb->vdev->config->get(vb->vdev,
                              offsetof(struct virtio_balloon_config, num_pages),
                              &v, sizeof(v));
-       return (s64)v - vb->num_pages;
+       target = le32_to_cpu(v);
+       return target - vb->num_pages;
 }
 
 static void update_balloon_size(struct virtio_balloon *vb)