diff options
author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2019-12-27 11:04:21 +0100 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2020-10-01 20:40:05 +0200 |
commit | 0516e42c7b0263721cee45429ac97eed6aff603c (patch) | |
tree | 1146e309aaf22f816ae583b68ef6e965e2ae301c | |
parent | 318a2c03e3827d41431ab2b56c52a91157d4fb2f (diff) | |
download | linux-stable-0516e42c7b0263721cee45429ac97eed6aff603c.tar.gz linux-stable-0516e42c7b0263721cee45429ac97eed6aff603c.tar.bz2 linux-stable-0516e42c7b0263721cee45429ac97eed6aff603c.zip |
ACPI: EC: Reference count query handlers under lock
[ Upstream commit 3df663a147fe077a6ee8444ec626738946e65547 ]
There is a race condition in acpi_ec_get_query_handler()
theoretically allowing query handlers to go away before refernce
counting them.
In order to avoid it, call kref_get() on query handlers under
ec->mutex.
Also simplify the code a bit while at it.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r-- | drivers/acpi/ec.c | 16 |
1 files changed, 4 insertions, 12 deletions
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index 307b3e28f34c..8781b5dc97f1 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -1050,28 +1050,20 @@ void acpi_ec_unblock_transactions(void) Event Management -------------------------------------------------------------------------- */ static struct acpi_ec_query_handler * -acpi_ec_get_query_handler(struct acpi_ec_query_handler *handler) -{ - if (handler) - kref_get(&handler->kref); - return handler; -} - -static struct acpi_ec_query_handler * acpi_ec_get_query_handler_by_value(struct acpi_ec *ec, u8 value) { struct acpi_ec_query_handler *handler; - bool found = false; mutex_lock(&ec->mutex); list_for_each_entry(handler, &ec->list, node) { if (value == handler->query_bit) { - found = true; - break; + kref_get(&handler->kref); + mutex_unlock(&ec->mutex); + return handler; } } mutex_unlock(&ec->mutex); - return found ? acpi_ec_get_query_handler(handler) : NULL; + return NULL; } static void acpi_ec_query_handler_release(struct kref *kref) |