From patchwork Sat Sep 15 03:05:04 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 1461411 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 477A240220 for ; Sat, 15 Sep 2012 03:15:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756397Ab2IODNe (ORCPT ); Fri, 14 Sep 2012 23:13:34 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:51468 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755862Ab2IODMn (ORCPT ); Fri, 14 Sep 2012 23:12:43 -0400 Received: by mail-pb0-f46.google.com with SMTP id rr13so6508977pbb.19 for ; Fri, 14 Sep 2012 20:12:43 -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=xduUGsjcC2mlYvSIGkqdd5LncOTSZSkHSek1/PgAElI=; b=gB/bKfuzRfD2AaFd4koT3IUXeLSyfweyK1fTghYMyxjKKGWtuiWxtqyHBwcPfRI72p 10/txgfxx/3uuajX8W6txr4glFn/1beHGgmdFQgSJNcwT3N0ME1k8IZjLx7ddP+/EWx+ RhF8ge+yPlP6Cer9fNS2vWxwKpacOCGWYVJ2h3x10PWymQa+NcZa9IyR54XyI+UyHs17 psIN/BiqOXOSalrs9jFvoIU9YV4bcDVGOlkbW1OKHgak0Pa6NRlu0k6PYvjcOmF1hnS0 J9pnuP0MFzMOhGgS6zL8qUpsLro8GB0TEAInZfPY6Pm7ay5ejdvo8NEZdscxWPeWuuYd 7kHw== Received: by 10.68.229.73 with SMTP id so9mr8276343pbc.66.1347678762882; Fri, 14 Sep 2012 20:12:42 -0700 (PDT) Received: from localhost.localdomain ([221.221.18.122]) by mx.google.com with ESMTPS id jz10sm2092777pbc.8.2012.09.14.20.12.35 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 14 Sep 2012 20:12:42 -0700 (PDT) From: Jiang Liu To: Bjorn Helgaas Cc: Tony Luck , Jiang Liu , Yinghai Lu , Kenji Kaneshige , Yijing Wang , Jiang Liu , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Subject: [PATCH v2 1/9] PCI: make PCI device create/destroy logic symmetric Date: Sat, 15 Sep 2012 11:05:04 +0800 Message-Id: <1347678312-11124-2-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1347678312-11124-1-git-send-email-jiang.liu@huawei.com> References: <1347678312-11124-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 --- 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 2396111..5dbad03 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1293,7 +1293,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 4f9ca91..37b9407 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)