From patchwork Thu Apr 23 07:41:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yijing Wang X-Patchwork-Id: 6260081 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 88BA3BF4A6 for ; Thu, 23 Apr 2015 07:46:10 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BFE2720376 for ; Thu, 23 Apr 2015 07:46:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 8420A2035E for ; Thu, 23 Apr 2015 07:46:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932208AbbDWHqG (ORCPT ); Thu, 23 Apr 2015 03:46:06 -0400 Received: from [119.145.14.66] ([119.145.14.66]:28380 "EHLO szxga03-in.huawei.com" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S932189AbbDWHqC (ORCPT ); Thu, 23 Apr 2015 03:46:02 -0400 Received: from 172.24.2.119 (EHLO szxeml427-hub.china.huawei.com) ([172.24.2.119]) by szxrg03-dlp.huawei.com (MOS 4.4.3-GA FastPath queued) with ESMTP id BEY30456; Thu, 23 Apr 2015 15:45:06 +0800 (CST) Received: from localhost.localdomain (10.175.100.166) by szxeml427-hub.china.huawei.com (10.82.67.182) with Microsoft SMTP Server id 14.3.158.1; Thu, 23 Apr 2015 15:44:42 +0800 From: Yijing Wang To: CC: , , , Yijing Wang Subject: [PATCH] PCI: Fix NULL pointer when find parent pcie_link_state Date: Thu, 23 Apr 2015 15:41:56 +0800 Message-ID: <1429774916-24920-1-git-send-email-wangyijing@huawei.com> X-Mailer: git-send-email 1.7.1 MIME-Version: 1.0 X-Originating-IP: [10.175.100.166] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020203.5538A303.0096, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-05-26 15:14:31, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 346e44a62244477cf4d9a37fa506e313 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP https://bugzilla.kernel.org/show_bug.cgi?id=94361 reported NULL Pointer in pcie_aspm_init_link_state(), Some platform like ATCA may has strange PCIe topology: E.g. ---root port---downstream port---upstream port |--downstream port |--downstream port When we try to alloc pcie_link_state, we assumed downstream port always has a upstream port, in this case, NULL pointer would be triggered when try to find the parent pci_link_state, because downstream port connects to root port directly. Signed-off-by: Yijing Wang --- drivers/pci/pcie/aspm.c | 13 +++++++++++-- 1 files changed, 11 insertions(+), 2 deletions(-) diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c index 7d4fcdc..f295824 100644 --- a/drivers/pci/pcie/aspm.c +++ b/drivers/pci/pcie/aspm.c @@ -526,8 +526,17 @@ static struct pcie_link_state *alloc_pcie_link_state(struct pci_dev *pdev) INIT_LIST_HEAD(&link->link); link->pdev = pdev; if (pci_pcie_type(pdev) == PCI_EXP_TYPE_DOWNSTREAM) { - struct pcie_link_state *parent; - parent = pdev->bus->parent->self->link_state; + struct pci_bus *pbus = pdev->bus; + struct pcie_link_state *parent = NULL; + + while (pbus) { + if (pbus->self) { + parent = pbus->self->link_state; + if (parent) + break; + } + pbus = pbus->parent; + } if (!parent) { kfree(link); return NULL;