From patchwork Sat May 25 13:48:30 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 2613361 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by patchwork2.kernel.org (Postfix) with ESMTP id F03BCDFE82 for ; Sat, 25 May 2013 13:51:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756160Ab3EYNv1 (ORCPT ); Sat, 25 May 2013 09:51:27 -0400 Received: from mail-pa0-f50.google.com ([209.85.220.50]:45554 "EHLO mail-pa0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756140Ab3EYNvZ (ORCPT ); Sat, 25 May 2013 09:51:25 -0400 Received: by mail-pa0-f50.google.com with SMTP id fb11so3929687pad.9 for ; Sat, 25 May 2013 06:51:24 -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=SEC2xYmEjmmA6e+qeqqrBYnoeqIQj/B4xhqx6wAF8/8=; b=bkQstyVpSumUcTijOjyyo+2PMh10Td/o7sMKPjYNTQSibK8XJTw7f0BPgAJHwDFiMB 0Uqcs4aKE+KyNPqncXNkZn0FHTyMUmbvaVw5pIwRv0X0kYhGi+v/UYh63rutCiSDIDLg p4sDOtsLMBGgDHXitiuVXCc9p4/FFRpz12WBgdTpdxlBJYpDI/F+/HOZX4ohHm4IAh4x 7lB+hlIdC5LnVnCx6z1hSFHmRQOPyJjWi3haUnDF46fOFYs9TqzJ9e+TrA4tDbtWtJij liR6qiH9us2Gr9Yu5uavoyivpBZlEQmsiE5myrVNqD24lC7e1FF27GVOs6VacqWiQdj0 X6RQ== X-Received: by 10.68.106.196 with SMTP id gw4mr22002442pbb.126.1369489884794; Sat, 25 May 2013 06:51:24 -0700 (PDT) Received: from localhost.localdomain ([114.250.94.230]) by mx.google.com with ESMTPSA id b7sm20545858pba.39.2013.05.25.06.51.19 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 25 May 2013 06:51:23 -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 v3, part1 02/10] PCI: Introduce pci_alloc_dev(struct pci_bus*) to replace alloc_pci_dev() Date: Sat, 25 May 2013 21:48:30 +0800 Message-Id: <1369489718-25869-3-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1369489718-25869-1-git-send-email-jiang.liu@huawei.com> References: <1369489718-25869-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 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 This also makes it safe to reference pci_dev->bus when holding a reference on a pci_dev. Also change __deprecated struct pci_dev * alloc_pci_dev(void); to struct pci_dev * __deprecated alloc_pci_dev(void); to follow common coding style. 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 | 18 ++++++++++++------ include/linux/pci.h | 3 ++- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 70f10fa..26df9c8 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1200,19 +1200,25 @@ 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); - dev->dev.type = &pci_dev_type; + if (dev) { + INIT_LIST_HEAD(&dev->bus_list); + dev->dev.type = &pci_dev_type; + 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 7556c59..b0f4a82 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)