From patchwork Tue Aug 7 16:10:43 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 1286581 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 4990ADFFEB for ; Tue, 7 Aug 2012 16:19:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755495Ab2HGQTI (ORCPT ); Tue, 7 Aug 2012 12:19:08 -0400 Received: from mail-yw0-f46.google.com ([209.85.213.46]:45249 "EHLO mail-yw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752380Ab2HGQTG (ORCPT ); Tue, 7 Aug 2012 12:19:06 -0400 Received: by yhmm54 with SMTP id m54so3844493yhm.19 for ; Tue, 07 Aug 2012 09:19:06 -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=ZlCxYuii6rwW3mZYQZ0h27xol7Sweu48LCYOApoceeY=; b=tk12Gcvxi5bp6sCd32e03LiP4iLd55Qe2BkL2tiQT+sohFIyeri9vWKf09Q13S4Ula roguORNHRK49K7uKwPJyjG5VL0lXNkjvT7ZPc5ViyeUeDGId511MH2oPNt0yDVYYPGWj Q9r314AdLXr4hIKVNe7MVDMtcGlXusbTsJB7RBQGMHHQtTn6vyjmf5zJpqkb1COYVhkZ 5azj+OkiuFoede7h7n8/T9RBkI+S/4Yl//MkUSD1vBNmKo+aSY0mASd0aEfjf/dy3LYu W8Z5bK7LwJEshmjhAYEyXbUMRphx0mbljMoSIgDeVt4SJFtFwNJzvGGMP6DYihx21B0i ng3w== Received: by 10.66.76.106 with SMTP id j10mr27137056paw.51.1344356345507; Tue, 07 Aug 2012 09:19:05 -0700 (PDT) Received: from localhost.localdomain ([58.250.81.2]) by mx.google.com with ESMTPS id pt2sm11429362pbb.58.2012.08.07.09.18.57 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 07 Aug 2012 09:19:05 -0700 (PDT) From: Jiang Liu To: Bjorn Helgaas , Don Dutile , Yinghai Lu , Greg KH , Kenji Kaneshige Cc: Jiang Liu , Taku Izumi , "Rafael J . Wysocki" , Yijing Wang , Xinwei Hu , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org, Jiang Liu Subject: [RFC PATCH v1 03/22] PCI: change PCI device management code to better follow device model Date: Wed, 8 Aug 2012 00:10:43 +0800 Message-Id: <1344355862-2726-4-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1344355862-2726-1-git-send-email-jiang.liu@huawei.com> References: <1344355862-2726-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 add/remove device object 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 here is to either use 1) device_register()/device_unregister() or 2) device_initialize()/device_add()/device_del()/put_device(). So change PCI core to follow the rule and get rid of the redundant pci_dev_get()/pci_dev_put() pair. Signed-off-by: Jiang Liu --- 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 0840409..dacca26 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 33b6318..b9ac765 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; } @@ -40,7 +40,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); } /**