From patchwork Mon Apr 22 06:13:56 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Qiu X-Patchwork-Id: 238340 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id AA6BD2C011A for ; Mon, 22 Apr 2013 16:14:27 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754623Ab3DVGOZ (ORCPT ); Mon, 22 Apr 2013 02:14:25 -0400 Received: from e28smtp05.in.ibm.com ([122.248.162.5]:47920 "EHLO e28smtp05.in.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752359Ab3DVGOZ (ORCPT ); Mon, 22 Apr 2013 02:14:25 -0400 Received: from /spool/local by e28smtp05.in.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 22 Apr 2013 11:40:50 +0530 Received: from d28dlp03.in.ibm.com (9.184.220.128) by e28smtp05.in.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 22 Apr 2013 11:40:47 +0530 Received: from d28relay03.in.ibm.com (d28relay03.in.ibm.com [9.184.220.60]) by d28dlp03.in.ibm.com (Postfix) with ESMTP id 570F81258023 for ; Mon, 22 Apr 2013 11:45:51 +0530 (IST) Received: from d28av03.in.ibm.com (d28av03.in.ibm.com [9.184.220.65]) by d28relay03.in.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id r3M6E94w2556250 for ; Mon, 22 Apr 2013 11:44:10 +0530 Received: from d28av03.in.ibm.com (loopback [127.0.0.1]) by d28av03.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id r3M6EEjq032394 for ; Mon, 22 Apr 2013 16:14:15 +1000 Received: from localhost (win-cfhhhd5ftv2.cn.ibm.com [9.111.29.51]) by d28av03.in.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id r3M6EDCs032324; Mon, 22 Apr 2013 16:14:14 +1000 From: Mike Qiu To: linux-pci@vger.kernel.org Cc: benh@kernel.crashing.org, tglx@linutronix.de, Mike Qiu Subject: [PATCH] PowerNV/PCI: Fix NULL PCI controller Date: Mon, 22 Apr 2013 02:13:56 -0400 Message-Id: <1366611236-1811-1-git-send-email-qiudayu@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.11.7 X-TM-AS-MML: No X-Content-Scanned: Fidelis XPS MAILER x-cbid: 13042206-8256-0000-0000-0000072A43B7 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org In pnv_pci_read_config() or pnv_pci_write_config(), we never check if the PCI controller is valid before converting that into platform dependent one, this is very dangerous. To avoid this potential risks, the patch check PCI controller first before use it. Signed-off-by: Mike Qiu --- arch/powerpc/platforms/powernv/pci.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/platforms/powernv/pci.c b/arch/powerpc/platforms/powernv/pci.c index b8b8e0b..e7b7f1a 100644 --- a/arch/powerpc/platforms/powernv/pci.c +++ b/arch/powerpc/platforms/powernv/pci.c @@ -286,11 +286,11 @@ static int pnv_pci_read_config(struct pci_bus *bus, int where, int size, u32 *val) { struct pci_controller *hose = pci_bus_to_host(bus); - struct pnv_phb *phb = hose->private_data; + struct pnv_phb *phb = hose ? hose->private_data : NULL; u32 bdfn = (((uint64_t)bus->number) << 8) | devfn; s64 rc; - if (hose == NULL) + if (!phb) return PCIBIOS_DEVICE_NOT_FOUND; switch (size) { @@ -330,10 +330,10 @@ static int pnv_pci_write_config(struct pci_bus *bus, int where, int size, u32 val) { struct pci_controller *hose = pci_bus_to_host(bus); - struct pnv_phb *phb = hose->private_data; + struct pnv_phb *phb = hose ? hose->private_data : NULL; u32 bdfn = (((uint64_t)bus->number) << 8) | devfn; - if (hose == NULL) + if (!phb) return PCIBIOS_DEVICE_NOT_FOUND; cfg_dbg("pnv_pci_write_config bus: %x devfn: %x +%x/%x -> %08x\n",