From patchwork Tue Aug 28 15:43:58 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 180511 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 9C32E2C009D for ; Wed, 29 Aug 2012 01:45:40 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753461Ab2H1Po7 (ORCPT ); Tue, 28 Aug 2012 11:44:59 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:56281 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753093Ab2H1Po6 (ORCPT ); Tue, 28 Aug 2012 11:44:58 -0400 Received: by mail-pb0-f46.google.com with SMTP id rr13so9582872pbb.19 for ; Tue, 28 Aug 2012 08:44:57 -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=r18g3sEcn8rPD4uL2mm5VhQMkIviQoV01fADrTOGgD4=; b=qQB18mcc7JdplX7/OlJOelbhxxvkrOjuYJUr695gUaAzYX+tP0Y+SlgraWcf+RkeqL JVc4uD7CLdvzmTBogrMtY3hIt1zXA0wTtOMZFHWSaWjRVR/kFPeleqSzwVwtgEEjW1Cp hJmBeHiltIgzG9IGqTQIQOnnMzuPmXVJXu2z5PQ2CZELJ3UAMJCPa0w8fT5LHbxXOjp9 eqsEwLSKzSPxcpLi3Nhnaay/eZVgwoDW82RhJt1GWdo6tl+1ctwozuG+850xTxl4FtEK 3kFOMgGq+nrnAUkBqpapHRIXk/ZGRG+oT8GA1QoCk1aZjjpCTeJdfxPjkHnnOG1x95Kf pzhw== Received: by 10.66.78.195 with SMTP id d3mr38551377pax.17.1346168697774; Tue, 28 Aug 2012 08:44:57 -0700 (PDT) Received: from localhost.localdomain ([58.250.81.2]) by mx.google.com with ESMTPS id tq4sm17276577pbc.11.2012.08.28.08.44.50 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 28 Aug 2012 08:44:55 -0700 (PDT) From: Jiang Liu To: Bjorn Helgaas , Konrad Rzeszutek Wilk Cc: Jiang Liu , Don Dutile , Yinghai Lu , Kenji Kaneshige , Yijing Wang , linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Subject: [PATCH 5/5] PCI/xen-pcifront: simplify code by hotplug safe pci_get_domain_bus_and_slot() Date: Tue, 28 Aug 2012 23:43:58 +0800 Message-Id: <1346168638-32724-6-git-send-email-jiang.liu@huawei.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1346168638-32724-1-git-send-email-jiang.liu@huawei.com> References: <1346168638-32724-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 Following code has a race window between pci_find_bus() and pci_get_slot() if PCI hotplug operation happens between them which removes the pci_bus. So use PCI hotplug safe interface pci_get_domain_bus_and_slot() instead, which also reduces code complexity. struct pci_bus *pci_bus = pci_find_bus(domain, busno); struct pci_dev *pci_dev = pci_get_slot(pci_bus, devfn); Signed-off-by: Jiang Liu Acked-by: Konrad Rzeszutek Wilk Tested-by: Konrad Rzeszutek Wilk --- drivers/pci/xen-pcifront.c | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/drivers/pci/xen-pcifront.c b/drivers/pci/xen-pcifront.c index d6cc62c..def8d0b 100644 --- a/drivers/pci/xen-pcifront.c +++ b/drivers/pci/xen-pcifront.c @@ -982,7 +982,6 @@ static int pcifront_detach_devices(struct pcifront_device *pdev) int err = 0; int i, num_devs; unsigned int domain, bus, slot, func; - struct pci_bus *pci_bus; struct pci_dev *pci_dev; char str[64]; @@ -1032,13 +1031,8 @@ static int pcifront_detach_devices(struct pcifront_device *pdev) goto out; } - pci_bus = pci_find_bus(domain, bus); - if (!pci_bus) { - dev_dbg(&pdev->xdev->dev, "Cannot get bus %04x:%02x\n", - domain, bus); - continue; - } - pci_dev = pci_get_slot(pci_bus, PCI_DEVFN(slot, func)); + pci_dev = pci_get_domain_bus_and_slot(domain, bus, + PCI_DEVFN(slot, func)); if (!pci_dev) { dev_dbg(&pdev->xdev->dev, "Cannot get PCI device %04x:%02x:%02x.%d\n",