From f1cd1fe61b96e4312312d42c0a9784dfab12e007 Mon Sep 17 00:00:00 2001 From: Alexey Starikovskiy Date: Fri, 3 Aug 2007 17:28:17 -0400 Subject: [PATCH 1/7] ACPI: EC: Remove noisy debug printk fron EC driver. ACPI: EC: Handler for query 0x57 is not found! Signed-off-by: Alexey Starikovskiy Signed-off-by: Len Brown --- drivers/acpi/ec.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index 469f3f57f881..dd384ec757dd 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -471,7 +471,6 @@ static void acpi_ec_gpe_query(void *ec_cxt) } } mutex_unlock(&ec->lock); - printk(KERN_ERR PREFIX "Handler for query 0x%x is not found!\n", value); } static u32 acpi_ec_gpe_handler(void *data) From cd8c93a4e04dce8f00d1ef3a476aac8bd65ae40b Mon Sep 17 00:00:00 2001 From: Alexey Starikovskiy Date: Fri, 3 Aug 2007 17:52:48 -0400 Subject: [PATCH 2/7] ACPI: EC: If ECDT is not found, look up EC in DSDT. Some ASUS laptops access EC space from device _INI methods, but do not provide ECDT for early EC setup. In order to make them function properly, there is a need to find EC is DSDT before any _INI is called. Similar functionality was turned on by acpi_fake_ecdt=1 command line before. Now it is on all the time. http://bugzilla.kernel.org/show_bug.cgi?id=8598 Signed-off-by: Alexey Starikovskiy Signed-off-by: Len Brown --- drivers/acpi/ec.c | 50 ++++++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 22 deletions(-) diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index dd384ec757dd..4d7fe829a6e2 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -664,30 +664,32 @@ acpi_ec_register_query_methods(acpi_handle handle, u32 level, return AE_OK; } -static int ec_parse_device(struct acpi_ec *ec, acpi_handle handle) +static acpi_status +ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval) { - if (ACPI_FAILURE(acpi_walk_resources(handle, METHOD_NAME__CRS, - ec_parse_io_ports, ec))) - return -EINVAL; + acpi_status status; + + struct acpi_ec *ec = context; + status = acpi_walk_resources(handle, METHOD_NAME__CRS, + ec_parse_io_ports, ec); + if (ACPI_FAILURE(status)) + return status; /* Get GPE bit assignment (EC events). */ /* TODO: Add support for _GPE returning a package */ - if (ACPI_FAILURE(acpi_evaluate_integer(handle, "_GPE", NULL, &ec->gpe))) - return -EINVAL; + status = acpi_evaluate_integer(handle, "_GPE", NULL, &ec->gpe); + if (ACPI_FAILURE(status)) + return status; /* Use the global lock for all EC transactions? */ acpi_evaluate_integer(handle, "_GLK", NULL, &ec->global_lock); - /* Find and register all query methods */ - acpi_walk_namespace(ACPI_TYPE_METHOD, handle, 1, - acpi_ec_register_query_methods, ec, NULL); - ec->handle = handle; printk(KERN_INFO PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx", ec->gpe, ec->command_addr, ec->data_addr); - return 0; + return AE_CTRL_TERMINATE; } static int acpi_ec_add(struct acpi_device *device) @@ -704,7 +706,8 @@ static int acpi_ec_add(struct acpi_device *device) if (!ec) return -ENOMEM; - if (ec_parse_device(ec, device->handle)) { + if (ec_parse_device(device->handle, 0, ec, NULL) != + AE_CTRL_TERMINATE) { kfree(ec); return -EINVAL; } @@ -867,18 +870,21 @@ int __init acpi_ec_ecdt_probe(void) /* * Generate a boot ec context */ - status = acpi_get_table(ACPI_SIG_ECDT, 1, (struct acpi_table_header **)&ecdt_ptr); - if (ACPI_FAILURE(status)) - goto error; - - printk(KERN_INFO PREFIX "EC description table is found, configuring boot EC\n"); - - boot_ec->command_addr = ecdt_ptr->control.address; - boot_ec->data_addr = ecdt_ptr->data.address; - boot_ec->gpe = ecdt_ptr->gpe; - boot_ec->handle = ACPI_ROOT_OBJECT; + if (ACPI_SUCCESS(status)) { + printk(KERN_INFO PREFIX "EC description table is found, configuring boot EC\n\n"); + boot_ec->command_addr = ecdt_ptr->control.address; + boot_ec->data_addr = ecdt_ptr->data.address; + boot_ec->gpe = ecdt_ptr->gpe; + boot_ec->handle = ACPI_ROOT_OBJECT; + } else { + printk(KERN_DEBUG PREFIX "Look up EC in DSDT\n"); + status = acpi_get_devices(ec_device_ids[0].id, ec_parse_device, + boot_ec, NULL); + if (ACPI_FAILURE(status)) + goto error; + } ret = ec_install_handlers(boot_ec); if (!ret) { From 52fe4bdf40bc07498c5f7935551774e8f8458190 Mon Sep 17 00:00:00 2001 From: Len Brown Date: Fri, 3 Aug 2007 17:55:53 -0400 Subject: [PATCH 3/7] ACPI: EC: fix build warning MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit drivers/acpi/ec.c:657: warning: ‘acpi_ec_register_query_methods’ defined but not used Signed-off-by: Len Brown --- drivers/acpi/ec.c | 13 ------------- 1 file changed, 13 deletions(-) diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index 4d7fe829a6e2..629289034b61 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -651,19 +651,6 @@ static struct acpi_ec *make_acpi_ec(void) return ec; } -static acpi_status -acpi_ec_register_query_methods(acpi_handle handle, u32 level, - void *context, void **return_value) -{ - struct acpi_namespace_node *node = handle; - struct acpi_ec *ec = context; - int value = 0; - if (sscanf(node->name.ascii, "_Q%x", &value) == 1) { - acpi_ec_add_query_handler(ec, value, handle, NULL, NULL); - } - return AE_OK; -} - static acpi_status ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval) { From 7c010de7506954e973abfab5c5999c5a97f7a73e Mon Sep 17 00:00:00 2001 From: Alexey Starikovskiy Date: Fri, 3 Aug 2007 17:57:53 -0400 Subject: [PATCH 4/7] ACPI: EC: Switch from boot_ec as soon as we find its desc in DSDT. Some ASUS laptops fail to use boot time EC and need to eventually switch to one described in DSDT. http://bugzilla.kernel.org/show_bug.cgi?id=8709 Signed-off-by: Alexey Starikovskiy Signed-off-by: Len Brown --- drivers/acpi/ec.c | 45 ++++++++++++++++----------------------------- 1 file changed, 16 insertions(+), 29 deletions(-) diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index 629289034b61..71caa7d983a3 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -679,6 +679,14 @@ ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval) return AE_CTRL_TERMINATE; } +static void ec_remove_handlers(struct acpi_ec *ec) +{ + acpi_remove_address_space_handler(ec->handle, + ACPI_ADR_SPACE_EC, + &acpi_ec_space_handler); + acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler); +} + static int acpi_ec_add(struct acpi_device *device) { struct acpi_ec *ec = NULL; @@ -702,16 +710,15 @@ static int acpi_ec_add(struct acpi_device *device) /* Check if we found the boot EC */ if (boot_ec) { if (boot_ec->gpe == ec->gpe) { - /* We might have incorrect info for GL at boot time */ mutex_lock(&boot_ec->lock); - boot_ec->global_lock = ec->global_lock; - /* Copy handlers from new ec into boot ec */ - list_splice(&ec->list, &boot_ec->list); + ec_remove_handlers(boot_ec); mutex_unlock(&boot_ec->lock); - kfree(ec); - ec = boot_ec; + mutex_destroy(&boot_ec->lock); + kfree(boot_ec); + first_ec = boot_ec = NULL; } - } else + } + if (!first_ec) first_ec = ec; ec->handle = device->handle; acpi_driver_data(device) = ec; @@ -740,9 +747,6 @@ static int acpi_ec_remove(struct acpi_device *device, int type) if (ec == first_ec) first_ec = NULL; - /* Don't touch boot EC */ - if (boot_ec != ec) - kfree(ec); return 0; } @@ -806,9 +810,7 @@ static int acpi_ec_start(struct acpi_device *device) if (!ec) return -EINVAL; - /* Boot EC is already working */ - if (ec != boot_ec) - ret = ec_install_handlers(ec); + ret = ec_install_handlers(ec); /* EC is fully operational, allow queries */ atomic_set(&ec->query_pending, 0); @@ -818,7 +820,6 @@ static int acpi_ec_start(struct acpi_device *device) static int acpi_ec_stop(struct acpi_device *device, int type) { - acpi_status status; struct acpi_ec *ec; if (!device) @@ -827,21 +828,7 @@ static int acpi_ec_stop(struct acpi_device *device, int type) ec = acpi_driver_data(device); if (!ec) return -EINVAL; - - /* Don't touch boot EC */ - if (ec == boot_ec) - return 0; - - status = acpi_remove_address_space_handler(ec->handle, - ACPI_ADR_SPACE_EC, - &acpi_ec_space_handler); - if (ACPI_FAILURE(status)) - return -ENODEV; - - status = acpi_remove_gpe_handler(NULL, ec->gpe, &acpi_ec_gpe_handler); - if (ACPI_FAILURE(status)) - return -ENODEV; - + ec_remove_handlers(ec); return 0; } From 07ddf768d860bee7bd6581b7af3ce1009dbd05d0 Mon Sep 17 00:00:00 2001 From: Adrian Bunk Date: Sun, 29 Jul 2007 17:00:37 +0200 Subject: [PATCH 5/7] ACPI: EC: acpi_ec_remove(): fix use-after-free This patch fixes an obvious use-after-free introduced by commit 837012ede14a8fc088be3682c964da7fc6af026b. Spotted by the Coverity checker. Signed-off-by: Adrian Bunk Acked-by: Alexey Starikovskiy Signed-off-by: Len Brown --- drivers/acpi/ec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index 71caa7d983a3..b649ac7122a5 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -730,14 +730,14 @@ static int acpi_ec_add(struct acpi_device *device) static int acpi_ec_remove(struct acpi_device *device, int type) { struct acpi_ec *ec; - struct acpi_ec_query_handler *handler; + struct acpi_ec_query_handler *handler, *tmp; if (!device) return -EINVAL; ec = acpi_driver_data(device); mutex_lock(&ec->lock); - list_for_each_entry(handler, &ec->list, node) { + list_for_each_entry_safe(handler, tmp, &ec->list, node) { list_del(&handler->node); kfree(handler); } From 0a5245099819b0ae0a8e985f54909ba8414faba5 Mon Sep 17 00:00:00 2001 From: Meelis Roos Date: Thu, 26 Jul 2007 12:56:55 +0300 Subject: [PATCH 6/7] ACPI: EC: fix run-together printk lines Signed-off-by: Meelis Roos Signed-off-by: Len Brown --- drivers/acpi/ec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index b649ac7122a5..b28b56524f0b 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -673,7 +673,7 @@ ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval) ec->handle = handle; - printk(KERN_INFO PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx", + printk(KERN_INFO PREFIX "GPE = 0x%lx, I/O: command/status = 0x%lx, data = 0x%lx\n", ec->gpe, ec->command_addr, ec->data_addr); return AE_CTRL_TERMINATE; From 199e9e7d1106686a85ee9fdf6a824051aa82682e Mon Sep 17 00:00:00 2001 From: Alexey Starikovskiy Date: Fri, 10 Aug 2007 13:45:18 -0700 Subject: [PATCH 7/7] ACPI EC: remove potential deadlock from EC Signed-off-by: Alexey Starikovskiy Signed-off-by: Andrew Morton Signed-off-by: Len Brown --- drivers/acpi/ec.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index b28b56524f0b..2300d81bbc4e 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -710,9 +710,7 @@ static int acpi_ec_add(struct acpi_device *device) /* Check if we found the boot EC */ if (boot_ec) { if (boot_ec->gpe == ec->gpe) { - mutex_lock(&boot_ec->lock); ec_remove_handlers(boot_ec); - mutex_unlock(&boot_ec->lock); mutex_destroy(&boot_ec->lock); kfree(boot_ec); first_ec = boot_ec = NULL;