diff options
author | David Gibson <david@gibson.dropbear.id.au> | 2012-04-12 01:36:34 -0400 |
---|---|---|
committer | Michael S. Tsirkin <mst@redhat.com> | 2012-04-15 04:51:05 -0400 |
commit | 1a87228f5f1d316002c7c161316f5524592be766 (patch) | |
tree | 3c852fe87074cdc40a3435e3c18233be3b3f23e3 /drivers/virtio | |
parent | c0aa3e0916d7e531e69b02e426f7162dfb1c6c0f (diff) |
virtio_balloon: Fix endian bug
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>
Diffstat (limited to 'drivers/virtio')
-rw-r--r-- | drivers/virtio/virtio_balloon.c | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/drivers/virtio/virtio_balloon.c b/drivers/virtio/virtio_balloon.c index 05f0a80818a2..9e95ca602006 100644 --- a/drivers/virtio/virtio_balloon.c +++ b/drivers/virtio/virtio_balloon.c | |||
@@ -234,11 +234,14 @@ static void virtballoon_changed(struct virtio_device *vdev) | |||
234 | 234 | ||
235 | static inline s64 towards_target(struct virtio_balloon *vb) | 235 | static inline s64 towards_target(struct virtio_balloon *vb) |
236 | { | 236 | { |
237 | u32 v; | 237 | __le32 v; |
238 | s64 target; | ||
239 | |||
238 | vb->vdev->config->get(vb->vdev, | 240 | vb->vdev->config->get(vb->vdev, |
239 | offsetof(struct virtio_balloon_config, num_pages), | 241 | offsetof(struct virtio_balloon_config, num_pages), |
240 | &v, sizeof(v)); | 242 | &v, sizeof(v)); |
241 | return (s64)v - vb->num_pages; | 243 | target = le32_to_cpu(v); |
244 | return target - vb->num_pages; | ||
242 | } | 245 | } |
243 | 246 | ||
244 | static void update_balloon_size(struct virtio_balloon *vb) | 247 | static void update_balloon_size(struct virtio_balloon *vb) |