From: Rong Zhang <i@rong.moe>
To: "Mark Pearson" <mpearson-lenovo@squebb.ca>,
"Derek J. Clark" <derekjohn.clark@gmail.com>,
"Hans de Goede" <hansg@kernel.org>,
"Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>,
"Gergo Koteles" <soyer@irl.hu>, "Ike Panhc" <ikepanhc@gmail.com>,
"Andrew Kallmeyer" <kallmeyeras@gmail.com>
Cc: Eduard Aliman <edialiman20@gmail.com>,
platform-driver-x86@vger.kernel.org,
linux-kernel@vger.kernel.org,
Mahir Faisal <mahirfaisalantiq33@gmail.com>,
Rong Zhang <i@rong.moe>,
stable@vger.kernel.org
Subject: [PATCH v3 2/8] platform/x86: lenovo-ymc: Serialize WMI event handling
Date: Thu, 26 Nov 2026 02:08:20 +0800 [thread overview]
Message-ID: <20261126-ymc-82yl-v3-2-e30842671ec3@rong.moe> (raw)
In-Reply-To: <20261126-ymc-82yl-v3-0-e30842671ec3@rong.moe>
WMI events may arrive in parallel, causing race conditions, e.g.,
CPU1 CPU2
query: posture A
query: posture B
input report B
input report A
trigger EC with B
trigger EC with A
Fix it by serializing lenovo_ymc_notify() with a mutex.
Fixes: e82882cdd241 ("platform/x86: Add driver for Yoga Tablet Mode switch")
Cc: stable@vger.kernel.org
Reviewed-by: Mark Pearson <mpearson-lenovo@squebb.ca>
Tested-by: Eduard Aliman <edialiman20@gmail.com>
Signed-off-by: Rong Zhang <i@rong.moe>
---
drivers/platform/x86/lenovo/ymc.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/platform/x86/lenovo/ymc.c b/drivers/platform/x86/lenovo/ymc.c
index 70f3ae20d3e3..eba22600161e 100644
--- a/drivers/platform/x86/lenovo/ymc.c
+++ b/drivers/platform/x86/lenovo/ymc.c
@@ -10,9 +10,11 @@
#include <linux/acpi.h>
#include <linux/bitfield.h>
#include <linux/bits.h>
+#include <linux/cleanup.h>
#include <linux/dmi.h>
#include <linux/input.h>
#include <linux/input/sparse-keymap.h>
+#include <linux/mutex.h>
#include <linux/wmi.h>
#include "ideapad-laptop.h"
@@ -60,6 +62,7 @@ static const struct dmi_system_id allowed_chasis_types_dmi_table[] = {
struct lenovo_ymc_private {
struct input_dev *input_dev;
+ struct mutex mutex; /* Protects event handling. */
};
static const struct key_entry lenovo_ymc_keymap[] = {
@@ -82,6 +85,8 @@ static void lenovo_ymc_notify(struct wmi_device *wdev, union acpi_object *data)
acpi_status status;
int code;
+ guard(mutex)(&priv->mutex);
+
status = wmi_evaluate_method(LENOVO_YMC_QUERY_GUID,
LENOVO_YMC_QUERY_INSTANCE,
LENOVO_YMC_QUERY_METHOD,
@@ -137,6 +142,10 @@ static int lenovo_ymc_probe(struct wmi_device *wdev, const void *ctx)
if (!input_dev)
return -ENOMEM;
+ err = devm_mutex_init(&wdev->dev, &priv->mutex);
+ if (err)
+ return err;
+
input_dev->name = "Lenovo Yoga Tablet Mode Control switch";
input_dev->phys = LENOVO_YMC_EVENT_GUID "/input0";
input_dev->id.bustype = BUS_HOST;
--
2.55.0
next prev parent reply other threads:[~2026-11-25 18:09 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 18:08 [PATCH v3 0/8] platform/x86: ideapad-laptop: Trigger the EC on YMC events following Windows behavior Rong Zhang
2026-11-25 18:08 ` [PATCH v3 1/8] platform/x86: lenovo-ymc: Use enumeration to represent device posture Rong Zhang
2026-11-25 18:08 ` Rong Zhang [this message]
2026-11-25 18:08 ` [PATCH v3 3/8] platform/x86: lenovo-wmi-events: Modernize WMI event handling Rong Zhang
2026-11-25 18:08 ` [PATCH v3 4/8] platform/x86: lenovo-ymc: Modernize WMI driver and factor out events Rong Zhang
2026-11-25 18:08 ` [PATCH v3 5/8] platform/x86: lenovo-ymc: Refresh posture on resume Rong Zhang
2026-11-25 18:08 ` [PATCH v3 6/8] platform/x86: ideapad-laptop: Trigger the EC on YMC events following Windows behavior Rong Zhang
2026-11-25 18:08 ` [PATCH v3 7/8] platform/x86: ideapad-laptop: Enable ymc_ec_trigger for Lenovo Yoga 7 14IRL8 Rong Zhang
2026-11-25 18:08 ` [PATCH v3 8/8] platform/x86: ideapad-laptop: Enable ymc_ec_trigger for Lenovo Yoga 7 14ARP8 Rong Zhang
2026-11-25 19:14 ` [PATCH v3 0/8] platform/x86: ideapad-laptop: Trigger the EC on YMC events following Windows behavior Eduard Aliman
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=20261126-ymc-82yl-v3-2-e30842671ec3@rong.moe \
--to=i@rong.moe \
--cc=derekjohn.clark@gmail.com \
--cc=edialiman20@gmail.com \
--cc=hansg@kernel.org \
--cc=ikepanhc@gmail.com \
--cc=ilpo.jarvinen@linux.intel.com \
--cc=kallmeyeras@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mahirfaisalantiq33@gmail.com \
--cc=mpearson-lenovo@squebb.ca \
--cc=platform-driver-x86@vger.kernel.org \
--cc=soyer@irl.hu \
--cc=stable@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®