Skip to content

Commit 1a87228

Browse files
dgibsonmstsirkin
authored andcommitted
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 <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent c0aa3e0 commit 1a87228

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

drivers/virtio/virtio_balloon.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,14 @@ static void virtballoon_changed(struct virtio_device *vdev)
234234

235235
static inline s64 towards_target(struct virtio_balloon *vb)
236236
{
237-
u32 v;
237+
__le32 v;
238+
s64 target;
239+
238240
vb->vdev->config->get(vb->vdev,
239241
offsetof(struct virtio_balloon_config, num_pages),
240242
&v, sizeof(v));
241-
return (s64)v - vb->num_pages;
243+
target = le32_to_cpu(v);
244+
return target - vb->num_pages;
242245
}
243246

244247
static void update_balloon_size(struct virtio_balloon *vb)

0 commit comments

Comments
 (0)