Skip to content

Commit 28f7b85

Browse files
Wer-Wolfrafaeljw
authored andcommitted
ACPI: EC: Limit explicit removal of query handlers to custom query handlers
According to the ACPI spec part 5.6.4.1.2, EC query handlers discovered thru ACPI should not be removed when a driver removes his custom query handler. On the Acer Travelmate 4002WLMi for example, such a query handler is used as a fallback to handle the EC SMBus alert when no driver is present. Change acpi_ec_remove_query_handlers() so that only custom query handlers are removed then remove_all is false. Query handlers discovered thru ACPI will still get removed when remove_all is true, which happens on device removal. Also add a simple check to ensure that acpi_ec_add_query_handler() is always called with either handle or func being set, since custom query handlers are detected based whether handlers->func is set or not. Tested on a Acer Travelmate 4002WLMi. Signed-off-by: Armin Wolf <W_Armin@gmx.de> [ rjw: Comment adjustment ] Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 197b6b6 commit 28f7b85

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

drivers/acpi/ec.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,9 +1083,12 @@ int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit,
10831083
acpi_handle handle, acpi_ec_query_func func,
10841084
void *data)
10851085
{
1086-
struct acpi_ec_query_handler *handler =
1087-
kzalloc(sizeof(struct acpi_ec_query_handler), GFP_KERNEL);
1086+
struct acpi_ec_query_handler *handler;
1087+
1088+
if (!handle && !func)
1089+
return -EINVAL;
10881090

1091+
handler = kzalloc(sizeof(*handler), GFP_KERNEL);
10891092
if (!handler)
10901093
return -ENOMEM;
10911094

@@ -1097,6 +1100,7 @@ int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit,
10971100
kref_init(&handler->kref);
10981101
list_add(&handler->node, &ec->list);
10991102
mutex_unlock(&ec->mutex);
1103+
11001104
return 0;
11011105
}
11021106
EXPORT_SYMBOL_GPL(acpi_ec_add_query_handler);
@@ -1109,9 +1113,16 @@ static void acpi_ec_remove_query_handlers(struct acpi_ec *ec,
11091113

11101114
mutex_lock(&ec->mutex);
11111115
list_for_each_entry_safe(handler, tmp, &ec->list, node) {
1112-
if (remove_all || query_bit == handler->query_bit) {
1116+
/*
1117+
* When remove_all is false, only remove custom query handlers
1118+
* which have handler->func set. This is done to preserve query
1119+
* handlers discovered thru ACPI, as they should continue handling
1120+
* EC queries.
1121+
*/
1122+
if (remove_all || (handler->func && handler->query_bit == query_bit)) {
11131123
list_del_init(&handler->node);
11141124
list_add(&handler->node, &free_list);
1125+
11151126
}
11161127
}
11171128
mutex_unlock(&ec->mutex);

0 commit comments

Comments
 (0)