From patchwork Mon May 13 16:08:26 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 2559181 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 ADECE3FE37 for ; Mon, 13 May 2013 16:09:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755096Ab3EMQJD (ORCPT ); Mon, 13 May 2013 12:09:03 -0400 Received: from mail-da0-f46.google.com ([209.85.210.46]:50090 "EHLO mail-da0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755087Ab3EMQJB (ORCPT ); Mon, 13 May 2013 12:09:01 -0400 Received: by mail-da0-f46.google.com with SMTP id e20so3670420dak.5 for ; Mon, 13 May 2013 09:09:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=i6jZ2kW6nwJePHl9Pr9RXC/MkbnVu/O0qr1q+gc/2jQ=; b=SiBy33ljj9UAV00GahbKhMYY54BGp5REW1AW0Xru1Jk/GkJh+uXmUeleI6PVigSyrs S7ad6MR7+F2GlDctCnPaGML4SwagxxK66MN36fDiHo1ccr2mHqqGEbTWjsGyQWPDgBCl Ygy+cR/dPcllrZdoE0TH51ZfinGc5qC+btmIM+w1fEv/zpOwVH2GQuQW1zFzM23lZGDj puRxHS5mzt6VqeWc38LoubDbJkGSUtmsHypxs0VF6v4SybnC856Yciji3NP/mWRqrgyK Bfw5r+Q2p6trEadO15+CfvGnTyvwtIPPv7B3+i8SHtlavLRCEbqnbTRdVLquoMTD9H+0 1znQ== X-Received: by 10.66.248.163 with SMTP id yn3mr30396041pac.39.1368461340982; Mon, 13 May 2013 09:09:00 -0700 (PDT) Received: from localhost.localdomain ([120.196.98.100]) by mx.google.com with ESMTPSA id nt2sm14580193pbc.17.2013.05.13.09.08.57 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 13 May 2013 09:09:00 -0700 (PDT) From: Jiang Liu To: Bjorn Helgaas , Yinghai Lu Cc: Gu Zheng , "Rafael J . Wysocki" , Greg Kroah-Hartman , Toshi Kani , Myron Stowe , Yijing Wang , Jiang Liu , linux-pci@vger.kernel.org, linux-kernel@vger.kernel.org, Jiang Liu Subject: [PATCH v2, part 1 2/9] PCI: Introduce pci_alloc_dev(struct pci_bus*) to replace alloc_pci_dev() Date: Tue, 14 May 2013 00:08:26 +0800 Message-Id: <1368461313-4371-3-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1368461313-4371-1-git-send-email-jiang.liu@huawei.com> References: <1368461313-4371-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: Gu Zheng From: Gu Zheng Now here we introduce a new interface to replace alloc_pci_dev(): struct pci_dev *pci_alloc_dev(struct pci_bus *bus) 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. We use pci_alloc_dev(NULL) to simplify the old alloc_pci_dev(), and keep it for a while but mark it as __deprecated. Jiang Liu Minor code tweaks and change __deprecated struct pci_dev * alloc_pci_dev(void); to struct pci_dev * __deprecated alloc_pci_dev(void); This enhancement makes it safe to reference pci_dev->bus when holding a reference on a pci_dev. Signed-off-by: Gu Zheng Signed-off-by: Jiang Liu Cc: Bjorn Helgaas Cc: linux-pci@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/pci/probe.c | 16 +++++++++++----- include/linux/pci.h | 3 ++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 43ece5d..4f0bc0a 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1201,18 +1201,24 @@ 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; dev = kzalloc(sizeof(struct pci_dev), GFP_KERNEL); - if (!dev) - return NULL; - - INIT_LIST_HEAD(&dev->bus_list); + if (dev) { + INIT_LIST_HEAD(&dev->bus_list); + dev->bus = pci_bus_get(bus); + } return dev; } +EXPORT_SYMBOL(pci_alloc_dev); + +struct pci_dev *alloc_pci_dev(void) +{ + return pci_alloc_dev(NULL); +} EXPORT_SYMBOL(alloc_pci_dev); bool pci_bus_read_dev_vendor_id(struct pci_bus *bus, int devfn, u32 *l, diff --git a/include/linux/pci.h b/include/linux/pci.h index f5e13f0..68beb11 100644 --- a/include/linux/pci.h +++ b/include/linux/pci.h @@ -364,7 +364,8 @@ static inline struct pci_dev *pci_physfn(struct pci_dev *dev) return dev; } -struct pci_dev *alloc_pci_dev(void); +struct pci_dev *pci_alloc_dev(struct pci_bus *bus); +struct pci_dev * __deprecated 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)