From patchwork Fri Apr 19 09:44:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gu Zheng X-Patchwork-Id: 2464131 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 6508C3FD1A for ; Fri, 19 Apr 2013 09:46:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758544Ab3DSJqe (ORCPT ); Fri, 19 Apr 2013 05:46:34 -0400 Received: from cn.fujitsu.com ([222.73.24.84]:23339 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1758536Ab3DSJqe (ORCPT ); Fri, 19 Apr 2013 05:46:34 -0400 X-IronPort-AV: E=Sophos;i="4.87,508,1363104000"; d="scan'208,223";a="7095462" Received: from unknown (HELO tang.cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 19 Apr 2013 17:43:51 +0800 Received: from fnstmail02.fnst.cn.fujitsu.com (tang.cn.fujitsu.com [127.0.0.1]) by tang.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id r3J9kVAg016738; Fri, 19 Apr 2013 17:46:31 +0800 Received: from [10.167.233.218] ([10.167.233.218]) by fnstmail02.fnst.cn.fujitsu.com (Lotus Domino Release 8.5.3) with ESMTP id 2013041917450593-687506 ; Fri, 19 Apr 2013 17:45:05 +0800 Message-ID: <51711214.8050606@cn.fujitsu.com> Date: Fri, 19 Apr 2013 17:44:52 +0800 From: Gu Zheng User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20110930 Thunderbird/7.0.1 MIME-Version: 1.0 To: Bjorn Helgaas CC: "linux-pci@vger.kernel.org" , Yasuaki Ishimatsu , Taku Izumi , Yinghai Lu , Jiang Liu , tangchen , Lin Feng , li guang Subject: [PATCH 1/2] PCI: Introduce pci_alloc_dev(struct pci_bus*) to replace alloc_pci_dev() References: <516FB647.5030203@cn.fujitsu.com> In-Reply-To: X-MIMETrack: Itemize by SMTP Server on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/04/19 17:45:05, Serialize by Router on mailserver/fnst(Release 8.5.3|September 15, 2011) at 2013/04/19 17:45:07, Serialize complete at 2013/04/19 17:45:07 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org From 906167d9a09babbe189f62944ecb8c0b198a0f64 Mon Sep 17 00:00:00 2001 From: Gu Zheng Date: Fri, 19 Apr 2013 18:12:32 +0900 Subject: [PATCH 1/2] PCI: Introduce pci_alloc_dev(struct pci_bus*) to replace alloc_pci_dev() Now here we introduce a new struct pci_dev *pci_alloc_dev(struct pci_bus *bus) to replace alloc_pci_dev(). It take a "struct pci_bus *" argument, so we can alloc a pci device on a target pci bus, and it acquire the reference of the pci_bus. Since the old alloc_pci_dev() is exported, so we still keep it for a while but mark it as __deprecated. Signed-off-by: Gu Zheng --- drivers/pci/probe.c | 21 ++++++++++++++++++++- include/linux/pci.h | 4 +++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index b494066..5233fb6 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1199,7 +1199,7 @@ static void pci_release_bus_bridge_dev(struct device *dev) kfree(bridge); } -struct pci_dev *alloc_pci_dev(void) +struct pci_dev *pci_alloc_dev(struct pci_bus *bus) { struct pci_dev *dev; @@ -1209,6 +1209,25 @@ struct pci_dev *alloc_pci_dev(void) INIT_LIST_HEAD(&dev->bus_list); + if (bus) { + get_device(&bus->dev); + dev->bus = bus; + } + + return dev; +} +EXPORT_SYMBOL(pci_alloc_dev); + +__deprecated struct pci_dev *alloc_pci_dev(void) +{ + struct pci_dev *dev; + printk(KERN_DEBUG "alloc_pci_dev is deprecated, please use pci_alloc_dev(struct pci_bus *) instead!\n"); + dev = kzalloc(sizeof(struct pci_dev), GFP_KERNEL); + if (!dev) + return NULL; + + INIT_LIST_HEAD(&dev->bus_list); + return dev; } EXPORT_SYMBOL(alloc_pci_dev); diff --git a/include/linux/pci.h b/include/linux/pci.h index 710067f..682de2b 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -348,7 +348,9 @@ static inline struct pci_dev *pci_physfn(struct pci_dev *dev) return dev; } -extern struct pci_dev *alloc_pci_dev(void); +extern struct pci_dev *pci_alloc_dev(struct pci_bus *bus); + +extern __deprecated struct pci_dev *alloc_pci_dev(void); #define to_pci_dev(n) container_of(n, struct pci_dev, dev) #define for_each_pci_dev(d) while ((d = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, d)) != NULL)