acpi/ec.c: Move call to kref_get() to under the mutex_lock(&ec->mutex)
PATCH 1/1 acpi/ec.c: Move call to kref_get() to under the mutex_lock(&ec->mutex)
From: KC27041980 <[email protected]>
Move call to kref_get() to under the mutex_lock(&ec->mutex) as this will remove any delete race scenarios.
Signed-off-by KC27041980 <[email protected]>
--- drivers/acpi/ec.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/acpi/ec.c +5 -1
@@ -1073,8 +1073,12 @@ acpi_ec_get_query_handler_by_value(struct acpi_ec *ec, u8 value)break ; } } + +if (found) +acpi_ec_get_query_handler (handler);mutex_unlock (&ec->mutex); -return found ?acpi_ec_get_query_handler (handler) :NULL ; + +return found ? handler :NULL ; }static void acpi_ec_query_handler_release (struct kref *kref)
Signature · 1 line
2.7.4
Quoted 19 lines · On Monday, November 25, 2019 12:03:18 PM CET [email protected] wrote:
From: KC27041980 <[email protected]>
Move call to
kref_get()to under themutex_lock(&ec->mutex)as this will remove any delete race scenarios.Signed-off-by KC27041980 <[email protected]>--- drivers/acpi/ec.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)drivers/acpi/ec.c +0
-0@@ -1073,8 +1073,12 @@ acpi_ec_get_query_handler_by_value(struct acpi_ec *ec, u8 value)break ; } }
drivers/acpi/ec.c acpi_ec_get_query_handler_by_value(struct acpi_ec *ec, u8 value) · line 1084
Quoted 10 lines
drivers/acpi/ec.c +5
-1+ +if (found) +acpi_ec_get_query_handler (handler);mutex_unlock (&ec->mutex); -return found ?acpi_ec_get_query_handler (handler) :NULL ; + +return found ? handler :NULL ; }static void acpi_ec_query_handler_release (struct kref *kref)
Well, what about the appended patch instead?
--- drivers/acpi/ec.c | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-)
drivers/acpi/ec.c +4 -12
@@ -1053,28 +1053,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)