From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757459AbcCCMBt (ORCPT ); Thu, 3 Mar 2016 07:01:49 -0500 Received: from lb3-smtp-cloud2.xs4all.net ([194.109.24.29]:48185 "EHLO lb3-smtp-cloud2.xs4all.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756802AbcCCMBq (ORCPT ); Thu, 3 Mar 2016 07:01:46 -0500 From: Paul Bolle To: Rusty Russell , Thomas Gleixner , Ingo Molnar , "H. Peter Anvin" Cc: x86@kernel.org, lguest@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] lguest: read length of device_cap later Date: Thu, 3 Mar 2016 13:01:40 +0100 Message-Id: <1457006501-5377-2-git-send-email-pebolle@tiscali.nl> X-Mailer: git-send-email 2.4.3 In-Reply-To: <1457006501-5377-1-git-send-email-pebolle@tiscali.nl> References: <1457006501-5377-1-git-send-email-pebolle@tiscali.nl> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- arch/x86/lguest/boot.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c index 4ba229ac3f4f..535e3197d0c7 100644 --- a/arch/x86/lguest/boot.c +++ b/arch/x86/lguest/boot.c @@ -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"); -- 2.4.3