From patchwork Fri Apr 27 15:16:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 155509 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 A9E48B6FA8 for ; Sat, 28 Apr 2012 01:23:37 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1760628Ab2D0PWU (ORCPT ); Fri, 27 Apr 2012 11:22:20 -0400 Received: from mail-pz0-f51.google.com ([209.85.210.51]:50093 "EHLO mail-pz0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760338Ab2D0PWR (ORCPT ); Fri, 27 Apr 2012 11:22:17 -0400 Received: by mail-pz0-f51.google.com with SMTP id z8so1149168dad.10 for ; Fri, 27 Apr 2012 08:22:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references; bh=Nsr1jY+s9zTj1a2K4qtJ0rfzhkNokN+zqTc8NiE22l4=; b=t6riDEnF8DK96EwRpDAUaD07cwETHE6+J68qaQqwp+B+Kc+PabyI+M9zRoXxNON391 6YgaMeygpZi59uV2FErWCaud8CccmbeUV6GAWX7XnA0vBCAKsjPHX8vV+z5Q1DLvhmR5 5Sig2/nf54rJ4H7WpsqgaTdZmWOaN55tv3RArZnW8XNvEC1IAU6B8NrXWXdxO64rf7mr cUisCfgHUuxki8sfgVsebn1NK8DhlZpPBOZR5tP2IxA2o0HaKZZmx/3s3bYx32Bviz9I Jgm0wSNnzR+ltKBOqUa5/xWtZH/UCrtxbTEsgzIo3JVosOXvnBcezupqZrRey0TCIhrg lPXQ== Received: by 10.68.240.135 with SMTP id wa7mr24358595pbc.7.1335540137348; Fri, 27 Apr 2012 08:22:17 -0700 (PDT) Received: from localhost.localdomain ([221.221.26.142]) by mx.google.com with ESMTPS id 2sm6743917pbw.57.2012.04.27.08.22.08 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 27 Apr 2012 08:22:16 -0700 (PDT) From: Jiang Liu To: Yinghai Lu , Kenji Kaneshige , Bjorn Helgaas , Don Dutile , Greg KH Cc: Jiang Liu , Keping Chen , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Jiang Liu Subject: [PATCH v2 15/19] PCI: hold a reference count to the PCI bus used by cpcihp drivers Date: Fri, 27 Apr 2012 23:16:56 +0800 Message-Id: <1335539820-11232-16-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.7.5.4 In-Reply-To: <1335539820-11232-1-git-send-email-jiang.liu@huawei.com> References: <1335539820-11232-1-git-send-email-jiang.liu@huawei.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From: Jiang Liu The PCI bus used by cpcihp drivers may be removed at runtime through /sys/devices/pcissss:bb/ssss\:bb\:dd.f/.../remove interface, so hold a reference count to the PCI bus to avoid invalid memory access. Signed-off-by: Jiang Liu --- drivers/pci/hotplug/cpcihp_generic.c | 7 +++++-- drivers/pci/hotplug/cpcihp_zt5550.c | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c index 518f387..f002be5 100644 --- a/drivers/pci/hotplug/cpcihp_generic.c +++ b/drivers/pci/hotplug/cpcihp_generic.c @@ -163,7 +163,7 @@ static int __init cpcihp_generic_init(void) err("Invalid bridge device %s", bridge); bus = NULL; } else - bus = dev->subordinate; + bus = pci_bus_get(dev->subordinate); pci_dev_put(dev); } if (!bus) { @@ -179,7 +179,7 @@ static int __init cpcihp_generic_init(void) if(status != 0) { err("Could not register cPCI hotplug controller"); status = -ENODEV; - goto init_find_bus_error; + goto init_register_controller_error; } dbg("registered controller"); @@ -202,6 +202,8 @@ init_start_error: cpci_hp_unregister_bus(bus); init_bus_register_error: cpci_hp_unregister_controller(&generic_hpc); +init_register_controller_error: + pci_bus_put(bus); init_find_bus_error: release_region(port, 1); err("status = %d", status); @@ -214,6 +216,7 @@ static void __exit cpcihp_generic_exit(void) cpci_hp_stop(); cpci_hp_unregister_bus(bus); cpci_hp_unregister_controller(&generic_hpc); + pci_bus_put(bus); release_region(port, 1); } diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c index 8a6f968..6606520 100644 --- a/drivers/pci/hotplug/cpcihp_zt5550.c +++ b/drivers/pci/hotplug/cpcihp_zt5550.c @@ -241,9 +241,9 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id if(!(bus0_dev = pci_get_device(PCI_VENDOR_ID_DEC, PCI_DEVICE_ID_DEC_21154, NULL))) { status = -ENODEV; - goto init_register_error; + goto init_find_bus_error; } - bus0 = bus0_dev->subordinate; + bus0 = pci_bus_get(bus0_dev->subordinate); pci_dev_put(bus0_dev); status = cpci_hp_register_bus(bus0, 0x0a, 0x0f); @@ -265,6 +265,8 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id init_start_error: cpci_hp_unregister_bus(bus0); init_register_error: + pci_bus_put(bus0); +init_find_bus_error: cpci_hp_unregister_controller(&zt5550_hpc); init_hc_error: err("status = %d", status); @@ -278,6 +280,7 @@ static void __devexit zt5550_hc_remove_one(struct pci_dev *pdev) cpci_hp_stop(); cpci_hp_unregister_bus(bus0); cpci_hp_unregister_controller(&zt5550_hpc); + pci_bus_put(bus0); zt5550_hc_cleanup(); }