From patchwork Wed Aug 19 01:58:46 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kenji Kaneshige X-Patchwork-Id: 42477 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n7J1uolL022565 for ; Wed, 19 Aug 2009 01:59:00 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751326AbZHSB65 (ORCPT ); Tue, 18 Aug 2009 21:58:57 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751348AbZHSB65 (ORCPT ); Tue, 18 Aug 2009 21:58:57 -0400 Received: from fgwmail6.fujitsu.co.jp ([192.51.44.36]:57236 "EHLO fgwmail6.fujitsu.co.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751326AbZHSB65 (ORCPT ); Tue, 18 Aug 2009 21:58:57 -0400 Received: from m1.gw.fujitsu.co.jp ([10.0.50.71]) by fgwmail6.fujitsu.co.jp (Fujitsu Gateway) with ESMTP id n7J1wwIa013424 for (envelope-from kaneshige.kenji@jp.fujitsu.com); Wed, 19 Aug 2009 10:58:58 +0900 Received: from smail (m1 [127.0.0.1]) by outgoing.m1.gw.fujitsu.co.jp (Postfix) with ESMTP id 01FAE45DE4E for ; Wed, 19 Aug 2009 10:58:58 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (s1.gw.fujitsu.co.jp [10.0.50.91]) by m1.gw.fujitsu.co.jp (Postfix) with ESMTP id D421145DE50 for ; Wed, 19 Aug 2009 10:58:57 +0900 (JST) Received: from s1.gw.fujitsu.co.jp (localhost.localdomain [127.0.0.1]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id B731A1DB8041 for ; Wed, 19 Aug 2009 10:58:57 +0900 (JST) Received: from m105.s.css.fujitsu.com (m105.s.css.fujitsu.com [10.249.87.105]) by s1.gw.fujitsu.co.jp (Postfix) with ESMTP id 5FCF61DB803A for ; Wed, 19 Aug 2009 10:58:57 +0900 (JST) Received: from m105.css.fujitsu.com (m105 [127.0.0.1]) by m105.s.css.fujitsu.com (Postfix) with ESMTP id 367555D8002; Wed, 19 Aug 2009 10:58:57 +0900 (JST) Received: from [127.0.0.1] (unknown [10.124.100.137]) by m105.s.css.fujitsu.com (Postfix) with ESMTP id CBC765D8001; Wed, 19 Aug 2009 10:58:56 +0900 (JST) X-SecurityPolicyCheck-FJ: OK by FujitsuOutboundMailChecker v1.3.1 Received: from KANE-LIFEBOOK[10.124.100.137] by KANE-LIFEBOOK (FujitsuOutboundMailChecker v1.3.1/9992[10.124.100.137]); Wed, 19 Aug 2009 10:58:50 +0900 (JST) Message-ID: <4A8B5C56.3060608@jp.fujitsu.com> Date: Wed, 19 Aug 2009 10:58:46 +0900 From: Kenji Kaneshige User-Agent: Thunderbird 2.0.0.22 (Windows/20090605) MIME-Version: 1.0 To: jbarnes@virtuousgeek.org, shaohua.li@intel.com, linux-pci@vger.kernel.org Subject: [PATCH 3/7] PCI ASPM: fix possible null pointer dereference References: <4A8B5BC8.1070907@jp.fujitsu.com> In-Reply-To: <4A8B5BC8.1070907@jp.fujitsu.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org Fix possible NULL dereference in pcie_aspm_exit_link_state(). This patch also cleanup some code. Signed-off-by: Kenji Kaneshige --- drivers/pci/pcie/aspm.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: 20090818/drivers/pci/pcie/aspm.c =================================================================== --- 20090818.orig/drivers/pci/pcie/aspm.c +++ 20090818/drivers/pci/pcie/aspm.c @@ -665,16 +665,16 @@ out: void pcie_aspm_exit_link_state(struct pci_dev *pdev) { struct pci_dev *parent = pdev->bus->self; - struct pcie_link_state *link_state = parent->link_state; + struct pcie_link_state *link; - if (aspm_disabled || !pdev->is_pcie || !parent || !link_state) + if (aspm_disabled || !pdev->is_pcie || !parent || !parent->link_state) return; if (parent->pcie_type != PCI_EXP_TYPE_ROOT_PORT && - parent->pcie_type != PCI_EXP_TYPE_DOWNSTREAM) + parent->pcie_type != PCI_EXP_TYPE_DOWNSTREAM) return; + down_read(&pci_bus_sem); mutex_lock(&aspm_lock); - /* * All PCIe functions are in one slot, remove one function will remove * the whole slot, so just wait until we are the last function left. @@ -682,13 +682,14 @@ void pcie_aspm_exit_link_state(struct pc if (!list_is_last(&pdev->bus_list, &parent->subordinate->devices)) goto out; + link = parent->link_state; + /* All functions are removed, so just disable ASPM for the link */ __pcie_aspm_config_one_dev(parent, 0); - list_del(&link_state->sibling); - list_del(&link_state->link); + list_del(&link->sibling); + list_del(&link->link); /* Clock PM is for endpoint device */ - - free_link_state(link_state); + free_link_state(link); out: mutex_unlock(&aspm_lock); up_read(&pci_bus_sem);