From: sashiko-bot@kernel.org
To: "Emfox Zhou" <emfox@debian.org>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v6 3/5] HID: intel-thc-hid: intel-ipts: register the HID device
Date: Tue, 17 Nov 2026 07:55:12 +0000 [thread overview]
Message-ID: <sashiko-outbox-218389@kernel.org> (raw)
In-Reply-To: <20261117073554.11557-4-emfox@debian.org>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] HID: intel-thc-hid: intel-ipts: unset feature_off on
thc_dma_write() timeout
- [Medium] HID: intel-thc-hid: intel-ipts: premature stopping flag in
thc_ipts_port_stop()
- [Medium] HID: intel-thc-hid: intel-ipts: recovery masks in-flight
thc_dma_write() IRQ
--
commit 4704713917ed8c2f944a8f47ba40eb93a02b398c
Author: Emfox Zhou <emfox@debian.org>
HID: intel-thc-hid: intel-ipts: register the HID device
This commit registers a HID device for each IPTS port and implements the
report descriptor, feature report, and input report handling over the THC
DMA transport.
> diff --git a/drivers/hid/intel-thc-hid/intel-ipts/ipts.c b/drivers/hid/intel-thc-hid/intel-ipts/ipts.c
> index 2265d07355221..5fc396e1b3d13 100644
> --- a/drivers/hid/intel-thc-hid/intel-ipts/ipts.c
> +++ b/drivers/hid/intel-thc-hid/intel-ipts/ipts.c
[ ... ]
> @@ -144,8 +146,75 @@ static int thc_ipts_touch_set(struct thc_ipts *idev, bool enable)
> &touch);
> }
>
> +/* Frames are built in @idev->tx_frame, so callers hold @req_lock. */
> +static int thc_ipts_send(struct thc_ipts *idev, u32 code, const void *data,
> + size_t len)
> +{
> + size_t padded = round_up(len, 4);
> + u8 *frame = idev->tx_frame;
> +
> + if (READ_ONCE(idev->stopping))
> + return -ESHUTDOWN;
> + /* The port is masked: the write would wait out its timeout. */
> + if (READ_ONCE(idev->recovering))
> + return -EAGAIN;
> + /* No engine to write into: waiting for a reset would not help. */
> + if (!READ_ONCE(idev->dma_ready))
> + return -ENODEV;
> + if (THC_IPTS_TX_HDR_SIZE + padded > idev->max_tx)
> + return -EMSGSIZE;
> +
> + put_unaligned_le32(code, frame);
> + put_unaligned_le32((u32)len, frame + 4);
> + memset(frame + THC_IPTS_TX_HDR_SIZE, 0, padded);
> + if (len && data)
> + memcpy(frame + THC_IPTS_TX_HDR_SIZE, data, len);
> +
> + return thc_dma_write(idev->thc, frame, THC_IPTS_TX_HDR_SIZE + padded);
> +}
[Severity: Medium]
Can a concurrent receive recovery mask the port interrupt while
thc_dma_write() is already waiting for its transmit completion?
thc_ipts_send() checks idev->recovering without synchronization against
thc_ipts_request_recover():
CPU0 CPU1 (thc_ipts_thread)
thc_ipts_send()
READ_ONCE(idev->recovering) -> false
thc_dma_write()
mutex_lock(&dev->thc_bus_lock)
dma_set_start_bit(... THC_TXDMA)
thc_ipts_request_recover()
WRITE_ONCE(idev->recovering, true)
thc_interrupt_enable(idev->thc, false)
schedule_work(&idev->recover_work)
wait_event_interruptible_timeout()
<-- 1s timeout (-ETIMEDOUT)
Disabling THC_M_PRT_INT_EN_GBL_INT_EN prevents the TXDMA completion
interrupt from firing, so thc_dma_write() stalls for its full 1-second
timeout while holding thc_bus_lock (which also blocks thc_rxdma_reset() in
thc_ipts_recover()). In thc_ipts_hid_parse(), only -EAGAIN is retried on
reset, so -ETIMEDOUT from thc_dma_write() aborts report descriptor
parsing and fails HID registration.
[ ... ]
> +/* A feature report comes back as a frame of its own: the request waits. */
> +static int thc_ipts_get_feature(struct thc_ipts *idev, unsigned char reportnum,
> + u8 *buf, size_t len)
> +{
> + unsigned long timeout = msecs_to_jiffies(THC_IPTS_REQ_TIMEOUT_MS);
> + unsigned int seq;
> + int ret;
> +
> + guard(mutex)(&idev->req_lock);
> +
> + /* The frame carries only the report ID, so a late answer cannot be
> + * told from the next one's: after a timeout the channel stays shut.
> + */
> + if (READ_ONCE(idev->feature_off))
> + return -EIO;
> +
> + mutex_lock(&idev->feature_lock);
> + WRITE_ONCE(idev->feature_done, false);
> + idev->feature_id = reportnum;
> + idev->feature_pending = true;
> + mutex_unlock(&idev->feature_lock);
> +
> + seq = READ_ONCE(idev->recover_seq);
> +
> + /* A frame that never reached the wire says nothing about the
> + * controller, so it is reported and the channel stays open.
> + */
> + ret = thc_ipts_send(idev, THC_IPTS_TX_GET_FEATURE, &reportnum, 1);
> + if (ret) {
> + mutex_lock(&idev->feature_lock);
> + idev->feature_pending = false;
> + mutex_unlock(&idev->feature_lock);
> +
> + return ret;
> + }
[Severity: Medium]
Does an error from thc_ipts_send() guarantee that the request never
reached the wire?
thc_ipts_send() calls thc_dma_write(), which starts the hardware TXDMA
engine before waiting on dev->write_complete_wait:
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c:thc_dma_write() {
...
dma_set_start_bit(dev, &dev->dma_ctx->dma_config[THC_TXDMA]);
ret = wait_event_interruptible_timeout(dev->write_complete_wait, dev->write_done, 1 * HZ);
if (ret <= 0 || !dev->write_done) {
dev_err_once(dev->dev, "timeout for waiting TxDMA completion\n");
ret = -ETIMEDOUT;
goto end;
}
...
}
If wait_event_interruptible_timeout() is interrupted by a signal or times
out, thc_dma_write() returns -ETIMEDOUT after dma_set_start_bit() has
already put the THC_IPTS_TX_GET_FEATURE frame on the wire. Returning here
without setting idev->feature_off = true allows the next
thc_ipts_get_feature() call for the same report ID to consume the late
reply from this request and return stale data.
[ ... ]
> @@ -485,11 +817,15 @@ int thc_ipts_port_start(struct thc_ipts *idev)
> */
> void thc_ipts_port_stop(struct thc_ipts *idev)
> {
> - /*
> - * Mask the line, then wait for a handler that may be holding a
> - * frame for the HID device which is about to go away.
> + /* Refuse new requests first, then wait for one that is already inside
> + * thc_dma_write(): it needs the interrupt the mask below takes away.
> + * The lock is not held across synchronize_irq(), because the threaded
> + * handler can issue a request of its own from a HID callback.
> */
> WRITE_ONCE(idev->stopping, true);
> + mutex_lock(&idev->req_lock);
> + mutex_unlock(&idev->req_lock);
> +
> thc_interrupt_enable(idev->thc, false);
[Severity: Medium]
Does setting idev->stopping before acquiring idev->req_lock still cut off
interrupts and incoming frames for an in-flight request?
If an interrupt fires on the shared line while thc_ipts_port_stop() is
waiting on idev->req_lock (for example from an incoming RXDMA2 frame or a
shared IRQ peer), thc_ipts_hardirq() masks the port and wakes
thc_ipts_thread(), which sees idev->stopping == true and exits without
unmasking:
CPU0 (request) CPU1 (thc_ipts_port_stop) CPU2 (IRQ)
mutex_lock(&idev->req_lock)
thc_ipts_send()
thc_dma_write()
dma_set_start_bit()
WRITE_ONCE(stopping, true)
mutex_lock(&idev->req_lock)
thc_ipts_hardirq()
thc_interrupt_enable(false)
thc_ipts_thread()
if (!stopping && ...)
/* skipped */
wait_event_interruptible_timeout()
<-- 1s timeout
Because the port interrupt stays masked, an in-flight thc_dma_write()
still waits out its 1-second timeout. Similarly, if the holder of
idev->req_lock is waiting on idev->wq in thc_ipts_get_feature() or
thc_ipts_hid_parse(), thc_ipts_thread() skips thc_ipts_read_frames() when
idev->stopping is true and nothing wakes idev->wq, forcing a 300 ms
timeout and a false dev_err() message on teardown.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261117073554.11557-1-emfox@debian.org?part=3
next prev parent reply other threads:[~2026-11-17 7:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-17 7:35 [PATCH v6 0/5] HID: intel-thc-hid: intel-ipts: support THC IPTS ports Emfox Zhou
2026-11-17 7:35 ` [PATCH v6 1/5] HID: intel-thc-hid: intel-ipts: bring up the port Emfox Zhou
2026-11-17 7:35 ` [PATCH v6 2/5] HID: intel-thc-hid: intel-ipts: receive reports Emfox Zhou
2026-11-17 8:01 ` sashiko-bot
2026-11-17 7:35 ` [PATCH v6 3/5] HID: intel-thc-hid: intel-ipts: register the HID device Emfox Zhou
2026-11-17 7:55 ` sashiko-bot [this message]
2026-11-17 7:35 ` [PATCH v6 4/5] HID: intel-thc-hid: intel-ipts: handle system sleep Emfox Zhou
2026-11-17 8:06 ` sashiko-bot
2026-11-17 7:35 ` [PATCH v6 5/5] HID: intel-thc-hid: intel-ipts: document the IPTS mode Emfox Zhou
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=sashiko-outbox-218389@kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=emfox@debian.org \
--cc=linux-input@vger.kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
/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