From 67fb677d886c7808fbca56eae9136b19381ea020 Mon Sep 17 00:00:00 2001 From: Christoffer Sandberg Date: Fri, 19 Mar 2021 16:20:50 +0100 Subject: [PATCH] clevo_keyboard: Add mutex to interface operations --- src/clevo_keyboard.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/clevo_keyboard.h b/src/clevo_keyboard.h index c9873c0..5a6983e 100644 --- a/src/clevo_keyboard.h +++ b/src/clevo_keyboard.h @@ -64,8 +64,12 @@ struct clevo_interface_t *active_clevo_interface; void clevo_keyboard_write_state(void); void clevo_keyboard_event_callb(u32 event); +static DEFINE_MUTEX(clevo_keyboard_interface_modification_lock); + u32 clevo_keyboard_add_interface(struct clevo_interface_t *new_interface) { + mutex_lock(&clevo_keyboard_interface_modification_lock); + if (strcmp(new_interface->string_id, "clevo_wmi") == 0) { clevo_interfaces.wmi = new_interface; clevo_interfaces.wmi->event_callb = clevo_keyboard_event_callb; @@ -88,28 +92,36 @@ u32 clevo_keyboard_add_interface(struct clevo_interface_t *new_interface) } else { // Not recognized interface pr_err("unrecognized interface\n"); + mutex_unlock(&clevo_keyboard_interface_modification_lock); return -EINVAL; } clevo_keyboard_write_state(); + mutex_unlock(&clevo_keyboard_interface_modification_lock); + return 0; } EXPORT_SYMBOL(clevo_keyboard_add_interface); u32 clevo_keyboard_remove_interface(struct clevo_interface_t *interface) { + mutex_lock(&clevo_keyboard_interface_modification_lock); + if (strcmp(interface->string_id, "clevo_wmi") == 0) { clevo_interfaces.wmi = NULL; } else if (strcmp(interface->string_id, "clevo_acpi") == 0) { clevo_interfaces.acpi = NULL; } else { + mutex_unlock(&clevo_keyboard_interface_modification_lock); return -EINVAL; } if (active_clevo_interface == interface) active_clevo_interface = NULL; + mutex_unlock(&clevo_keyboard_interface_modification_lock); + return 0; } EXPORT_SYMBOL(clevo_keyboard_remove_interface);