From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: "Henrique de Moraes Holschuh" <hmh@hmh.eng.br>,
"Mark Pearson" <mpearson-lenovo@squebb.ca>,
"Derek J. Clark" <derekjohn.clark@gmail.com>,
"Rong Zhang" <i@rong.moe>, "Hans de Goede" <hansg@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: platform-driver-x86@vger.kernel.org,
ibm-acpi-devel@lists.sourceforge.net,
linux-kernel@vger.kernel.org
Subject: [PATCH 6/8] platform/x86: thinkpad_acpi: convert hotkey_thread_data_mutex to a spinlock
Date: Wed, 25 Nov 2026 15:11:19 -0800 [thread overview]
Message-ID: <20261125-thinkpad-acpi-hotkey-poll-v1-6-6dee57519c2e@gmail.com> (raw)
In-Reply-To: <20261125-thinkpad-acpi-hotkey-poll-v1-0-6dee57519c2e@gmail.com>
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@gmail.com>
---
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
next prev parent reply other threads:[~2026-11-25 23:11 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 23:11 [PATCH 0/8] platform/x86: thinkpad_acpi: clean up hotkey polling and locking Dmitry Torokhov
2026-11-25 23:11 ` [PATCH 1/8] platform/x86: thinkpad_acpi: remove early exit in hotkey_kthread() Dmitry Torokhov
2026-11-25 23:11 ` [PATCH 2/8] platform/x86: thinkpad_acpi: drop dead -ENXIO check in hotkey_init() Dmitry Torokhov
2026-11-25 23:11 ` [PATCH 3/8] platform/x86: thinkpad_acpi: simplify hotkey open/close and poll setup Dmitry Torokhov
2026-11-25 23:11 ` [PATCH 4/8] platform/x86: thinkpad_acpi: update polling state in hotkey_user_mask_set() Dmitry Torokhov
2026-11-25 23:11 ` [PATCH 5/8] platform/x86: thinkpad_acpi: use scoped_guard() for hotkey config locking Dmitry Torokhov
2026-11-25 23:11 ` Dmitry Torokhov [this message]
2026-11-25 23:11 ` [PATCH 7/8] platform/x86: thinkpad_acpi: remove unused hotkey_poll_active flag Dmitry Torokhov
2026-11-25 23:11 ` [PATCH 8/8] platform/x86: thinkpad_acpi: drop redundant input device parent assignment Dmitry Torokhov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261125-thinkpad-acpi-hotkey-poll-v1-6-6dee57519c2e@gmail.com \
--to=dmitry.torokhov@gmail.com \
--cc=derekjohn.clark@gmail.com \
--cc=hansg@kernel.org \
--cc=hmh@hmh.eng.br \
--cc=i@rong.moe \
--cc=ibm-acpi-devel@lists.sourceforge.net \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mpearson-lenovo@squebb.ca \
--cc=platform-driver-x86@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®