From patchwork Sun May 26 15:53:00 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 2616651 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork1.kernel.org (Postfix) with ESMTP id 399B73FD4E for ; Sun, 26 May 2013 16:02:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754151Ab3EZP5d (ORCPT ); Sun, 26 May 2013 11:57:33 -0400 Received: from mail-pd0-f181.google.com ([209.85.192.181]:62339 "EHLO mail-pd0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754077Ab3EZP5X (ORCPT ); Sun, 26 May 2013 11:57:23 -0400 Received: by mail-pd0-f181.google.com with SMTP id bv13so3919071pdb.40 for ; Sun, 26 May 2013 08:57:22 -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=A7kmXO3z1G8gBsC0ut0rZl5T78oDN5L3CdlbTfzx7tM=; b=Fg/XdrzXJY5QrGGLyTCqi3oC/KkWLUnUY0AKUVZHs1gXKPCe7fCNES1tzmNE4rLZTc C5Y6Xdea8smljNfCTwZWkTrZGDN8PNLbGgRM9FlxHZSMo+0BWB7biENaj+6tGdQXT8tt GJcSMuWudCHI9SViSeTmVm7yQHVyQYVBt3kTj3FuqR/96f2td2A8KzmIZaHyZnSwNaHy 4bzHEG3YnAgOiYjAAaoF+kt6kbLYYTIsDtCHSWdYrVf/lkJMAY4xzoH1mTXstdJ84HzJ z2gyFa3uZdIOyWOxvJ1BeDsdpTuH6/q44kZjUZBTNwItiNQ28lmb4hBgB+6F8kgKggh0 f57g== X-Received: by 10.68.232.42 with SMTP id tl10mr25830071pbc.72.1369583842373; Sun, 26 May 2013 08:57:22 -0700 (PDT) Received: from localhost.localdomain ([111.196.197.202]) by mx.google.com with ESMTPSA id ze11sm26603189pab.22.2013.05.26.08.57.16 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sun, 26 May 2013 08:57:21 -0700 (PDT) From: Jiang Liu To: Bjorn Helgaas , Yinghai Lu Cc: Jiang Liu , "Rafael J . Wysocki" , Greg Kroah-Hartman , Gu Zheng , Toshi Kani , Myron Stowe , Yijing Wang , Jiang Liu , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Jiri Kosina , Masanari Iida , "Rafael J. Wysocki" Subject: [PATCH v3, part2 03/20] PCI, hotplug: use hotplug-safe iterators to walk PCI buses Date: Sun, 26 May 2013 23:53:00 +0800 Message-Id: <1369583597-3801-4-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1369583597-3801-1-git-send-email-jiang.liu@huawei.com> References: <1369583597-3801-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 Enhance PCI hotplug drivers to use hotplug-safe iterators to walk PCI buses. In other words, replace pci_find_bus(), pci_find_next_bus() and pci_root_buses with pci_bus_exists(), pci_get_bus(), pci_get_next_bus() and pci_get_next_root_bus() etc. Signed-off-by: Jiang Liu Acked-by: Yinghai Lu Cc: Jiri Kosina Cc: Masanari Iida Cc: "Rafael J. Wysocki" Cc: Toshi Kani Cc: linux-pci@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/pci/hotplug-pci.c | 2 +- drivers/pci/hotplug/ibmphp_core.c | 8 +++++--- drivers/pci/hotplug/ibmphp_ebda.c | 8 ++++++-- drivers/pci/hotplug/sgi_hotplug.c | 3 ++- drivers/pci/hotplug/shpchp_sysfs.c | 2 +- 5 files changed, 15 insertions(+), 8 deletions(-) diff --git a/drivers/pci/hotplug-pci.c b/drivers/pci/hotplug-pci.c index 6258dc2..18533ed 100644 --- a/drivers/pci/hotplug-pci.c +++ b/drivers/pci/hotplug-pci.c @@ -11,7 +11,7 @@ int __ref pci_hp_add_bridge(struct pci_dev *dev) int end = parent->busn_res.end; for (busnr = start; busnr <= end; busnr++) { - if (!pci_find_bus(pci_domain_nr(parent), busnr)) + if (!pci_bus_exists(pci_domain_nr(parent), busnr)) break; } if (busnr-- > end) { diff --git a/drivers/pci/hotplug/ibmphp_core.c b/drivers/pci/hotplug/ibmphp_core.c index cbd72d8..fb47695 100644 --- a/drivers/pci/hotplug/ibmphp_core.c +++ b/drivers/pci/hotplug/ibmphp_core.c @@ -739,7 +739,7 @@ static u8 bus_structure_fixup(u8 busno) struct pci_dev *dev; u16 l; - if (pci_find_bus(0, busno) || !(ibmphp_find_same_bus_num(busno))) + if (pci_bus_exists(0, busno) || !(ibmphp_find_same_bus_num(busno))) return 1; bus = kmalloc(sizeof(*bus), GFP_KERNEL); @@ -787,7 +787,7 @@ static int ibm_configure_device(struct pci_func *func) PCI_DEVFN(func->device, func->function)); if (func->dev == NULL) { - struct pci_bus *bus = pci_find_bus(0, func->busno); + struct pci_bus *bus = pci_get_bus(0, func->busno); if (!bus) return 0; @@ -795,6 +795,7 @@ static int ibm_configure_device(struct pci_func *func) PCI_DEVFN(func->device, func->function)); if (num) pci_bus_add_devices(bus); + pci_bus_put(bus); func->dev = pci_get_bus_and_slot(func->busno, PCI_DEVFN(func->device, func->function)); @@ -1315,13 +1316,14 @@ static int __init ibmphp_init(void) goto exit; } - bus = pci_find_bus(0, 0); + bus = pci_get_bus(0, 0); if (!bus) { err("Can't find the root pci bus, can not continue\n"); rc = -ENODEV; goto error; } memcpy(ibmphp_pci_bus, bus, sizeof(*ibmphp_pci_bus)); + pci_bus_put(bus); ibmphp_debug = debug; diff --git a/drivers/pci/hotplug/ibmphp_ebda.c b/drivers/pci/hotplug/ibmphp_ebda.c index 9df78bc..e17f271 100644 --- a/drivers/pci/hotplug/ibmphp_ebda.c +++ b/drivers/pci/hotplug/ibmphp_ebda.c @@ -978,9 +978,13 @@ static int __init ebda_rsrc_controller (void) } /* each hpc */ list_for_each_entry(tmp_slot, &ibmphp_slot_head, ibm_slot_list) { + struct pci_bus *bus = pci_get_bus(0, tmp_slot->bus); + + BUG_ON(!bus); snprintf(name, SLOT_NAME_SIZE, "%s", create_file_name(tmp_slot)); - pci_hp_register(tmp_slot->hotplug_slot, - pci_find_bus(0, tmp_slot->bus), tmp_slot->device, name); + pci_hp_register(tmp_slot->hotplug_slot, bus, tmp_slot->device, + name); + pci_bus_put(bus); } print_ebda_hpc (); diff --git a/drivers/pci/hotplug/sgi_hotplug.c b/drivers/pci/hotplug/sgi_hotplug.c index b2781df..5c69bda 100644 --- a/drivers/pci/hotplug/sgi_hotplug.c +++ b/drivers/pci/hotplug/sgi_hotplug.c @@ -684,7 +684,7 @@ static int __init sn_pci_hotplug_init(void) INIT_LIST_HEAD(&sn_hp_list); - while ((pci_bus = pci_find_next_bus(pci_bus))) { + for_each_pci_root_bus(pci_bus) { if (!pci_bus->sysdata) continue; @@ -703,6 +703,7 @@ static int __init sn_pci_hotplug_init(void) break; } } + pci_bus_put(pci_bus); return registered == 1 ? 0 : -ENODEV; } diff --git a/drivers/pci/hotplug/shpchp_sysfs.c b/drivers/pci/hotplug/shpchp_sysfs.c index e8c31fe..e7a5dd2 100644 --- a/drivers/pci/hotplug/shpchp_sysfs.c +++ b/drivers/pci/hotplug/shpchp_sysfs.c @@ -74,7 +74,7 @@ static ssize_t show_ctrl (struct device *dev, struct device_attribute *attr, cha } out += sprintf(out, "Free resources: bus numbers\n"); for (busnr = bus->busn_res.start; busnr <= bus->busn_res.end; busnr++) { - if (!pci_find_bus(pci_domain_nr(bus), busnr)) + if (!pci_bus_exists(pci_domain_nr(bus), busnr)) break; } if (busnr < bus->busn_res.end)