From patchwork Tue Aug 7 16:10:53 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 1286891 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 17E543FC23 for ; Tue, 7 Aug 2012 16:23:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755649Ab2HGQXD (ORCPT ); Tue, 7 Aug 2012 12:23:03 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:51364 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755642Ab2HGQUc (ORCPT ); Tue, 7 Aug 2012 12:20:32 -0400 Received: by mail-pb0-f46.google.com with SMTP id rr13so4529963pbb.19 for ; Tue, 07 Aug 2012 09:20:32 -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=kA5fsUzvZ6zvv/rK/EMEYc5MNggv8Xc3Oz3tvV/UDbY=; b=ymiDxlvhyfxDVLdaWkz0bn/hjo0yU0ItsZqd3WzLQUI5H1Y4rUSGSCAjcOFJgt0gGM Tm1TUoe5UDKUC70CkdpwhP609X9XexmW1Hxdt5zXxbCVAS/GjKXDhT/6dmmNtdjAdPgd aEDjidonBOEgWtC172Py2HY3SjcTE9K3bysNVQvMxJWFljNUulHEpaHKlDJZS5e/Ewyi 1W1lEM6gVo0PGnYSkjJQmERPNqZNnOQbMrsgqTeNzC9cF0nhopP9g4GiHL71Ks4cCI6x mkyIvyKSZyIMxkfTwPEoZbK3etUaUAlfM+OGGMHUw0dfkR0NWgqUTQVvf/rQzGio4ojF NUKw== Received: by 10.68.191.72 with SMTP id gw8mr29313028pbc.143.1344356432400; Tue, 07 Aug 2012 09:20:32 -0700 (PDT) Received: from localhost.localdomain ([58.250.81.2]) by mx.google.com with ESMTPS id pt2sm11429362pbb.58.2012.08.07.09.20.24 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 07 Aug 2012 09:20:31 -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 13/22] PCI: make each PCI device hold a reference to its parent PCI bus Date: Wed, 8 Aug 2012 00:10:53 +0800 Message-Id: <1344355862-2726-14-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 Make each PCI device hold a reference to its parent PCI bus, so it won't cause invalid memory access when doing: pci_bus_lock_states(dev->bus, PCI_BUS_STATE_xxxx); Signed-off-by: Jiang Liu --- drivers/pci/iov.c | 3 ++- drivers/pci/probe.c | 2 +- drivers/pci/remove.c | 1 + 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c index c7d2969..40f5f52 100644 --- a/drivers/pci/iov.c +++ b/drivers/pci/iov.c @@ -92,7 +92,8 @@ static int virtfn_add(struct pci_dev *dev, int id, int reset) kfree(virtfn); mutex_unlock(&iov->dev->sriov->lock); return -ENOMEM; - } + } else + pci_bus_get(virtfn->bus); virtfn->devfn = virtfn_devfn(dev, id); virtfn->vendor = dev->vendor; pci_read_config_word(dev, iov->pos + PCI_SRIOV_VF_DID, &virtfn->device); diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c index e6b40d0..47bf071 100644 --- a/drivers/pci/probe.c +++ b/drivers/pci/probe.c @@ -1272,7 +1272,7 @@ static struct pci_dev *pci_scan_device(struct pci_bus *bus, int devfn) if (!dev) return NULL; - dev->bus = bus; + dev->bus = pci_bus_get(bus); dev->devfn = devfn; dev->vendor = l & 0xffff; dev->device = (l >> 16) & 0xffff; diff --git a/drivers/pci/remove.c b/drivers/pci/remove.c index a26a841..0d947c0 100644 --- a/drivers/pci/remove.c +++ b/drivers/pci/remove.c @@ -43,6 +43,7 @@ static void pci_destroy_dev(struct pci_dev *dev) dev->bus_list.next = dev->bus_list.prev = NULL; up_write(&pci_bus_sem); pci_free_resources(dev); + pci_bus_put(dev->bus); put_device(&dev->dev); } }