From patchwork Tue Sep 25 14:29:25 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 1504621 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 0CE2FDF24C for ; Tue, 25 Sep 2012 14:35:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754916Ab2IYOdh (ORCPT ); Tue, 25 Sep 2012 10:33:37 -0400 Received: from mail-pa0-f46.google.com ([209.85.220.46]:36607 "EHLO mail-pa0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754429Ab2IYOdc (ORCPT ); Tue, 25 Sep 2012 10:33:32 -0400 Received: by padhz1 with SMTP id hz1so1706002pad.19 for ; Tue, 25 Sep 2012 07:33:31 -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=mJePisD21T7ZyquK6i6aFn5QKMswTM8WpomR6CiqZeg=; b=rOqUQ6eg4nHFfVlXbvvUOCwjyDBAbFNFBKd9B6uE+LDyMDozyuDxPK8fT7pwjxBI7R XXwbPsBUpocMhdkVFH0M2UXL+ShwwBlaoGESf4BaoHQ8Y3MOik156KmpdyYr9ikaZAmw vkJQxRbU9wcFgPT3OJLJPTKkedkh0qRLqjuCNanmemZinpB7jeMb7QlV9M3Cfp2jo039 7TOba+md0vHHxHHAbRrVAxWB/9zui4Kbr0digfoZr7vW6NuWjBDviNXkxquJExq8LVwJ tSeaAyKMftDCaa6LVteh8cN2VLHtbiAVRg74tO+rVQ3d2oblLXVscY2rS/wC21EqMEcg hrdg== Received: by 10.68.234.71 with SMTP id uc7mr35596293pbc.72.1348583611800; Tue, 25 Sep 2012 07:33:31 -0700 (PDT) Received: from localhost.localdomain ([221.221.22.12]) by mx.google.com with ESMTPS id nu8sm415218pbc.45.2012.09.25.07.33.19 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 25 Sep 2012 07:33:31 -0700 (PDT) From: Jiang Liu To: Bjorn Helgaas Cc: Jiang Liu , Yinghai Lu , Kenji Kaneshige , Yijing Wang , Jiang Liu , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Subject: [PATCH v3 2/7] PCI: split registration of PCI bus devices into two stages Date: Tue, 25 Sep 2012 22:29:25 +0800 Message-Id: <1348583370-11006-2-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1348583370-11006-1-git-send-email-jiang.liu@huawei.com> References: <1348583370-11006-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: Jiang Liu When handling BUS_NOTIFY_ADD_DEVICE event for a PCI bridge device, the notification handler can't hold reference count to the new PCI bus because the device object for the new bus (pci_dev->subordinate->dev) hasn't been initialized yet. Split the registration of PCI bus device into two stages as below, so that the event handler could hold reference count to the new PCI bus when handling BUS_NOTIFY_ADD_DEVICE event. 1) device_initialize(&pci_dev->dev) 2) device_initialize(&pci_dev->subordinate->dev) 3) notify BUS_NOTIFY_ADD_DEVICE event for pci_dev 4) device_add(&pci_dev->dev) 5) device_add(&pci_dev->subordinate->dev) Signed-off-by: Jiang Liu Signed-off-by: Yinghai Lu --- drivers/pci/bus.c | 2 +- drivers/pci/probe.c | 4 +++- drivers/pci/remove.c | 10 +++++----- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/pci/bus.c b/drivers/pci/bus.c index 4b0970b..11a5c28 100644 --- a/drivers/pci/bus.c +++ b/drivers/pci/bus.c @@ -189,7 +189,7 @@ int pci_bus_add_child(struct pci_bus *bus) if (bus->bridge) bus->dev.parent = bus->bridge; - retval = device_register(&bus->dev); + retval = device_add(&bus->dev); if (retval) return retval; diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index 5dbad03..7ef8c1b 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -639,6 +639,7 @@ static struct pci_bus *pci_alloc_child_bus(struct pci_bus *parent, */ child->dev.class = &pcibus_class; dev_set_name(&child->dev, "%04x:%02x", pci_domain_nr(child), busnr); + device_initialize(&child->dev); /* * Set up the primary, secondary and subordinate @@ -1672,7 +1673,8 @@ struct pci_bus *pci_create_root_bus(struct device *parent, int bus, b->dev.class = &pcibus_class; b->dev.parent = b->bridge; dev_set_name(&b->dev, "%04x:%02x", pci_domain_nr(b), bus); - error = device_register(&b->dev); + device_initialize(&b->dev); + error = device_add(&b->dev); if (error) goto class_dev_reg_err; diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c index 10693f5..0d03026 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -48,11 +48,11 @@ void pci_remove_bus(struct pci_bus *bus) list_del(&bus->node); pci_bus_release_busn_res(bus); up_write(&pci_bus_sem); - if (!bus->is_added) - return; - - pci_remove_legacy_files(bus); - device_unregister(&bus->dev); + if (bus->is_added) { + pci_remove_legacy_files(bus); + device_del(&bus->dev); + } + put_device(&bus->dev); } EXPORT_SYMBOL(pci_remove_bus);