virtio: mmio: fix signature checking for BE guests
authorMarc Zyngier <marc.zyngier@arm.com>
Tue, 5 Nov 2013 10:51:28 +0000 (21:21 +1030)
committerRusty Russell <rusty@rustcorp.com.au>
Thu, 7 Nov 2013 01:43:04 +0000 (12:13 +1030)
As virtio-mmio config registers are specified to be little-endian,
using readl() to read the magic value and then memcmp() to check it
fails on BE (as readl() has an implicit swab).

Fix it by encoding the magic value as an integer instead of a string.

Cc: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Marc Zyngier <marc.zyngier@arm.com>
Acked-by: Pawel Moll <pawel.moll@arm.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
drivers/virtio/virtio_mmio.c

index e9fdeb8..c600ccf 100644 (file)
@@ -471,7 +471,7 @@ static int virtio_mmio_probe(struct platform_device *pdev)
 
        /* Check magic value */
        magic = readl(vm_dev->base + VIRTIO_MMIO_MAGIC_VALUE);
-       if (memcmp(&magic, "virt", 4) != 0) {
+       if (magic != ('v' | 'i' << 8 | 'r' << 16 | 't' << 24)) {
                dev_warn(&pdev->dev, "Wrong magic value 0x%08lx!\n", magic);
                return -ENODEV;
        }