From patchwork Wed Aug 31 16:21:42 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shyam Iyer X-Patchwork-Id: 1117272 X-Patchwork-Delegate: bhelgaas@google.com Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter2.kernel.org (8.14.4/8.14.4) with ESMTP id p7VGLqCS029188 for ; Wed, 31 Aug 2011 16:21:53 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756321Ab1HaQVw (ORCPT ); Wed, 31 Aug 2011 12:21:52 -0400 Received: from mail-vw0-f46.google.com ([209.85.212.46]:49900 "EHLO mail-vw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756233Ab1HaQVv (ORCPT ); Wed, 31 Aug 2011 12:21:51 -0400 Received: by vws1 with SMTP id 1so674925vws.19 for ; Wed, 31 Aug 2011 09:21:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:date:message-id:x-mailer; bh=X8Ap1CTTDGCy7EGMF9Por/RhO0I5eUp0AWSKWjzDmWc=; b=ZfK7dNQH62ZOlqfPlT1Ox5f+A5RGFS5GA6A808lTZGc6hshAoXeou6SFGLUZ7FXq7c JMk9oOzchEqhzgZ9NzXI4iYLpTsam0rvfz4DsRS0qfkCxv9X8Bc/cXbg08dQAbXjZ6/U kpvCeeJENd1GIC/IFqtCtHbcW8HEJGIjpqN1k= Received: by 10.52.71.41 with SMTP id r9mr493190vdu.289.1314807711020; Wed, 31 Aug 2011 09:21:51 -0700 (PDT) Received: from localhost.localdomain (nat-pool-rdu.redhat.com [66.187.233.202]) by mx.google.com with ESMTPS id k10sm4415688vdi.43.2011.08.31.09.21.50 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 31 Aug 2011 09:21:50 -0700 (PDT) From: Shyam Iyer To: linux-pci@vger.kernel.org Cc: sgruszka@redhat.com, mason@myri.com, jbarnes@virtuousgeek.org, Shyam Iyer Subject: [PATCH] [pci][v2] Fix pointer dereference before call to pcie_bus_configure_settings Date: Wed, 31 Aug 2011 12:21:42 -0400 Message-Id: <1314807702-25346-1-git-send-email-shyam_iyer@dell.com> X-Mailer: git-send-email 1.7.2.3 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter2.kernel.org [140.211.167.43]); Wed, 31 Aug 2011 16:21:53 +0000 (UTC) Commit b03e7495a862b028294f59fc87286d6d78ee7fa1 introduces a few issues by dereferencing bus->self in the call to pcie_bus_configure_settings. This fixes it by checking existence of bus->self before dereferencing it. Reported-by: Stanislaw Gruszka Signed-off-by: Shyam Iyer --- arch/x86/pci/acpi.c | 9 +++++++-- drivers/pci/hotplug/pcihp_slot.c | 4 +++- drivers/pci/probe.c | 3 --- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/arch/x86/pci/acpi.c b/arch/x86/pci/acpi.c index c953302..86bf435 100644 --- a/arch/x86/pci/acpi.c +++ b/arch/x86/pci/acpi.c @@ -365,8 +365,13 @@ struct pci_bus * __devinit pci_acpi_scan_root(struct acpi_pci_root *root) */ if (bus) { struct pci_bus *child; - list_for_each_entry(child, &bus->children, node) - pcie_bus_configure_settings(child, child->self->pcie_mpss); + list_for_each_entry(child, &bus->children, node) { + struct pci_bus *self = child->self; + if (!self) + continue; + + pcie_bus_configure_settings(child, self->pcie_mpss); + } } if (!bus) diff --git a/drivers/pci/hotplug/pcihp_slot.c b/drivers/pci/hotplug/pcihp_slot.c index 753b21a..3ffd9c1 100644 --- a/drivers/pci/hotplug/pcihp_slot.c +++ b/drivers/pci/hotplug/pcihp_slot.c @@ -169,7 +169,9 @@ void pci_configure_slot(struct pci_dev *dev) (dev->class >> 8) == PCI_CLASS_BRIDGE_PCI))) return; - pcie_bus_configure_settings(dev->bus, dev->bus->self->pcie_mpss); + if (dev->bus && dev->bus->self) + pcie_bus_configure_settings(dev->bus, + dev->bus->self->pcie_mpss); memset(&hpp, 0, sizeof(hpp)); ret = pci_get_hp_params(dev, &hpp); diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 8473727..0820fc1 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1456,9 +1456,6 @@ void pcie_bus_configure_settings(struct pci_bus *bus, u8 mpss) { u8 smpss = mpss; - if (!bus->self) - return; - if (!pci_is_pcie(bus->self)) return;