From patchwork Tue Jan 8 16:52:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 1946941 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 0ED4E3FED4 for ; Tue, 8 Jan 2013 16:54:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756759Ab3AHQwm (ORCPT ); Tue, 8 Jan 2013 11:52:42 -0500 Received: from mail-da0-f45.google.com ([209.85.210.45]:46271 "EHLO mail-da0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756742Ab3AHQwl (ORCPT ); Tue, 8 Jan 2013 11:52:41 -0500 Received: by mail-da0-f45.google.com with SMTP id w4so278542dam.18 for ; Tue, 08 Jan 2013 08:52:40 -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:in-reply-to:references; bh=YDsqWNBCJ0IgEuUIjZyTAT1ay3oy7Pd1LW48W9pkyJo=; b=yPZU2F24c7RQ6/2AVE7TDq69lGcWZ5y4SleVXaIMSt2QcGl0SOjhQsydHpygOavX2p wp1alNjPwc0OMblhs+YTjHikFr3If4EE+i1cs5bq/fKsBONNxwHvWTCMRXwoZ6ZZjiPR HYoN4Rwoj4aNKRa0g6wdwFV/DfRgGGF8SUS4AlJE+NZ0lnMVEuauD1foZzdBimHaeQhf YQjHbJuIwJJQni9uKIR+7O9htInPM12ap2n+dkCyd/OH42uduhozt8H90DyYLG8222Ig BXLhU9mk5kWodFG/2e9CelII6znSY4Nz1qYqmQkNG38eeX/6W8zmMgG+dBEIenaNo4JK 9ztw== X-Received: by 10.68.234.167 with SMTP id uf7mr200256559pbc.20.1357663960518; Tue, 08 Jan 2013 08:52:40 -0800 (PST) Received: from localhost.localdomain ([120.196.98.117]) by mx.google.com with ESMTPS id f5sm41038922pav.22.2013.01.08.08.52.37 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 08 Jan 2013 08:52:39 -0800 (PST) From: Jiang Liu To: Bjorn Helgaas Cc: Jiang Liu , "Rafael J . Wysocki" , Yijing Wang , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Subject: [PATCH v3 1/6] PCI: make PCI device create/destroy logic symmetric Date: Wed, 9 Jan 2013 00:52:20 +0800 Message-Id: <1357663945-16054-2-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1357663945-16054-1-git-send-email-jiang.liu@huawei.com> References: <1357663945-16054-1-git-send-email-jiang.liu@huawei.com> In-Reply-To: References: 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 6186f03..e557d6f 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1299,7 +1299,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 7c0fd92..fc38c48 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)