From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Gui-Dong Han <hanguidong02@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,
baijiaju1990@gmail.com
Subject: Re: [PATCH] Input: cyapa - publish PIP command state to the IRQ handler
Date: Mon, 30 Nov 2026 15:45:35 -0800 [thread overview]
Message-ID: <b416221949886cab1f7c27ad2b5831a0@gmail.com> (raw)
In-Reply-To: <20261130031927.557229-1-hanguidong02@gmail.com>
Hi Gui-Dong,
On Mon, Nov 30, 2026 at 11:19:27AM +0800, Gui-Dong Han wrote:
> 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>
Pairing a raw smp_wmb() plus atomic_inc() with atomic_read_acquire() is
pretty awkward and asymmetric, and since commands are already serialized
by cmd_lock, cmd_issued is really just a boolean flag rather than a
counter.
More importantly, adding barriers only papers over a bigger race on the
error and timeout paths. cyapa_irq() is a threaded IRQ that sleeps in
I2C reads inside cyapa_pip_irq_cmd_handler(). If a command write fails
or times out while the handler is still running, the sender decrements
cmd_issued, clears the response pointers, and returns (with the caller's
stack response buffers going out of scope) without synchronizing with
the IRQ thread. The handler can then dereference cleared/freed response
pointers and run a second atomic_dec(), driving cmd_issued to -1 and
permanently breaking touch reporting.
Since cyapa_irq() already runs in thread context, I would prefer to drop
the lockless atomic_t and manual barriers altogether and replace
cmd_issued with a bool protected by a dedicated mutex separate from
cmd_lock. Take it with guard()/scoped_guard() during setup, teardown,
and timeout cancellation (without holding it across I2C writes, polling,
or wait_for_completion_timeout(), and checking cmd_issued on timeout so
a racing completion is not discarded), and hold it across
cyapa_pip_irq_cmd_handler() so it is released before returning to
cyapa_irq(). That handles memory ordering, the teardown races, and the
-1 underflow together.
Could you please rework and resubmit the patch along those lines?
Thanks.
--
Dmitry
prev parent reply other threads:[~2026-11-30 23:45 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 3:19 Gui-Dong Han
2026-11-30 23:45 ` Dmitry Torokhov [this message]
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=b416221949886cab1f7c27ad2b5831a0@gmail.com \
--to=dmitry.torokhov@gmail.com \
--cc=baijiaju1990@gmail.com \
--cc=dudl@cypress.com \
--cc=hanguidong02@gmail.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®