mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Gui-Dong Han <hanguidong02@gmail.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: Dudley Du <dudl@cypress.com>,
	Sakari Ailus <sakari.ailus@linux.intel.com>,
	linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	Gui-Dong Han <hanguidong02@gmail.com>,
	baijiaju1990@gmail.com
Subject: [PATCH] Input: cyapa - publish PIP command state to the IRQ handler
Date: Mon, 30 Nov 2026 11:19:27 +0800	[thread overview]
Message-ID: <20261130031927.557229-1-hanguidong02@gmail.com> (raw)

cyapa_i2c_pip_cmd_irq_sync() sets is_irq_mode and the response parameters
before cyapa_do_i2c_pip_cmd_irq_sync() or cyapa_do_i2c_pip_cmd_polling()
increments cmd_issued. cyapa_pip_irq_cmd_handler() reads cmd_issued
without holding cmd_lock to decide whether to inspect that state.

However, atomic_inc() and atomic_read() are unordered. On weakly ordered
architectures, cyapa_pip_irq_cmd_handler() can observe a nonzero
cmd_issued before the updates to is_irq_mode or the response parameters
become visible, causing it to misread the command mode or use stale
response state.

Add smp_wmb() before atomic_inc(&pip->cmd_issued) in both command paths,
and use atomic_read_acquire(&pip->cmd_issued) in
cyapa_pip_irq_cmd_handler() to ensure the setup stores are visible once a
nonzero count is observed.

Fixes: 6972a859601a ("Input: cyapa - add gen5 trackpad device basic functions support")
Signed-off-by: Gui-Dong Han <hanguidong02@gmail.com>
---
Found by auditing atomic operations used for synchronization.
A similar fix can be found in 6df8e84aa6b5.
---
 drivers/input/mouse/cyapa_gen5.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/input/mouse/cyapa_gen5.c b/drivers/input/mouse/cyapa_gen5.c
index 59f6e97d5482..8f5cec948878 100644
--- a/drivers/input/mouse/cyapa_gen5.c
+++ b/drivers/input/mouse/cyapa_gen5.c
@@ -544,6 +544,8 @@ static int cyapa_do_i2c_pip_cmd_irq_sync(
 	/* Wait for interrupt to set ready completion */
 	init_completion(&pip->cmd_ready);
 
+	/* Publish command state to cyapa_pip_irq_cmd_handler(). */
+	smp_wmb();
 	atomic_inc(&pip->cmd_issued);
 	error = cyapa_i2c_pip_write(cyapa, cmd, cmd_len);
 	if (error) {
@@ -574,6 +576,8 @@ static int cyapa_do_i2c_pip_cmd_polling(
 	int length;
 	int error;
 
+	/* Publish command state to cyapa_pip_irq_cmd_handler(). */
+	smp_wmb();
 	atomic_inc(&pip->cmd_issued);
 	error = cyapa_i2c_pip_write(cyapa, cmd, cmd_len);
 	if (error) {
@@ -2608,7 +2612,7 @@ bool cyapa_pip_irq_cmd_handler(struct cyapa *cyapa)
 	struct cyapa_pip_cmd_states *pip = &cyapa->cmd_states.pip;
 	int length;
 
-	if (atomic_read(&pip->cmd_issued)) {
+	if (atomic_read_acquire(&pip->cmd_issued)) {
 		/* Polling command response data. */
 		if (pip->is_irq_mode == false)
 			return false;

base-commit: 8d7fe9885c62fc9a95bf55d9db244d9672a8aadc
-- 
2.34.1


                 reply	other threads:[~2026-11-30  3:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261130031927.557229-1-hanguidong02@gmail.com \
    --to=hanguidong02@gmail.com \
    --cc=baijiaju1990@gmail.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=dudl@cypress.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=sakari.ailus@linux.intel.com \
    /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®