From patchwork Thu Nov 7 00:14:57 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: 3150061 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 605F4BEEB2 for ; Thu, 7 Nov 2013 00:02:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5BF1820460 for ; Thu, 7 Nov 2013 00:02:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5B4F42044B for ; Thu, 7 Nov 2013 00:02:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752753Ab3KGACj (ORCPT ); Wed, 6 Nov 2013 19:02:39 -0500 Received: from v094114.home.net.pl ([79.96.170.134]:61998 "HELO v094114.home.net.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1752631Ab3KGACi (ORCPT ); Wed, 6 Nov 2013 19:02:38 -0500 Received: from aerm137.neoplus.adsl.tpnet.pl [79.191.194.137] (HELO vostro.rjw.lan) by serwer1319399.home.pl [79.96.170.134] with SMTP (IdeaSmtpServer v0.80) id d78c3d0cb8cde765; Thu, 7 Nov 2013 01:02:36 +0100 From: "Rafael J. Wysocki" To: Toshi Kani Cc: ACPI Devel Maling List , LKML , Linux PCI , Bjorn Helgaas , Yinghai Lu Subject: Re: [Update][PATCH 4/6] ACPI / hotplug: Simplify device ejection routines Date: Thu, 07 Nov 2013 01:14:57 +0100 Message-ID: <1642586.5aH3MlB2GZ@vostro.rjw.lan> User-Agent: KMail/4.10.5 (Linux/3.12.0-rc6+; KDE/4.10.5; x86_64; ; ) In-Reply-To: <1383780421.1847.50.camel@misato.fc.hp.com> References: <5839747.7HXXGHmMBd@vostro.rjw.lan> <1602442.26cFiMyQkW@vostro.rjw.lan> <1383780421.1847.50.camel@misato.fc.hp.com> 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 On Wednesday, November 06, 2013 04:27:01 PM Toshi Kani wrote: > On Mon, 2013-11-04 at 14:36 +0100, Rafael J. Wysocki wrote: > > From: Rafael J. Wysocki > > > > Simplify handle_root_bridge_removal() and acpi_eject_store() by > > getting rid of struct acpi_eject_event and passing device objects > > directly to async routines executed via acpi_os_hotplug_execute(). > : > > static ssize_t > > acpi_eject_store(struct device *d, struct device_attribute *attr, > > const char *buf, size_t count) > > { > > struct acpi_device *acpi_device = to_acpi_device(d); > > - struct acpi_eject_event *ej_event; > > acpi_object_type not_used; > > acpi_status status; > > - int ret; > > > > if (!count || buf[0] != '1') > > return -EINVAL; > > @@ -518,28 +519,17 @@ acpi_eject_store(struct device *d, struc > > if (ACPI_FAILURE(status) || !acpi_device->flags.ejectable) > > return -ENODEV; > > > > - ej_event = kmalloc(sizeof(*ej_event), GFP_KERNEL); > > - if (!ej_event) { > > - ret = -ENOMEM; > > - goto err_out; > > - } > > acpi_evaluate_hotplug_ost(acpi_device->handle, ACPI_OST_EC_OSPM_EJECT, > > ACPI_OST_SC_EJECT_IN_PROGRESS, NULL); > > - ej_event->device = acpi_device; > > - ej_event->event = ACPI_OST_EC_OSPM_EJECT; > > get_device(&acpi_device->dev); > > - status = acpi_os_hotplug_execute(acpi_bus_hot_remove_device, ej_event); > > + status = acpi_os_hotplug_execute(acpi_eject_store_work, acpi_device); > > if (ACPI_SUCCESS(status)) > > return count; > > > > put_device(&acpi_device->dev); > > - kfree(ej_event); > > - ret = status == AE_NO_MEMORY ? -ENOMEM : -EAGAIN; > > Why are you deleting the above line as part of this change? Ah, because I forgot that acpi_os_hotplug_execute() can also return AE_NO_MEMORY. :-) Good catch, updated pach follows. Thanks, Rafael Acked-by: Toshi Kani --- From: Rafael J. Wysocki Subject: ACPI / hotplug: Simplify device ejection routines Simplify handle_root_bridge_removal() and acpi_eject_store() by getting rid of struct acpi_eject_event and passing device objects directly to async routines executed via acpi_os_hotplug_execute(). Signed-off-by: Rafael J. Wysocki --- drivers/acpi/pci_root.c | 20 ++------------------ drivers/acpi/scan.c | 46 ++++++++++++++++++---------------------------- include/acpi/acpi_bus.h | 5 ----- 3 files changed, 20 insertions(+), 51 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/pci_root.c =================================================================== --- linux-pm.orig/drivers/acpi/pci_root.c +++ linux-pm/drivers/acpi/pci_root.c @@ -593,27 +593,11 @@ static void handle_root_bridge_insertion static void handle_root_bridge_removal(struct acpi_device *device) { acpi_status status; - struct acpi_eject_event *ej_event; - - ej_event = kmalloc(sizeof(*ej_event), GFP_KERNEL); - if (!ej_event) { - /* Inform firmware the hot-remove operation has error */ - (void) acpi_evaluate_hotplug_ost(device->handle, - ACPI_NOTIFY_EJECT_REQUEST, - ACPI_OST_SC_NON_SPECIFIC_FAILURE, - NULL); - return; - } - - ej_event->device = device; - ej_event->event = ACPI_NOTIFY_EJECT_REQUEST; get_device(&device->dev); - status = acpi_os_hotplug_execute(acpi_bus_hot_remove_device, ej_event); - if (ACPI_FAILURE(status)) { + status = acpi_os_hotplug_execute(acpi_bus_hot_remove_device, device); + if (ACPI_FAILURE(status)) put_device(&device->dev); - kfree(ej_event); - } } static void _handle_hotplug_event_root(struct work_struct *work) Index: linux-pm/drivers/acpi/scan.c =================================================================== --- linux-pm.orig/drivers/acpi/scan.c +++ linux-pm/drivers/acpi/scan.c @@ -441,18 +441,8 @@ static void acpi_hotplug_notify_cb(acpi_ NULL); } -/** - * acpi_bus_hot_remove_device: hot-remove a device and its children - * @context: struct acpi_eject_event pointer (freed in this func) - * - * Hot-remove a device and its children. This function frees up the - * memory space passed by arg context, so that the caller may call - * this function asynchronously through acpi_os_hotplug_execute(). - */ -void acpi_bus_hot_remove_device(void *context) +void __acpi_bus_hot_remove_device(struct acpi_device *device, u32 ost_src) { - struct acpi_eject_event *ej_event = context; - struct acpi_device *device = ej_event->device; acpi_handle handle = device->handle; int error; @@ -461,13 +451,21 @@ void acpi_bus_hot_remove_device(void *co error = acpi_scan_hot_remove(device); if (error && handle) - acpi_evaluate_hotplug_ost(handle, ej_event->event, + acpi_evaluate_hotplug_ost(handle, ost_src, ACPI_OST_SC_NON_SPECIFIC_FAILURE, NULL); mutex_unlock(&acpi_scan_lock); unlock_device_hotplug(); - kfree(context); +} + +/** + * 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); } EXPORT_SYMBOL(acpi_bus_hot_remove_device); @@ -497,15 +495,18 @@ static ssize_t power_state_show(struct d static DEVICE_ATTR(power_state, 0444, power_state_show, NULL); +static void acpi_eject_store_work(void *context) +{ + __acpi_bus_hot_remove_device(context, ACPI_OST_EC_OSPM_EJECT); +} + static ssize_t acpi_eject_store(struct device *d, struct device_attribute *attr, const char *buf, size_t count) { struct acpi_device *acpi_device = to_acpi_device(d); - struct acpi_eject_event *ej_event; acpi_object_type not_used; acpi_status status; - int ret; if (!count || buf[0] != '1') return -EINVAL; @@ -518,28 +519,17 @@ acpi_eject_store(struct device *d, struc if (ACPI_FAILURE(status) || !acpi_device->flags.ejectable) return -ENODEV; - ej_event = kmalloc(sizeof(*ej_event), GFP_KERNEL); - if (!ej_event) { - ret = -ENOMEM; - goto err_out; - } acpi_evaluate_hotplug_ost(acpi_device->handle, ACPI_OST_EC_OSPM_EJECT, ACPI_OST_SC_EJECT_IN_PROGRESS, NULL); - ej_event->device = acpi_device; - ej_event->event = ACPI_OST_EC_OSPM_EJECT; get_device(&acpi_device->dev); - status = acpi_os_hotplug_execute(acpi_bus_hot_remove_device, ej_event); + status = acpi_os_hotplug_execute(acpi_eject_store_work, acpi_device); if (ACPI_SUCCESS(status)) return count; put_device(&acpi_device->dev); - kfree(ej_event); - ret = status == AE_NO_MEMORY ? -ENOMEM : -EAGAIN; - - err_out: acpi_evaluate_hotplug_ost(acpi_device->handle, ACPI_OST_EC_OSPM_EJECT, ACPI_OST_SC_NON_SPECIFIC_FAILURE, NULL); - return ret; + return status == AE_NO_MEMORY ? -ENOMEM : -EAGAIN; } static DEVICE_ATTR(eject, 0200, NULL, acpi_eject_store); Index: linux-pm/include/acpi/acpi_bus.h =================================================================== --- linux-pm.orig/include/acpi/acpi_bus.h +++ linux-pm/include/acpi/acpi_bus.h @@ -339,11 +339,6 @@ struct acpi_bus_event { u32 data; }; -struct acpi_eject_event { - struct acpi_device *device; - u32 event; -}; - struct acpi_hp_work { struct work_struct work; acpi_handle handle;