From patchwork Tue Aug 7 16:10:55 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 1286851 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 530AEDF280 for ; Tue, 7 Aug 2012 16:22:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755688Ab2HGQUw (ORCPT ); Tue, 7 Aug 2012 12:20:52 -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 S1755670Ab2HGQUu (ORCPT ); Tue, 7 Aug 2012 12:20:50 -0400 Received: by mail-pb0-f46.google.com with SMTP id rr13so4529963pbb.19 for ; Tue, 07 Aug 2012 09:20:49 -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=C5d0RABroJDMj8yW4KZpgaLZGbFoJFwWqzQHcQmT/0Q=; b=DQInyHcvDYHoonkbJB49Q0cFJYdpes1eyk5azjQ6ds544Q5lYyxav6c0kAivQKVQ5Z Pw7SpY7VFL14xmiR4OfTmnOeDp2Ji5PDoCKeMKIb/bjvAbNFMik2WvZ6Pe0/7woDIHCK 6XjriwcOMDwy3SVrqP+7FQdPrhBLd6/Etwejg/2fpF0UCZLJW3GRmrXSe5+EhnAUJQO9 I0KNZo2qrjJclA4I9cFZXEmGMpdKhTzSSB1vHwyRSRWPbGS6P6MeA3snKb8HDEWIvgyX cMVaovsbcWL2xuc3jGf+jNKcAZNPdVN1ldLSKSm8WuN8lewH80mmSVjFh6LIY1KrQm6i yssw== Received: by 10.68.241.228 with SMTP id wl4mr28852790pbc.51.1344356449792; Tue, 07 Aug 2012 09:20:49 -0700 (PDT) Received: from localhost.localdomain ([58.250.81.2]) by mx.google.com with ESMTPS id pt2sm11429362pbb.58.2012.08.07.09.20.42 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 07 Aug 2012 09:20:49 -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 15/22] PCI/eeepc: use PCI bus lock to avoid race conditions Date: Wed, 8 Aug 2012 00:10:55 +0800 Message-Id: <1344355862-2726-16-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 This patch uses PCI bus lock mechanism to avoid race conditions when doing PCI device hotplug through eeepc driver. It also fixes a PCI device reference count leakage issue because acpi_get_pci_dev() holds a reference to the device returned. Signed-off-by: Jiang Liu --- drivers/platform/x86/eeepc-laptop.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c index dab91b4..25c4176 100644 --- a/drivers/platform/x86/eeepc-laptop.c +++ b/drivers/platform/x86/eeepc-laptop.c @@ -606,16 +606,16 @@ static void eeepc_rfkill_hotplug(struct eeepc_laptop *eeepc, acpi_handle handle) goto out_unlock; } - bus = port->subordinate; + bus = pci_lock_subordinate(port, PCI_BUS_STATE_WORKING); if (!bus) { pr_warn("Unable to find PCI bus 1?\n"); - goto out_unlock; + goto out_put_dev; } if (pci_bus_read_config_dword(bus, 0, PCI_VENDOR_ID, &l)) { pr_err("Unable to read PCI config space?\n"); - goto out_unlock; + goto out_unlock_bus; } absent = (l == 0xffffffff); @@ -627,7 +627,7 @@ static void eeepc_rfkill_hotplug(struct eeepc_laptop *eeepc, acpi_handle handle) absent ? "absent" : "present"); pr_warn("skipped wireless hotplug as probably " "inappropriate for this model\n"); - goto out_unlock; + goto out_unlock_bus; } if (!blocked) { @@ -635,7 +635,7 @@ static void eeepc_rfkill_hotplug(struct eeepc_laptop *eeepc, acpi_handle handle) if (dev) { /* Device already present */ pci_dev_put(dev); - goto out_unlock; + goto out_unlock_bus; } dev = pci_scan_single_device(bus, 0); if (dev) { @@ -650,6 +650,11 @@ static void eeepc_rfkill_hotplug(struct eeepc_laptop *eeepc, acpi_handle handle) pci_dev_put(dev); } } + +out_unlock_bus: + pci_bus_unlock(bus); +out_put_dev: + pci_dev_put(port); } out_unlock: @@ -757,7 +762,7 @@ static struct hotplug_slot_ops eeepc_hotplug_slot_ops = { static int eeepc_setup_pci_hotplug(struct eeepc_laptop *eeepc) { int ret = -ENOMEM; - struct pci_bus *bus = pci_find_bus(0, 1); + struct pci_bus *bus = pci_get_bus(0, 1); if (!bus) { pr_err("Unable to find wifi PCI bus\n"); @@ -785,6 +790,8 @@ static int eeepc_setup_pci_hotplug(struct eeepc_laptop *eeepc) goto error_register; } + pci_bus_put(bus); + return 0; error_register: @@ -793,6 +800,7 @@ error_info: kfree(eeepc->hotplug_slot); eeepc->hotplug_slot = NULL; error_slot: + pci_bus_put(bus); return ret; }