[PATCH 6/8] platform/x86: thinkpad_acpi: convert hotkey_thread_data_mutex to a spinlock
From: Dmitry Torokhov
Date: Wed Nov 25 2026 - 18:12:05 EST
hotkey_thread_data_mutex only protects a few in-memory integer reads
and updates across hotkey_kthread(), tpacpi_hotkey_driver_mask_set(),
and hotkey_source_mask_store(), with no sleeping calls inside any of
its critical sections.
Convert it to a statically initialized spinlock_t
(hotkey_thread_data_lock), which also allows dropping the conditional
mutex_init() call from hotkey_init().
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@xxxxxxxxx>
---
drivers/platform/x86/lenovo/thinkpad_acpi.c | 19 ++++++++-----------
1 file changed, 8 insertions(+), 11 deletions(-)
diff --git a/drivers/platform/x86/lenovo/thinkpad_acpi.c b/drivers/platform/x86/lenovo/thinkpad_acpi.c
index 58500b72d9d2..0ebaea0ab96b 100644
--- a/drivers/platform/x86/lenovo/thinkpad_acpi.c
+++ b/drivers/platform/x86/lenovo/thinkpad_acpi.c
@@ -67,6 +67,7 @@
#include <linux/sched/signal.h>
#include <linux/seq_file.h>
#include <linux/slab.h>
+#include <linux/spinlock.h>
#include <linux/string.h>
#include <linux/string_choices.h>
#include <linux/string_helpers.h>
@@ -1814,19 +1815,19 @@ struct tp_nvram_state {
static struct task_struct *tpacpi_hotkey_task;
/*
- * Acquire mutex to write poller control variables as an
+ * Acquire spinlock to write poller control variables as an
* atomic block.
*
* Increment hotkey_config_change when changing them if you
* want the kthread to forget old state.
*/
-static struct mutex hotkey_thread_data_mutex;
+static DEFINE_SPINLOCK(hotkey_thread_data_lock);
static unsigned int hotkey_config_change;
/*
* hotkey poller control variables
*
- * Must be atomic or readers will also need to acquire mutex.
+ * Must be atomic or readers will also need to acquire spinlock.
*/
static u32 hotkey_source_mask; /* bit mask 0=ACPI,1=NVRAM */
static unsigned int hotkey_poll_freq = 10; /* Hz */
@@ -2143,7 +2144,7 @@ static int tpacpi_hotkey_driver_mask_set(const u32 mask)
guard(mutex)(&hotkey_mutex);
#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
- scoped_guard(mutex, &hotkey_thread_data_mutex) {
+ scoped_guard(spinlock, &hotkey_thread_data_lock) {
hotkey_driver_mask = mask;
hotkey_source_mask |= (mask & ~hotkey_all_mask);
hotkey_config_change++;
@@ -2446,7 +2447,7 @@ static int hotkey_kthread(void *data)
t = 0;
/* Initial state for compares */
- scoped_guard(mutex, &hotkey_thread_data_mutex) {
+ scoped_guard(spinlock, &hotkey_thread_data_lock) {
change_detector = hotkey_config_change;
poll_mask = hotkey_source_mask;
event_mask = hotkey_source_mask &
@@ -2469,7 +2470,7 @@ static int hotkey_kthread(void *data)
if (t > 0 && !was_frozen)
continue;
- scoped_guard(mutex, &hotkey_thread_data_mutex) {
+ scoped_guard(spinlock, &hotkey_thread_data_lock) {
if (was_frozen ||
hotkey_config_change != change_detector) {
/* forget old state on thaw or config change */
@@ -2726,7 +2727,7 @@ static ssize_t hotkey_source_mask_store(struct device *dev,
if (rc)
return rc;
- scoped_guard(mutex, &hotkey_thread_data_mutex) {
+ scoped_guard(spinlock, &hotkey_thread_data_lock) {
hotkey_source_mask = t;
hotkey_config_change++;
}
@@ -3329,10 +3330,6 @@ static int __init hotkey_init(struct ibm_init_struct *iibm)
TPACPI_ACPIHANDLE_INIT(hkey);
mutex_init(&hotkey_mutex);
-#ifdef CONFIG_THINKPAD_ACPI_HOTKEY_POLL
- mutex_init(&hotkey_thread_data_mutex);
-#endif
-
/* hotkey not supported on 570 */
tp_features.hotkey = hkey_handle != NULL;
--
2.56.1.839.g22a8290db9-goog