提交 f77283f2 编写于 作者: R Rafael J. Wysocki 提交者: Yang Yingliang

ACPI: EC: Reference count query handlers under lock

stable inclusion
from linux-4.19.149
commit 4913d773d113b1f61620baeadaa9d8ef3a4400c1

--------------------------------

[ Upstream commit 3df663a1 ]

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: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: NSasha Levin <sashal@kernel.org>
Signed-off-by: NYang Yingliang <yangyingliang@huawei.com>
上级 a6f0c975
...@@ -1080,29 +1080,21 @@ void acpi_ec_dispatch_gpe(void) ...@@ -1080,29 +1080,21 @@ void acpi_ec_dispatch_gpe(void)
/* -------------------------------------------------------------------------- /* --------------------------------------------------------------------------
Event Management 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 * static struct acpi_ec_query_handler *
acpi_ec_get_query_handler_by_value(struct acpi_ec *ec, u8 value) acpi_ec_get_query_handler_by_value(struct acpi_ec *ec, u8 value)
{ {
struct acpi_ec_query_handler *handler; struct acpi_ec_query_handler *handler;
bool found = false;
mutex_lock(&ec->mutex); mutex_lock(&ec->mutex);
list_for_each_entry(handler, &ec->list, node) { list_for_each_entry(handler, &ec->list, node) {
if (value == handler->query_bit) { if (value == handler->query_bit) {
found = true; kref_get(&handler->kref);
break; mutex_unlock(&ec->mutex);
return handler;
} }
} }
mutex_unlock(&ec->mutex); 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) static void acpi_ec_query_handler_release(struct kref *kref)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册