Linux Input/HID development
 help / color / mirror / Atom feed
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 4/5] HID: intel-thc-hid: intel-ipts: handle system sleep
Date: Tue, 17 Nov 2026 08:06:18 +0000	[thread overview]
Message-ID: <sashiko-outbox-218395@kernel.org> (raw)
In-Reply-To: <20261117073554.11557-5-emfox@debian.org>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] HID: intel-ipts: premature synchronize_irq() in
  thc_ipts_port_stop()
--

commit ecbcb8810dc8ab842baead9bb9c79da3060e7ca1
Author: Emfox Zhou <emfox@debian.org>

HID: intel-thc-hid: intel-ipts: handle system sleep

This commit adds system sleep PM callbacks that stop the IPTS port and
remove its HID device on suspend, then restart the port and recreate the
HID device on resume.

> diff --git a/drivers/hid/intel-thc-hid/intel-ipts/pci-ipts.c b/drivers/hid/intel-thc-hid/intel-ipts/pci-ipts.c
> index 46934ac79bbc8..1426e52e831c4 100644
> --- a/drivers/hid/intel-thc-hid/intel-ipts/pci-ipts.c
> +++ b/drivers/hid/intel-thc-hid/intel-ipts/pci-ipts.c
> @@ -134,6 +134,40 @@ static void thc_ipts_remove(struct pci_dev *pci)
>  	pci_clear_master(pci);
>  }
>  
> +/*
> + * The controller forgets the streaming mode, so the port is torn down and
> + * rebuilt: the HID device comes back and the daemon restarts with it.
> + */
> +static int thc_ipts_suspend(struct device *dev)
> +{
> +	struct thc_ipts *idev = dev_get_drvdata(dev);
> +
> +	if (!idev)
> +		return -ENODEV;
> +
> +	thc_ipts_port_stop(idev);
> +
> +	return 0;
> +}
> +
> +static int thc_ipts_resume(struct device *dev)
> +{
> +	struct thc_ipts *idev = dev_get_drvdata(dev);
> +	int ret;
> +
> +	if (!idev)
> +		return -ENODEV;
> +
> +	ret = thc_ipts_port_start(idev);

[Severity: Medium]
Can a threaded IRQ handler woken during thc_ipts_port_stop() still be
pending when thc_ipts_resume() calls thc_ipts_port_start()?

Unlike thc_ipts_remove(), which calls devm_free_irq() right after
thc_ipts_port_stop(), suspend and resume keep the shared IRQ registered.
In thc_ipts_port_stop(), synchronize_irq() runs while idev->dma_ready is
still true, and idev->dma_ready is only cleared later inside
thc_ipts_dma_stop() with no synchronize_irq() after it.

If a shared interrupt fires in that window and suspend aborts before
dpm_suspend_noirq() (so suspend_device_irqs() never drains the line),
thc_ipts_thread() can run after thc_ipts_port_start() clears
idev->stopping:

CPU0                              CPU1
thc_ipts_suspend()
  thc_ipts_port_stop()
    WRITE_ONCE(idev->stopping, true)
    thc_interrupt_enable(..., false)
    synchronize_irq(idev->irq)
    ...
    thc_ipts_touch_set(..., false)
                                  <hardirq>
                                  thc_ipts_hardirq()
                                    READ_ONCE(idev->dma_ready) == true
                                    return IRQ_WAKE_THREAD
    thc_ipts_dma_stop()
      WRITE_ONCE(idev->dma_ready, false)
      thc_dma_release()
...
thc_ipts_resume()
  thc_ipts_port_start()
    WRITE_ONCE(idev->stopping, false)
    msleep(THC_IPTS_BOOT_MS)
                                  thc_ipts_thread()
                                    READ_ONCE(idev->stopping) == false
                                    thc_ipts_read_frames() /
                                    thc_interrupt_enable(..., true)
                                      <-- runs before DMA is set up

The lingering thread can then unmask THC interrupts early or attempt DMA
reads or recovery while DMA buffers are unallocated.  Clearing
idev->dma_ready before synchronize_irq() (or calling synchronize_irq()
again after clearing idev->dma_ready) would ensure no threaded handler
remains queued after thc_ipts_port_stop().

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261117073554.11557-1-emfox@debian.org?part=4

  reply	other threads:[~2026-11-17  8:06 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
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 [this message]
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-218395@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