* [PATCH] Input: cyapa - publish PIP command state to the IRQ handler
@ 2026-11-30 3:19 Gui-Dong Han
0 siblings, 0 replies; only message in thread
From: Gui-Dong Han @ 2026-11-30 3:19 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: Dudley Du, Sakari Ailus, linux-input, linux-kernel, Gui-Dong Han,
baijiaju1990
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-30 3:19 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 3:19 [PATCH] Input: cyapa - publish PIP command state to the IRQ handler Gui-Dong Han
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox