From patchwork Mon Nov 4 13:36:58 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 3135751 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 71E9BBEEB2 for ; Mon, 4 Nov 2013 13:26:11 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B7CB32054E for ; Mon, 4 Nov 2013 13:26:06 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7024520562 for ; Mon, 4 Nov 2013 13:26:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753224Ab3KDN0B (ORCPT ); Mon, 4 Nov 2013 08:26:01 -0500 Received: from v094114.home.net.pl ([79.96.170.134]:52951 "HELO v094114.home.net.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1752018Ab3KDN0A (ORCPT ); Mon, 4 Nov 2013 08:26:00 -0500 Received: from afjm202.neoplus.adsl.tpnet.pl [95.49.246.202] (HELO vostro.rjw.lan) by serwer1319399.home.pl [79.96.170.134] with SMTP (IdeaSmtpServer v0.80) id 5957bf3d3931b1b7; Mon, 4 Nov 2013 14:25:59 +0100 From: "Rafael J. Wysocki" To: ACPI Devel Maling List Cc: LKML , Linux PCI , Bjorn Helgaas , Toshi Kani , Yinghai Lu Subject: [Update][PATCH 6/6] ACPI / hotplug: Merge device hot-removal routines Date: Mon, 04 Nov 2013 14:36:58 +0100 Message-ID: <7014358.W2jKmobrlg@vostro.rjw.lan> User-Agent: KMail/4.10.5 (Linux/3.12.0-rc6+; KDE/4.10.5; x86_64; ; ) In-Reply-To: <2970389.SeMGM45Qln@vostro.rjw.lan> References: <5839747.7HXXGHmMBd@vostro.rjw.lan> <2970389.SeMGM45Qln@vostro.rjw.lan> MIME-Version: 1.0 Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Rafael J. Wysocki There is no real reasn why acpi_bus_device_eject() and acpi_bus_hot_remove_device() should work differently, so rework acpi_bus_device_eject() so that it can be called internally by both acpi_bus_hot_remove_device() and acpi_eject_store_work(). Accordingly, rework acpi_hotplug_notify_cb() to queue up the execution of acpi_bus_hot_remove_device() through acpi_os_hotplug_execute() on eject request notifications. Signed-off-by: Rafael J. Wysocki --- drivers/acpi/scan.c | 84 +++++++++++++++++++++++----------------------------- 1 file changed, 38 insertions(+), 46 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-pci" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: linux-pm/drivers/acpi/scan.c =================================================================== --- linux-pm.orig/drivers/acpi/scan.c +++ linux-pm/drivers/acpi/scan.c @@ -285,10 +285,9 @@ static int acpi_scan_hot_remove(struct a return 0; } -static void acpi_bus_device_eject(void *context) +static void acpi_bus_device_eject(struct acpi_device *device, u32 ost_src) { - acpi_handle handle = context; - struct acpi_device *device = NULL; + acpi_handle handle = device->handle; struct acpi_scan_handler *handler; u32 ost_code = ACPI_OST_SC_NON_SPECIFIC_FAILURE; int error; @@ -296,20 +295,19 @@ static void acpi_bus_device_eject(void * lock_device_hotplug(); mutex_lock(&acpi_scan_lock); - acpi_bus_get_device(handle, &device); - if (!device) - goto err_out; - handler = device->handler; - if (!handler || !handler->hotplug.enabled) + if (!handler || !handler->hotplug.enabled) { + put_device(&device->dev); goto err_support; + } + + if (ost_src == ACPI_NOTIFY_EJECT_REQUEST) + acpi_evaluate_hotplug_ost(handle, ACPI_NOTIFY_EJECT_REQUEST, + ACPI_OST_SC_EJECT_IN_PROGRESS, NULL); - acpi_evaluate_hotplug_ost(handle, ACPI_NOTIFY_EJECT_REQUEST, - ACPI_OST_SC_EJECT_IN_PROGRESS, NULL); if (handler->hotplug.mode == AHM_CONTAINER) kobject_uevent(&device->dev.kobj, KOBJ_OFFLINE); - get_device(&device->dev); error = acpi_scan_hot_remove(device); if (error == -EPERM) { goto err_support; @@ -325,8 +323,7 @@ static void acpi_bus_device_eject(void * err_support: ost_code = ACPI_OST_SC_EJECT_NOT_SUPPORTED; err_out: - acpi_evaluate_hotplug_ost(handle, ACPI_NOTIFY_EJECT_REQUEST, ost_code, - NULL); + acpi_evaluate_hotplug_ost(handle, ost_src, ost_code, NULL); goto out; } @@ -408,10 +405,20 @@ static void acpi_hotplug_unsupported(acp acpi_evaluate_hotplug_ost(handle, type, ost_status, NULL); } +/** + * acpi_bus_hot_remove_device: Hot-remove a device and its children. + * @context: Address of the ACPI device object to hot-remove. + */ +void acpi_bus_hot_remove_device(void *context) +{ + acpi_bus_device_eject(context, ACPI_NOTIFY_EJECT_REQUEST); +} + static void acpi_hotplug_notify_cb(acpi_handle handle, u32 type, void *data) { acpi_osd_exec_callback callback; struct acpi_scan_handler *handler = data; + struct acpi_device *adev; acpi_status status; if (!handler->hotplug.enabled) @@ -428,44 +435,29 @@ static void acpi_hotplug_notify_cb(acpi_ break; case ACPI_NOTIFY_EJECT_REQUEST: acpi_handle_debug(handle, "ACPI_NOTIFY_EJECT_REQUEST event\n"); - callback = acpi_bus_device_eject; - break; + status = acpi_bus_get_device(handle, &adev); + if (ACPI_FAILURE(status)) + goto err_out; + + get_device(&adev->dev); + callback = acpi_bus_hot_remove_device; + status = acpi_os_hotplug_execute(callback, adev); + if (ACPI_SUCCESS(status)) + return; + + put_device(&adev->dev); + goto err_out; default: /* non-hotplug event; possibly handled by other handler */ return; } status = acpi_os_hotplug_execute(callback, handle); - if (ACPI_FAILURE(status)) - acpi_evaluate_hotplug_ost(handle, type, - ACPI_OST_SC_NON_SPECIFIC_FAILURE, - NULL); -} - -void __acpi_bus_hot_remove_device(struct acpi_device *device, u32 ost_src) -{ - acpi_handle handle = device->handle; - int error; - - lock_device_hotplug(); - mutex_lock(&acpi_scan_lock); - - error = acpi_scan_hot_remove(device); - if (error && handle) - acpi_evaluate_hotplug_ost(handle, ost_src, - ACPI_OST_SC_NON_SPECIFIC_FAILURE, - NULL); - - mutex_unlock(&acpi_scan_lock); - unlock_device_hotplug(); -} + if (ACPI_SUCCESS(status)) + return; -/** - * acpi_bus_hot_remove_device: Hot-remove a device and its children. - * @context: Address of the ACPI device object to hot-remove. - */ -void acpi_bus_hot_remove_device(void *context) -{ - __acpi_bus_hot_remove_device(context, ACPI_NOTIFY_EJECT_REQUEST); + err_out: + acpi_evaluate_hotplug_ost(handle, type, + ACPI_OST_SC_NON_SPECIFIC_FAILURE, NULL); } static ssize_t real_power_state_show(struct device *dev, @@ -496,7 +488,7 @@ static DEVICE_ATTR(power_state, 0444, po static void acpi_eject_store_work(void *context) { - __acpi_bus_hot_remove_device(context, ACPI_OST_EC_OSPM_EJECT); + acpi_bus_device_eject(context, ACPI_OST_EC_OSPM_EJECT); } static ssize_t