lguest: Read length of device_cap later
authorPaul Bolle <pebolle@tiscali.nl>
Thu, 3 Mar 2016 12:01:40 +0000 (13:01 +0100)
committerThomas Gleixner <tglx@linutronix.de>
Fri, 10 Jun 2016 09:39:09 +0000 (11:39 +0200)
Read the length of the capability with type VIRTIO_PCI_CAP_DEVICE_CFG
only when we're sure we're going to need it. Which is just before the
check whether the virtio console actually has an emerg_wr field.

Signed-off-by: Paul Bolle <pebolle@tiscali.nl>
Cc: Rusty Russell <rusty@rustcorp.com.au>
Cc: lguest@lists.ozlabs.org
Link: http://lkml.kernel.org/r/1457006501-5377-2-git-send-email-pebolle@tiscali.nl
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
arch/x86/lguest/boot.c

index 3847e736702e1153cc7e654087ca716d6b55d7da..146d11c8cf78c8b819158dd26cf3e6acd4f46ed4 100644 (file)
@@ -1258,7 +1258,7 @@ static void probe_pci_console(void)
                u8 vndr = read_pci_config_byte(0, 1, 0, cap);
                if (vndr == PCI_CAP_ID_VNDR) {
                        u8 type, bar;
-                       u32 offset, length;
+                       u32 offset;
 
                        type = read_pci_config_byte(0, 1, 0,
                            cap + offsetof(struct virtio_pci_cap, cfg_type));
@@ -1266,15 +1266,12 @@ static void probe_pci_console(void)
                            cap + offsetof(struct virtio_pci_cap, bar));
                        offset = read_pci_config(0, 1, 0,
                            cap + offsetof(struct virtio_pci_cap, offset));
-                       length = read_pci_config(0, 1, 0,
-                           cap + offsetof(struct virtio_pci_cap, length));
 
                        switch (type) {
                        case VIRTIO_PCI_CAP_DEVICE_CFG:
                                if (bar == 0) {
                                        device_cap = cap;
                                        device_offset = offset;
-                                       device_len = length;
                                }
                                break;
                        case VIRTIO_PCI_CAP_PCI_CFG:
@@ -1297,6 +1294,8 @@ static void probe_pci_console(void)
         * emerg_wr.  If it doesn't support VIRTIO_CONSOLE_F_EMERG_WRITE
         * it should ignore the access.
         */
+       device_len = read_pci_config(0, 1, 0,
+                       device_cap + offsetof(struct virtio_pci_cap, length));
        if (device_len < (offsetof(struct virtio_console_config, emerg_wr)
                          + sizeof(u32))) {
                printk(KERN_ERR "lguest: console missing emerg_wr field\n");