From patchwork Fri Jan 18 16:07:39 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 2003821 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 9E9E5DF5B1 for ; Fri, 18 Jan 2013 16:10:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754466Ab3ARQIJ (ORCPT ); Fri, 18 Jan 2013 11:08:09 -0500 Received: from mail-da0-f45.google.com ([209.85.210.45]:64202 "EHLO mail-da0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751686Ab3ARQIG (ORCPT ); Fri, 18 Jan 2013 11:08:06 -0500 Received: by mail-da0-f45.google.com with SMTP id w4so1685029dam.18 for ; Fri, 18 Jan 2013 08:08:05 -0800 (PST) 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=8wV9Lqm/6v8BkmHmgP1U4Xjjitg47M6uoVdCe/vrnyI=; b=LGeoPe9E0+B5cTtqv+avCZP7q3sN+rOGkzvqGvTi6t1ievU4TAdt7VZkWqWSIirhb+ bCGUqByswYI5TAygiZTUhLLDuhuNdNOMrr85+J5fXhuuIxOaDezWNzPFFZRXbmnrKCCi WzagsH71cktjs5ovodD78W/3mX7NKzCm3kV5Ae0IDJqTJ9n0LVKzfDRzCTaKMmsBk5v8 ZJukZohT8GXRwx5mwFO0V+sOsgWqKgCTVZewVAPQXNkUbOJyEfeKzYaZ05yJ8K7vZab9 OdAMVhEHxVUlNMjjqooyttNxdoc+rP3qoNmXAg+21ei5BMx/O6rJBB90nFhp82hVsjkq KrOQ== X-Received: by 10.68.217.98 with SMTP id ox2mr6507131pbc.96.1358525284254; Fri, 18 Jan 2013 08:08:04 -0800 (PST) Received: from localhost.localdomain ([120.197.109.98]) by mx.google.com with ESMTPS id ux4sm3320742pbc.25.2013.01.18.08.08.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 18 Jan 2013 08:08:03 -0800 (PST) From: Jiang Liu To: "Rafael J . Wysocki" , Bjorn Helgaas Cc: Jiang Liu , Yinghai Lu , Kenji Kaneshige , Yijing Wang , Jiang Liu , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Greg Kroah-Hartman , ACPI Devel Maling List , Toshi Kani , Myron Stowe Subject: [RFC PATCH v5 1/8] PCI: make PCI device create/destroy logic symmetric Date: Sat, 19 Jan 2013 00:07:39 +0800 Message-Id: <1358525267-14268-2-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1358525267-14268-1-git-send-email-jiang.liu@huawei.com> References: <1358525267-14268-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 According to device model documentation, the way to create/destroy PCI devices should be symmetric. /** * device_del - delete device from system. * @dev: device. * * This is the first part of the device unregistration * sequence. This removes the device from the lists we control * from here, has it removed from the other driver model * subsystems it was added to in device_add(), and removes it * from the kobject hierarchy. * * NOTE: this should be called manually _iff_ device_add() was * also called manually. */ The rule is to either use 1) device_register()/device_unregister() or 2) device_initialize()/device_add()/device_del()/put_device(). So change PCI core logic to follow the rule and get rid of the redundant pci_dev_get()/pci_dev_put() pair. Signed-off-by: Jiang Liu Acked-by: Bjorn Helgaas Reviewed-by: Yinghai Lu --- drivers/pci/probe.c | 1 - drivers/pci/remove.c | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 4f7f963..ec5d28f 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1294,7 +1294,6 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus) { device_initialize(&dev->dev); dev->dev.release = pci_release_dev; - pci_dev_get(dev); dev->dev.dma_mask = &dev->dma_mask; dev->dev.dma_parms = &dev->dma_parms; diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c index 513972f..10693f5 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -22,7 +22,7 @@ static void pci_stop_dev(struct pci_dev *dev) if (dev->is_added) { pci_proc_detach_device(dev); pci_remove_sysfs_dev_files(dev); - device_unregister(&dev->dev); + device_del(&dev->dev); dev->is_added = 0; } @@ -37,7 +37,7 @@ static void pci_destroy_dev(struct pci_dev *dev) up_write(&pci_bus_sem); pci_free_resources(dev); - pci_dev_put(dev); + put_device(&dev->dev); } void pci_remove_bus(struct pci_bus *bus)