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 3/6] HID: intel-thc-hid: intel-ipts: receive reports
Date: Fri, 27 Nov 2026 16:18:16 +0000 [thread overview]
Message-ID: <sashiko-outbox-237865@kernel.org> (raw)
In-Reply-To: <cf9ec2b7e10689426fe07ac127cdce884879c8b5.1795794049.git.emfox@debian.org>
Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Medium] HID: intel-thc-hid: DMA buffer leak on reset failure in
thc_ipts_recover()
- [Medium] HID: intel-thc-hid: intel-ipts: invalid wait context in
thc_ipts_hardirq()
- [Medium] HID: intel-thc-hid: intel-ipts: IRQ left masked on
thc_ipts_thread() recovery
--
commit 7673d514a40c57318bfb19e7aad1ebad5c468aba
Author: Emfox Zhou <emfox@debian.org>
HID: intel-thc-hid: intel-ipts: receive reports
This commit adds DMA receive ring management, shared INTx / MSI interrupt
handling, error recovery, and incoming frame decoding for Intel THC IPTS
ports.
> diff --git a/drivers/hid/intel-thc-hid/intel-ipts/ipts.c b/drivers/hid/intel-thc-hid/intel-ipts/ipts.c
> index c680b09265667..f5f2cb3d2c7fe 100644
> --- a/drivers/hid/intel-thc-hid/intel-ipts/ipts.c
> +++ b/drivers/hid/intel-thc-hid/intel-ipts/ipts.c
[ ... ]
> @@ -101,6 +116,291 @@ static int thc_ipts_touch_set(struct thc_ipts *idev, bool enable)
[ ... ]
> +static void thc_ipts_dma_stop(struct thc_ipts *idev)
> +{
> + 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);
> +}
[ ... ]
> +irqreturn_t thc_ipts_hardirq(int irq, void *data)
> +{
> + struct thc_ipts *idev = data;
> +
> + /* Nothing of ours is pending: the cause belongs to a sharer. A reset
> + * in flight owns the status registers and acknowledges nothing.
> + */
> + if (READ_ONCE(idev->state) < THC_IPTS_DMA ||
> + READ_ONCE(idev->recovering))
> + return IRQ_NONE;
> +
> + /* Level triggered and shared: mask first, or it stays asserted. */
> + thc_interrupt_enable(idev->thc, false);
[Severity: Medium]
Can thc_interrupt_enable() trigger an invalid wait context splat here?
thc_ipts_probe() registers thc_ipts_hardirq() on the legacy PCI_IRQ_INTX
line with IRQF_SHARED | IRQF_COND_ONESHOT. When the line is shared with
an IRQF_ONESHOT handler, __setup_irq() promotes the action to
IRQF_ONESHOT, so __handle_irq_event_percpu() runs thc_ipts_hardirq() in
LD_WAIT_SPIN wait context without calling lockdep_hardirq_threaded().
thc_interrupt_enable() calls regmap_write_bits() on dev->thc_regmap,
which is configured in thc_regmap_cfg with .fast_io = true and without
.use_raw_spinlock = true, acquiring a regular spinlock_t in hardirq
context.
[ ... ]
> +/*
> + * Refuse new requests and queue the reset. The line stays open: a write that
> + * is already waiting for its completion needs this interrupt, and the work
> + * item takes the port once that write is done.
> + */
> +static void thc_ipts_request_recover(struct thc_ipts *idev)
> +{
> + if (READ_ONCE(idev->recover_pending))
> + return;
> +
> + WRITE_ONCE(idev->recover_pending, true);
> + schedule_work(&idev->recover_work);
> +}
> +
> +/*
> + * From a work item: the reset waits for the bus lock a pending write holds
> + * until the threaded handler delivers its completion.
> + */
> +void thc_ipts_recover(struct work_struct *work)
> +{
> + struct thc_ipts *idev = container_of(work, struct thc_ipts,
> + recover_work);
> +
> + /*
> + * 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
> + * interrupt that would announce it again never comes. The flag alone
> + * 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
> + * the line open: mask it again, the write is idempotent.
> + */
> + thc_interrupt_enable(idev->thc, false);
> +
> + if (thc_rxdma_reset(idev->thc)) {
> + /* Nothing left to reset: keep the port masked until it
> + * restarts, and let the requests fail with -ENODEV instead of
> + * -EAGAIN, which would look like a reset that never ends.
> + */
> + dev_err(idev->dev, "cannot reset the receive engine\n");
> + WRITE_ONCE(idev->state, THC_IPTS_CONFIG);
> + WRITE_ONCE(idev->recover_seq, READ_ONCE(idev->recover_seq) + 1);
> + WRITE_ONCE(idev->recover_pending, false);
> + WRITE_ONCE(idev->recovering, false);
> + return;
> + }
[Severity: Medium]
Does lowering idev->state to THC_IPTS_CONFIG here leak the DMA buffers
when thc_rxdma_reset() fails?
thc_rxdma_reset() does not call thc_dma_release() (and returns before
thc_dma_unconfigure() if thc_interrupt_quiesce() or
thc_wait_for_dma_pause() fails). Once idev->state is set to
THC_IPTS_CONFIG, a subsequent thc_ipts_port_stop() sees
idev->state < THC_IPTS_DMA in thc_ipts_dma_stop() and returns without
unconfiguring DMA or releasing the coherent PRD tables and scatter-gather
buffers.
[ ... ]
> + /* The work item resets the engine and unmasks again; a frame read
> + * meanwhile would corrupt the ring.
> + */
> + 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.
> + */
> + if (!READ_ONCE(idev->recovering) && !READ_ONCE(idev->stopping))
> + thc_interrupt_enable(idev->thc, true);
> +
> + return ret;
> +}
[Severity: Medium]
Does returning early when need_recover is true leave the port interrupt
masked while an in-flight TxDMA write is waiting for completion?
thc_ipts_hardirq() and thc_ipts_thread() mask the interrupt on entry, and
the comments on thc_ipts_request_recover() and thc_ipts_recover() note
that the line must stay open until an in-flight write holding
thc_bus_lock receives its completion interrupt. Returning here before
thc_interrupt_enable(idev->thc, true) (and masking in thc_ipts_recover()
before thc_rxdma_reset() waits on thc_bus_lock) starves thc_dma_write()
of its completion interrupt until its 1-second timeout expires. Commit
"HID: intel-thc-hid: intel-ipts: add the HID device" later serializes
thc_ipts_recover() on idev->tx_lock and removes this early return, but
changes the unmask condition to check !READ_ONCE(idev->recover_pending),
which is already false after thc_ipts_request_recover().
--
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1795794049.git.emfox@debian.org?part=3
next prev parent reply other threads:[~2026-11-27 16:18 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 [this message]
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
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-237865@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.