From: sashiko-bot@kernel.org
To: "Emfox Zhou" <emfox@debian.org>
Cc: linux-input@vger.kernel.org, dmitry.torokhov@gmail.com
Subject: Re: [PATCH v10 4/6] HID: intel-thc-hid: intel-ipts: add the HID device
Date: Fri, 27 Nov 2026 16:06:29 +0000 [thread overview]
Message-ID: <sashiko-outbox-237826@kernel.org> (raw)
In-Reply-To: <f8529097ea0778363ba902af07f910036f7f5b94.1795794049.git.emfox@debian.org>
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [High] HID: intel-thc-hid: intel-ipts: masked IRQ on recovery starves
thc_dma_write()
- [Medium] HID: intel-thc-hid: intel-ipts: DMA leak in
thc_ipts_dma_stop() on reset error
--
commit cf6199acae63b20d55f6ee4b4578d3004cdbf95e
Author: Emfox Zhou <emfox@debian.org>
HID: intel-thc-hid: intel-ipts: add the HID device
This commit registers a HID device for Intel THC ports operating in IPTS
mode, adding report descriptor and feature report handshakes, input report
forwarding, and transmit serialization across recovery and teardown.
> diff --git a/drivers/hid/intel-thc-hid/intel-ipts/ipts.c b/drivers/hid/intel-thc-hid/intel-ipts/ipts.c
> index f5f2cb3d2c7fe..506d2f330caf6 100644
> --- a/drivers/hid/intel-thc-hid/intel-ipts/ipts.c
> +++ b/drivers/hid/intel-thc-hid/intel-ipts/ipts.c
[ ... ]
> @@ -274,6 +400,15 @@ void thc_ipts_recover(struct work_struct *work)
> struct thc_ipts *idev = container_of(work, struct thc_ipts,
> recover_work);
>
> + /*
> + * A write that is already on the wire holds this lock and needs the
> + * interrupt that the mask below takes away: let it finish first, or it
> + * times out over the bus lock the reset is waiting for.
> + */
> + mutex_lock(&idev->tx_lock);
> + WRITE_ONCE(idev->recovering, true);
> + mutex_unlock(&idev->tx_lock);
> +
> /*
> * From here the status registers belong to the reset: the threaded
> * handler must not acknowledge a frame it is not going to read, or the
> @@ -281,7 +416,6 @@ void thc_ipts_recover(struct work_struct *work)
> * is only a snapshot to a run that is already inside, so the mask and
> * the wait below are what keeps that run out.
> */
> - WRITE_ONCE(idev->recovering, true);
> thc_interrupt_enable(idev->thc, false);
> synchronize_irq(idev->irq);
> /* A run that unmasked just before synchronize_irq() returned leaves
> @@ -299,6 +433,7 @@ void thc_ipts_recover(struct work_struct *work)
> WRITE_ONCE(idev->recover_seq, READ_ONCE(idev->recover_seq) + 1);
> WRITE_ONCE(idev->recover_pending, false);
> WRITE_ONCE(idev->recovering, false);
> + wake_up(&idev->wq);
> return;
> }
[Severity: Medium]
Does setting idev->state to THC_IPTS_CONFIG when thc_rxdma_reset() fails
cause thc_ipts_dma_stop() to leak the DMA allocations on teardown?
drivers/hid/intel-thc-hid/intel-ipts/ipts.c:thc_ipts_dma_stop() {
if (READ_ONCE(idev->state) < THC_IPTS_DMA)
return;
WRITE_ONCE(idev->state, THC_IPTS_CONFIG);
thc_dma_unconfigure(idev->thc);
thc_dma_release(idev->thc);
}
Because idev->state is lowered to THC_IPTS_CONFIG here to make
thc_ipts_send() return -ENODEV, a later thc_ipts_port_stop() will see
idev->state < THC_IPTS_DMA and skip both thc_dma_unconfigure() and
thc_dma_release(), leaking the non-devm coherent PRD tables and mapped
scatterlists.
[ ... ]
> @@ -383,24 +522,294 @@ irqreturn_t thc_ipts_thread(int irq, void *data)
> need_recover = true;
> }
>
> - /* The work item resets the engine and unmasks again; a frame read
> - * meanwhile would corrupt the ring.
> + /*
> + * The work item resets the engine in its own time; a frame read
> + * meanwhile would corrupt the ring, so only queue the reset.
> */
> - if (need_recover) {
> + if (need_recover)
> thc_ipts_request_recover(idev);
> - return IRQ_HANDLED;
> - }
>
> - /* A reset unmasks when it is done and a teardown masks on its own, so
> - * the line only stays open here while neither runs: a write already
> - * on the wire needs the completion this handler delivers.
> + /*
> + * A reset unmasks when it is done, and a teardown masks on its own
> + * after waiting for this very run. Leaving the line open here is what
> + * a write already on the wire needs: this handler is where its
> + * completion is delivered, and masking it away would make that write
> + * time out over the bus lock the teardown is waiting for.
> */
> - if (!READ_ONCE(idev->recovering) && !READ_ONCE(idev->stopping))
> + if (!READ_ONCE(idev->recovering) && !READ_ONCE(idev->recover_pending))
> thc_interrupt_enable(idev->thc, true);
>
> return ret;
> }
[Severity: High]
Does checking !READ_ONCE(idev->recover_pending) here leave the interrupt
masked while an in-flight write in thc_dma_write() still needs it?
Sender IRQ thread kworker
thc_ipts_send()
mutex_lock(&idev->tx_lock)
thc_dma_write()
thc_ipts_thread()
thc_interrupt_enable(..., false)
...
thc_ipts_request_recover()
idev->recover_pending = true
schedule_work(...)
/* recover_pending is true:
* IRQ is left masked
*/
thc_ipts_recover()
mutex_lock(&idev->tx_lock)
wait_event_timeout(..., 1 * HZ)
<-- TxDMA IRQ masked, times out after 1s
thc_ipts_recover() waits on idev->tx_lock before setting idev->recovering
and masking the line so that a write already on the wire can finish.
However, thc_ipts_request_recover() sets idev->recover_pending = true just
above, so checking !READ_ONCE(idev->recover_pending) prevents
thc_ipts_thread() from unmasking the interrupt. Any concurrent
thc_ipts_send() in thc_dma_write() stalls for its 1-second timeout holding
tx_lock and thc_bus_lock, and if that write was from
thc_ipts_get_feature(), the resulting -ETIMEDOUT permanently latches
idev->feature_off = true until the port is restarted.
Should the unmask check here test only !READ_ONCE(idev->recovering)?
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795794049.git.emfox@debian.org?part=4
next prev parent reply other threads:[~2026-11-27 16:06 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-27 15:51 [PATCH v10 0/6] HID: intel-thc-hid: intel-ipts: support THC IPTS ports Emfox Zhou
2026-11-27 15:51 ` [PATCH v10 1/6] HID: intel-thc-hid: intel-thc: expose the operations an IPTS port needs Emfox Zhou
2026-11-27 16:01 ` sashiko-bot
2026-11-27 15:51 ` [PATCH v10 2/6] HID: intel-thc-hid: intel-ipts: bring up the port Emfox Zhou
2026-11-27 16:11 ` sashiko-bot
2026-11-27 15:51 ` [PATCH v10 3/6] HID: intel-thc-hid: intel-ipts: receive reports Emfox Zhou
2026-11-27 16:18 ` sashiko-bot
2026-11-27 15:51 ` [PATCH v10 4/6] HID: intel-thc-hid: intel-ipts: add the HID device Emfox Zhou
2026-11-27 16:06 ` sashiko-bot [this message]
2026-11-27 15:51 ` [PATCH v10 5/6] HID: intel-thc-hid: intel-ipts: handle system sleep Emfox Zhou
2026-11-27 15:51 ` [PATCH v10 6/6] 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-237826@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