clevo_keyboard: Add mutex to interface operations

This commit is contained in:
Christoffer Sandberg 2021-03-19 16:20:50 +01:00
parent b7a0b23db1
commit 67fb677d88
No known key found for this signature in database
GPG key ID: BF563F71B6C7A96D

View file

@ -64,8 +64,12 @@ struct clevo_interface_t *active_clevo_interface;
void clevo_keyboard_write_state(void); void clevo_keyboard_write_state(void);
void clevo_keyboard_event_callb(u32 event); 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) 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) { if (strcmp(new_interface->string_id, "clevo_wmi") == 0) {
clevo_interfaces.wmi = new_interface; clevo_interfaces.wmi = new_interface;
clevo_interfaces.wmi->event_callb = clevo_keyboard_event_callb; 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 { } else {
// Not recognized interface // Not recognized interface
pr_err("unrecognized interface\n"); pr_err("unrecognized interface\n");
mutex_unlock(&clevo_keyboard_interface_modification_lock);
return -EINVAL; return -EINVAL;
} }
clevo_keyboard_write_state(); clevo_keyboard_write_state();
mutex_unlock(&clevo_keyboard_interface_modification_lock);
return 0; return 0;
} }
EXPORT_SYMBOL(clevo_keyboard_add_interface); EXPORT_SYMBOL(clevo_keyboard_add_interface);
u32 clevo_keyboard_remove_interface(struct clevo_interface_t *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) { if (strcmp(interface->string_id, "clevo_wmi") == 0) {
clevo_interfaces.wmi = NULL; clevo_interfaces.wmi = NULL;
} else if (strcmp(interface->string_id, "clevo_acpi") == 0) { } else if (strcmp(interface->string_id, "clevo_acpi") == 0) {
clevo_interfaces.acpi = NULL; clevo_interfaces.acpi = NULL;
} else { } else {
mutex_unlock(&clevo_keyboard_interface_modification_lock);
return -EINVAL; return -EINVAL;
} }
if (active_clevo_interface == interface) if (active_clevo_interface == interface)
active_clevo_interface = NULL; active_clevo_interface = NULL;
mutex_unlock(&clevo_keyboard_interface_modification_lock);
return 0; return 0;
} }
EXPORT_SYMBOL(clevo_keyboard_remove_interface); EXPORT_SYMBOL(clevo_keyboard_remove_interface);