Skip to contentSkip to conversation

HID: intel-thc-hid: quiesce interrupts before final teardown

PATCH Superseded Myeonghun Pak 3 participants 11 messages Oct 11 – Nov 10

Subsystems (2)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover HID: intel-thc-hid: quiesce interrupts before final teardown

QuickSPI and QuickI2C can tear down HID/DMA resources while IRQ handlers are still running. Stop new IRQ handling, wait for running handlers, then drain recovery work and mask THC interrupts before final teardown.

This series covers remove, probe unwind and shutdown.

GCC 15.2.0 x86_64 W=1 builds, strict checkpatch and patch application checks passed. No hardware runtime testing.

Base: 238650ef6c7c7cca08e032527329424c9fbd70e5

1. HID: intel-thc-hid: quickspi: quiesce IRQs during teardown
2. HID: intel-thc-hid: quicki2c: quiesce IRQs during teardown

Assisted-by LLM
#1 lore raw

PATCH 1/2 HID: intel-thc-hid: quickspi: quiesce IRQs during teardown

The managed IRQ can access HID/DMA buffers or queue recovery work while remove or probe unwind tears down those resources.

Disable and synchronize the IRQ, drain recovery work, then mask THC interrupts before freeing the IRQ and releasing HID/DMA resources. Track IRQ/DMA initialization for conditional probe cleanup.

Disable the IRQ before shutdown deinit as well. Keep IRQ disabling and release outside the shared hibernation helper.

This issue was found by static analysis.

Fixes 4138f21115ae ("HID: intel-thc-hid: intel-quickspi: Complete THC QuickSPI driver")
Assisted-by LLM

---
Compile-tested with GCC, W=1 (x86_64). No runtime testing.

Related recovery-work review and series:
https://lore-kernel.gnuweeb.org/linux-input/[email protected]/T/
https://patchew.org/linux/[email protected]/

 .../intel-quickspi/pci-quickspi.c             | 28 +++++++++++++++----
 1 file changed, 22 insertions(+), 6 deletions(-)
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +22 -6
index 89226f5ce45e..0bd22f285c78 100644
@@ -597,6 +597,8 @@ static int quickspi_probe(struct pci_dev *pdev,
 			  const struct pci_device_id *id)
 {
 	struct quickspi_device *qsdev;
+	bool dma_initialized = false;
+	bool irq_requested = false;
 	void __iomem *mem_addr;
 	int ret;
 
@@ -649,6 +651,7 @@ static int quickspi_probe(struct pci_dev *pdev,
 					qsdev);
 	if (ret)
 		goto dev_deinit;
+	irq_requested = true;
 
 	ret = reset_tic(qsdev);
 	if (ret) {
@@ -667,17 +670,18 @@ static int quickspi_probe(struct pci_dev *pdev,
 		dev_err(&pdev->dev, "Setup THC DMA failed, ret= %d\n", ret);
 		goto dev_deinit;
 	}
+	dma_initialized = true;
 
 	ret = quickspi_get_report_descriptor(qsdev);
 	if (ret) {
 		dev_err(&pdev->dev, "Get report descriptor failed, ret = %d\n", ret);
-		goto dma_deinit;
+		goto dev_deinit;
 	}
 
 	ret = quickspi_hid_probe(qsdev);
 	if (ret) {
 		dev_err(&pdev->dev, "Failed to register HID device, ret = %d\n", ret);
-		goto dma_deinit;
+		goto dev_deinit;
 	}
 
 	qsdev->state = QUICKSPI_ENABLED;
@@ -692,10 +696,16 @@ static int quickspi_probe(struct pci_dev *pdev,
 
 	return 0;
 
-dma_deinit:
-	quickspi_dma_deinit(qsdev);
 dev_deinit:
+	if (irq_requested) {
+		WRITE_ONCE(qsdev->recovery_disabled, true);
+		disable_irq(pdev->irq);
+	}
 	quickspi_dev_deinit(qsdev);
+	if (irq_requested)
+		devm_free_irq(&pdev->dev, pdev->irq, qsdev);
+	if (dma_initialized)
+		quickspi_dma_deinit(qsdev);
 disable_pci_device:
 	pci_clear_master(pdev);
 
@@ -718,9 +728,12 @@ static void quickspi_remove(struct pci_dev *pdev)
 	if (!qsdev)
 		return;
 
-	quickspi_hid_remove(qsdev);
-
+	WRITE_ONCE(qsdev->recovery_disabled, true);
+	disable_irq(pdev->irq);
 	quickspi_dev_deinit(qsdev);
+	devm_free_irq(&pdev->dev, pdev->irq, qsdev);
+
+	quickspi_hid_remove(qsdev);
 
 	quickspi_dma_deinit(qsdev);
 
@@ -747,6 +760,9 @@ static void quickspi_shutdown(struct pci_dev *pdev)
 	if (!qsdev)
 		return;
 
+	WRITE_ONCE(qsdev->recovery_disabled, true);
+	disable_irq(pdev->irq);
+
 	quickspi_dev_deinit(qsdev);
 
 	/* Must stop DMA before reboot to avoid DMA entering into unknown state */
#2 lore raw

Re: [PATCH 1/2] HID: intel-thc-hid: quickspi: quiesce IRQs during teardown

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] hid: intel-thc-hid: DMA UAF due to HID deregistration race in remove --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] hid: intel-thc-hid: DMA UAF due to HID deregistration race in remove --

commit 664b72e58bd5cb1485c8eb563326dab08180f916
Author: Myeonghun Pak <[email protected]>

HID: intel-thc-hid: quickspi: quiesce IRQs during teardown

This commit disables and synchronizes the IRQ and drains recovery work prior to freeing the IRQ and releasing HID/DMA resources. It introduces this ordered teardown in both the probe error and remove paths.

Quoted 4 lines
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +0 -0
index 53023e30cf8d4..c67476a378573 100644

[ ... ]

drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c static void quickspi_remove(struct pci_dev *pdev) · line 739

Quoted 12 lines
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +5 -2
@@ -721,9 +731,12 @@ static void quickspi_remove(struct pci_dev *pdev)
 	if (!qsdev)
 		return;
 
-	quickspi_hid_remove(qsdev);
-
+	WRITE_ONCE(qsdev->recovery_disabled, true);
+	disable_irq(pdev->irq);
 	quickspi_dev_deinit(qsdev);
+	devm_free_irq(&pdev->dev, pdev->irq, qsdev);
+
+	quickspi_hid_remove(qsdev);

[Severity: High]
Does this sequence open a race window for a hardware DMA use-after-free?

By tearing down the hardware and disabling interrupts before unregistering the HID device, it appears userspace can still issue a request via hidraw during unbind.

If a raw_request is queued on the disabled device, it may call thc_dma_write() to submit a TxDMA request:

drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c:thc_dma_write() {
    ...
	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;
	}
    ...
}

Because IRQs are disabled here, the wait will time out and return -ETIMEDOUT, but it fails to clear the TxDMA START bit.

quickspi_remove() will then proceed to unregister the HID device and call quickspi_dma_deinit(), which frees the DMA buffers without clearing the TxDMA START bit. Could this allow the hardware TxDMA engine to remain active and access freed DMA memory, leading to memory corruption or an IOMMU fault?

Note that follow-up patches in the series do not appear to resolve this race.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
maintainer
#3 lore raw

RE: [PATCH 1/2] HID: intel-thc-hid: quickspi: quiesce IRQs during teardown

In reply to Myeonghun Pak
Quoted 14 lines

-----Original Message-----
From: Myeonghun Pak <[email protected]>
Sent: Monday, October 12, 2026 6:06 AM
To: Xu, Even <[email protected]>; Sun, Xinpeng <[email protected]>; Jiri Kosina <[email protected]>; Benjamin Tissoires <[email protected]>
Cc: Srinivas Pandruvada <[email protected]>; Mark Pearson <[email protected]>; [email protected]; linux- [email protected]; Ijae Kim <[email protected]>
Subject: [PATCH 1/2] HID: intel-thc-hid: quickspi: quiesce IRQs during teardown

The managed IRQ can access HID/DMA buffers or queue recovery work while remove or probe unwind tears down those resources.

Quoted 8 lines

Disable and synchronize the IRQ, drain recovery work, then mask THC interrupts before freeing the IRQ and releasing HID/DMA resources.
Track IRQ/DMA initialization for conditional probe cleanup.

Disable the IRQ before shutdown deinit as well. Keep IRQ disabling and release outside the shared hibernation helper.

This issue was found by static analysis.

Thanks for your patch!

I think this patch is still necessary. It can prevent some extremely unlikely but problematic cases, such as an interrupt already being queued in the thread before the THC interrupt is disabled. Have you tested this code on actual hardware?

Best Regards,
Even Xu

Quoted 108 lines
Fixes 4138f21115ae ("HID: intel-thc-hid: intel-quickspi: Complete THC QuickSPI

driver")

---
Compile-tested with GCC, W=1 (x86_64). No runtime testing.

Related recovery-work review and series:
https://lore-kernel.gnuweeb.org/linux-input/20260717035609.3874015-1-
[email protected]/T/
https://patchew.org/linux/[email protected]/

 .../intel-quickspi/pci-quickspi.c             | 28 +++++++++++++++----
 1 file changed, 22 insertions(+), 6 deletions(-)
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +6 -2
index 89226f5ce45e..0bd22f285c78 100644
@@ -597,6 +597,8 @@ static int quickspi_probe(struct pci_dev *pdev,
 			  const struct pci_device_id *id)
 {
 	struct quickspi_device *qsdev;
+	bool dma_initialized = false;
+	bool irq_requested = false;
 	void __iomem *mem_addr;
 	int ret;
 
@@ -649,6 +651,7 @@ static int quickspi_probe(struct pci_dev *pdev,
 					qsdev);
 	if (ret)
 		goto dev_deinit;
+	irq_requested = true;
 
 	ret = reset_tic(qsdev);
 	if (ret) {
@@ -667,17 +670,18 @@ static int quickspi_probe(struct pci_dev *pdev,
 		dev_err(&pdev->dev, "Setup THC DMA failed, ret= %d\n", ret);
 		goto dev_deinit;
 	}
+	dma_initialized = true;
 
 	ret = quickspi_get_report_descriptor(qsdev);
 	if (ret) {
 		dev_err(&pdev->dev, "Get report descriptor failed, ret = %d\n",
 ret);
-		goto dma_deinit;
+		goto dev_deinit;
 	}
 
 	ret = quickspi_hid_probe(qsdev);
 	if (ret) {
 		dev_err(&pdev->dev, "Failed to register HID device, ret = %d\n",
 ret);
-		goto dma_deinit;
+		goto dev_deinit;
 	}
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +16 -4
 	qsdev->state = QUICKSPI_ENABLED;
@@ -692,10 +696,16 @@ static int quickspi_probe(struct pci_dev *pdev,
 
 	return 0;
 
-dma_deinit:
-	quickspi_dma_deinit(qsdev);
 dev_deinit:
+	if (irq_requested) {
+		WRITE_ONCE(qsdev->recovery_disabled, true);
+		disable_irq(pdev->irq);
+	}
 	quickspi_dev_deinit(qsdev);
+	if (irq_requested)
+		devm_free_irq(&pdev->dev, pdev->irq, qsdev);
+	if (dma_initialized)
+		quickspi_dma_deinit(qsdev);
 disable_pci_device:
 	pci_clear_master(pdev);
 
@@ -718,9 +728,12 @@ static void quickspi_remove(struct pci_dev *pdev)
 	if (!qsdev)
 		return;
 
-	quickspi_hid_remove(qsdev);
-
+	WRITE_ONCE(qsdev->recovery_disabled, true);
+	disable_irq(pdev->irq);
 	quickspi_dev_deinit(qsdev);
+	devm_free_irq(&pdev->dev, pdev->irq, qsdev);
+
+	quickspi_hid_remove(qsdev);
 
 	quickspi_dma_deinit(qsdev);
 
@@ -747,6 +760,9 @@ static void quickspi_shutdown(struct pci_dev *pdev)
 	if (!qsdev)
 		return;
 
+	WRITE_ONCE(qsdev->recovery_disabled, true);
+	disable_irq(pdev->irq);
+
 	quickspi_dev_deinit(qsdev);
 
 	/* Must stop DMA before reboot to avoid DMA entering into unknown

state */

#4 lore raw

Re: [PATCH 1/2] HID: intel-thc-hid: quickspi: quiesce IRQs during teardown

Hi Even,

Thanks for reviewing the patch.

No, I haven't tested it on actual hardware. I have only compile-tested it with GCC and W=1 on x86_64.

Best regards,
Myeonghun

2026년 10월 12일 (월) 오후 8:52, Xu, Even <[email protected]>님이 작성:

Quoted 139 lines
Quoted 15 lines

-----Original Message-----
From: Myeonghun Pak <[email protected]>
Sent: Monday, October 12, 2026 6:06 AM
To: Xu, Even <[email protected]>; Sun, Xinpeng <[email protected]>; Jiri Kosina <[email protected]>; Benjamin Tissoires <[email protected]>
Cc: Srinivas Pandruvada <[email protected]>; Mark Pearson <[email protected]>; [email protected]; linux- [email protected]; Ijae Kim <[email protected]>
Subject: [PATCH 1/2] HID: intel-thc-hid: quickspi: quiesce IRQs during teardown

The managed IRQ can access HID/DMA buffers or queue recovery work while remove or probe unwind tears down those resources.

Quoted 8 lines

Disable and synchronize the IRQ, drain recovery work, then mask THC interrupts before freeing the IRQ and releasing HID/DMA resources.
Track IRQ/DMA initialization for conditional probe cleanup.

Disable the IRQ before shutdown deinit as well. Keep IRQ disabling and release outside the shared hibernation helper.

This issue was found by static analysis.

Thanks for your patch!

I think this patch is still necessary. It can prevent some extremely unlikely but problematic cases, such as an interrupt already being queued in the thread before the THC interrupt is disabled. Have you tested this code on actual hardware?

Best Regards,
Even Xu

Quoted 108 lines
Fixes 4138f21115ae ("HID: intel-thc-hid: intel-quickspi: Complete THC QuickSPI

driver")

---
Compile-tested with GCC, W=1 (x86_64). No runtime testing.

Related recovery-work review and series:
https://lore-kernel.gnuweeb.org/linux-input/20260717035609.3874015-1-
[email protected]/T/
https://patchew.org/linux/[email protected]/

 .../intel-quickspi/pci-quickspi.c             | 28 +++++++++++++++----
 1 file changed, 22 insertions(+), 6 deletions(-)
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +6 -2
index 89226f5ce45e..0bd22f285c78 100644
@@ -597,6 +597,8 @@ static int quickspi_probe(struct pci_dev *pdev,
                        const struct pci_device_id *id)
 {
      struct quickspi_device *qsdev;
+     bool dma_initialized = false;
+     bool irq_requested = false;
      void __iomem *mem_addr;
      int ret;
 
@@ -649,6 +651,7 @@ static int quickspi_probe(struct pci_dev *pdev,
                                      qsdev);
      if (ret)
              goto dev_deinit;
+     irq_requested = true;
 
      ret = reset_tic(qsdev);
      if (ret) {
@@ -667,17 +670,18 @@ static int quickspi_probe(struct pci_dev *pdev,
              dev_err(&pdev->dev, "Setup THC DMA failed, ret= %d\n", ret);
              goto dev_deinit;
      }
+     dma_initialized = true;
 
      ret = quickspi_get_report_descriptor(qsdev);
      if (ret) {
              dev_err(&pdev->dev, "Get report descriptor failed, ret = %d\n",
 ret);
-             goto dma_deinit;
+             goto dev_deinit;
      }
 
      ret = quickspi_hid_probe(qsdev);
      if (ret) {
              dev_err(&pdev->dev, "Failed to register HID device, ret = %d\n",
 ret);
-             goto dma_deinit;
+             goto dev_deinit;
      }
      qsdev->state = QUICKSPI_ENABLED;
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +16 -4
@@ -692,10 +696,16 @@ static int quickspi_probe(struct pci_dev *pdev,
 
      return 0;
 
-dma_deinit:
-     quickspi_dma_deinit(qsdev);
 dev_deinit:
+     if (irq_requested) {
+             WRITE_ONCE(qsdev->recovery_disabled, true);
+             disable_irq(pdev->irq);
+     }
      quickspi_dev_deinit(qsdev);
+     if (irq_requested)
+             devm_free_irq(&pdev->dev, pdev->irq, qsdev);
+     if (dma_initialized)
+             quickspi_dma_deinit(qsdev);
 disable_pci_device:
      pci_clear_master(pdev);
 
@@ -718,9 +728,12 @@ static void quickspi_remove(struct pci_dev *pdev)
      if (!qsdev)
              return;
 
-     quickspi_hid_remove(qsdev);
-
+     WRITE_ONCE(qsdev->recovery_disabled, true);
+     disable_irq(pdev->irq);
      quickspi_dev_deinit(qsdev);
+     devm_free_irq(&pdev->dev, pdev->irq, qsdev);
+
+     quickspi_hid_remove(qsdev);
 
      quickspi_dma_deinit(qsdev);
 
@@ -747,6 +760,9 @@ static void quickspi_shutdown(struct pci_dev *pdev)
      if (!qsdev)
              return;
 
+     WRITE_ONCE(qsdev->recovery_disabled, true);
+     disable_irq(pdev->irq);
+
      quickspi_dev_deinit(qsdev);
 
      /* Must stop DMA before reboot to avoid DMA entering into unknown

state */

maintainer
#5 lore raw

RE: [PATCH 1/2] HID: intel-thc-hid: quickspi: quiesce IRQs during teardown

Hi, Myeonghun,

Then let me test it, it may take several days.
Will feedback once test finished.

Best Regards,
Even Xu

Quoted 168 lines

-----Original Message-----
From: Myeonghun Pak <[email protected]>
Sent: Thursday, October 15, 2026 8:36 AM
To: Xu, Even <[email protected]>
Cc: Sun, Xinpeng <[email protected]>; Jiri Kosina <[email protected]>; Benjamin Tissoires <[email protected]>; Srinivas Pandruvada <[email protected]>; Mark Pearson <mpearson- [email protected]>; [email protected]; [email protected]; Ijae Kim <[email protected]>
Subject: Re: [PATCH 1/2] HID: intel-thc-hid: quickspi: quiesce IRQs during teardown

Hi Even,

Thanks for reviewing the patch.

No, I haven't tested it on actual hardware. I have only compile-tested it with GCC and W=1 on x86_64.

Best regards,
Myeonghun

2026년 10월 12일 (월) 오후 8:52, Xu, Even <[email protected]>님이 작성:

Quoted 21 lines
Quoted 21 lines

-----Original Message-----
From: Myeonghun Pak <[email protected]>
Sent: Monday, October 12, 2026 6:06 AM
To: Xu, Even <[email protected]>; Sun, Xinpeng <[email protected]>; Jiri Kosina <[email protected]>; Benjamin Tissoires <[email protected]>
Cc: Srinivas Pandruvada <[email protected]>; Mark Pearson <[email protected]>; [email protected]; linux- [email protected]; Ijae Kim <[email protected]>
Subject: [PATCH 1/2] HID: intel-thc-hid: quickspi: quiesce IRQs during teardown

The managed IRQ can access HID/DMA buffers or queue recovery work while remove or probe unwind tears down those resources.

Disable and synchronize the IRQ, drain recovery work, then mask THC interrupts before freeing the IRQ and releasing HID/DMA resources. Track IRQ/DMA initialization for conditional probe cleanup.

Quoted 8 lines
Quoted 4 lines

Disable the IRQ before shutdown deinit as well. Keep IRQ disabling and release outside the shared hibernation helper.

This issue was found by static analysis.

Thanks for your patch!

I think this patch is still necessary. It can prevent some extremely unlikely but

problematic cases, such as an interrupt already being queued in the thread before the THC interrupt is disabled. Have you tested this code on actual hardware?

Quoted 114 lines

Best Regards,
Even Xu

Quoted 110 lines
Fixes 4138f21115ae ("HID: intel-thc-hid: intel-quickspi: Complete

THC QuickSPI
driver")

---
Compile-tested with GCC, W=1 (x86_64). No runtime testing.

Related recovery-work review and series:
https://lore-kernel.gnuweeb.org/linux-input/20260717035609.3874015-1
-
[email protected]/T/
https://patchew.org/linux/[email protected]
/

 .../intel-quickspi/pci-quickspi.c             | 28 +++++++++++++++----
 1 file changed, 22 insertions(+), 6 deletions(-)
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +6 -2
index 89226f5ce45e..0bd22f285c78 100644
@@ -597,6 +597,8 @@ static int quickspi_probe(struct pci_dev *pdev,
                        const struct pci_device_id *id)  {
      struct quickspi_device *qsdev;
+     bool dma_initialized = false;
+     bool irq_requested = false;
      void __iomem *mem_addr;
      int ret;
 
@@ -649,6 +651,7 @@ static int quickspi_probe(struct pci_dev *pdev,
                                      qsdev);
      if (ret)
              goto dev_deinit;
+     irq_requested = true;
 
      ret = reset_tic(qsdev);
      if (ret) {
@@ -667,17 +670,18 @@ static int quickspi_probe(struct pci_dev *pdev,
              dev_err(&pdev->dev, "Setup THC DMA failed, ret= %d\n", ret);
              goto dev_deinit;
      }
+     dma_initialized = true;
 
      ret = quickspi_get_report_descriptor(qsdev);
      if (ret) {
              dev_err(&pdev->dev, "Get report descriptor failed, ret
 = %d\n", ret);
-             goto dma_deinit;
+             goto dev_deinit;
      }
 
      ret = quickspi_hid_probe(qsdev);
      if (ret) {
              dev_err(&pdev->dev, "Failed to register HID device,
 ret = %d\n", ret);
-             goto dma_deinit;
+             goto dev_deinit;
      }
      qsdev->state = QUICKSPI_ENABLED; @@ -692,10 +696,16 @@ static

int quickspi_probe(struct pci_dev *pdev,

      return 0;
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +16 -4
-dma_deinit:
-     quickspi_dma_deinit(qsdev);
 dev_deinit:
+     if (irq_requested) {
+             WRITE_ONCE(qsdev->recovery_disabled, true);
+             disable_irq(pdev->irq);
+     }
      quickspi_dev_deinit(qsdev);
+     if (irq_requested)
+             devm_free_irq(&pdev->dev, pdev->irq, qsdev);
+     if (dma_initialized)
+             quickspi_dma_deinit(qsdev);
 disable_pci_device:
      pci_clear_master(pdev);
@@ -718,9 +728,12 @@ static void quickspi_remove(struct pci_dev *pdev)
      if (!qsdev)
              return;
 
-     quickspi_hid_remove(qsdev);
-
+     WRITE_ONCE(qsdev->recovery_disabled, true);
+     disable_irq(pdev->irq);
      quickspi_dev_deinit(qsdev);
+     devm_free_irq(&pdev->dev, pdev->irq, qsdev);
+
+     quickspi_hid_remove(qsdev);
 
      quickspi_dma_deinit(qsdev);
 
@@ -747,6 +760,9 @@ static void quickspi_shutdown(struct pci_dev *pdev)
      if (!qsdev)
              return;
 
+     WRITE_ONCE(qsdev->recovery_disabled, true);
+     disable_irq(pdev->irq);
+
      quickspi_dev_deinit(qsdev);
 
      /* Must stop DMA before reboot to avoid DMA entering into

unknown state */

maintainer
#6 lore raw

RE: [PATCH 1/2] HID: intel-thc-hid: quickspi: quiesce IRQs during teardown

Hi, Myeonghun,

Validation passed, but I suppose you need rebase your patches on top of latest mainline kernel.

Best Regards,
Even Xu

Quoted 195 lines

-----Original Message-----
From: Xu, Even
Sent: Thursday, October 15, 2026 9:53 AM
To: 'Myeonghun Pak' <[email protected]>
Cc: Sun, Xinpeng <[email protected]>; Jiri Kosina <[email protected]>; Benjamin Tissoires <[email protected]>; Srinivas Pandruvada <[email protected]>; Mark Pearson <mpearson- [email protected]>; [email protected]; [email protected]; Ijae Kim <[email protected]>
Subject: RE: [PATCH 1/2] HID: intel-thc-hid: quickspi: quiesce IRQs during teardown

Hi, Myeonghun,

Then let me test it, it may take several days.
Will feedback once test finished.

Best Regards,
Even Xu

Quoted 48 lines

-----Original Message-----
From: Myeonghun Pak <[email protected]>
Sent: Thursday, October 15, 2026 8:36 AM
To: Xu, Even <[email protected]>
Cc: Sun, Xinpeng <[email protected]>; Jiri Kosina <[email protected]>; Benjamin Tissoires <[email protected]>; Srinivas Pandruvada <[email protected]>; Mark Pearson <mpearson- [email protected]>; [email protected]; [email protected]; Ijae Kim <[email protected]>
Subject: Re: [PATCH 1/2] HID: intel-thc-hid: quickspi: quiesce IRQs during teardown

Hi Even,

Thanks for reviewing the patch.

No, I haven't tested it on actual hardware. I have only compile-tested it with GCC and W=1 on x86_64.

Best regards,
Myeonghun

2026년 10월 12일 (월) 오후 8:52, Xu, Even <[email protected]>님이 작성:

Quoted 25 lines
Quoted 25 lines

-----Original Message-----
From: Myeonghun Pak <[email protected]>
Sent: Monday, October 12, 2026 6:06 AM
To: Xu, Even <[email protected]>; Sun, Xinpeng <[email protected]>; Jiri Kosina <[email protected]>; Benjamin Tissoires <[email protected]>
Cc: Srinivas Pandruvada <[email protected]>; Mark Pearson <[email protected]>; [email protected];
linux- [email protected]; Ijae Kim <[email protected]>
Subject: [PATCH 1/2] HID: intel-thc-hid: quickspi: quiesce IRQs during teardown

The managed IRQ can access HID/DMA buffers or queue recovery work while remove or probe unwind tears down those resources.

Disable and synchronize the IRQ, drain recovery work, then mask THC interrupts before freeing the IRQ and releasing HID/DMA resources. Track IRQ/DMA initialization for conditional probe cleanup.

Disable the IRQ before shutdown deinit as well. Keep IRQ disabling and release outside the shared hibernation helper.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

This issue was found by static analysis.

Thanks for your patch!

I think this patch is still necessary. It can prevent some extremely unlikely but

problematic cases, such as an interrupt already being queued in the thread before the THC interrupt is disabled. Have you tested this code on actual

hardware?

Quoted 104 lines
Quoted 104 lines

Best Regards,
Even Xu

Quoted 100 lines
Fixes 4138f21115ae ("HID: intel-thc-hid: intel-quickspi: Complete

THC QuickSPI
driver")

---
Compile-tested with GCC, W=1 (x86_64). No runtime testing.

Related recovery-work review and series:
https://lore-kernel.gnuweeb.org/linux-input/20260717035609.3874015
-1
-
[email protected]/T/
https://patchew.org/linux/[email protected]
om
/

 .../intel-quickspi/pci-quickspi.c             | 28 +++++++++++++++----
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c b/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c index 89226f5ce45e..0bd22f285c78 100644

drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +6 -2
@@ -597,6 +597,8 @@ static int quickspi_probe(struct pci_dev *pdev,
                        const struct pci_device_id *id)  {
      struct quickspi_device *qsdev;
+     bool dma_initialized = false;
+     bool irq_requested = false;
      void __iomem *mem_addr;
      int ret;
 
@@ -649,6 +651,7 @@ static int quickspi_probe(struct pci_dev *pdev,
                                      qsdev);
      if (ret)
              goto dev_deinit;
+     irq_requested = true;
 
      ret = reset_tic(qsdev);
      if (ret) {
@@ -667,17 +670,18 @@ static int quickspi_probe(struct pci_dev *pdev,
              dev_err(&pdev->dev, "Setup THC DMA failed, ret= %d\n", ret);
              goto dev_deinit;
      }
+     dma_initialized = true;
 
      ret = quickspi_get_report_descriptor(qsdev);
      if (ret) {
              dev_err(&pdev->dev, "Get report descriptor failed,
 ret = %d\n", ret);
-             goto dma_deinit;
+             goto dev_deinit;
      }
 
      ret = quickspi_hid_probe(qsdev);
      if (ret) {
              dev_err(&pdev->dev, "Failed to register HID device,
 ret = %d\n", ret);
-             goto dma_deinit;
+             goto dev_deinit;
      }
      qsdev->state = QUICKSPI_ENABLED; @@ -692,10 +696,16 @@

static int quickspi_probe(struct pci_dev *pdev,

      return 0;
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +13 -4
-dma_deinit:
-     quickspi_dma_deinit(qsdev);
 dev_deinit:
+     if (irq_requested) {
+             WRITE_ONCE(qsdev->recovery_disabled, true);
+             disable_irq(pdev->irq);
+     }
      quickspi_dev_deinit(qsdev);
+     if (irq_requested)
+             devm_free_irq(&pdev->dev, pdev->irq, qsdev);
+     if (dma_initialized)
+             quickspi_dma_deinit(qsdev);
 disable_pci_device:
      pci_clear_master(pdev);
@@ -718,9 +728,12 @@ static void quickspi_remove(struct pci_dev *pdev)
      if (!qsdev)
              return;
 
-     quickspi_hid_remove(qsdev);
-
+     WRITE_ONCE(qsdev->recovery_disabled, true);
+     disable_irq(pdev->irq);
      quickspi_dev_deinit(qsdev);
+     devm_free_irq(&pdev->dev, pdev->irq, qsdev);
+
+     quickspi_hid_remove(qsdev);
 
Quoted 3 lines
Quoted 3 lines

drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c static void quickspi_shutdown(struct pci_dev

Quoted 3 lines
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +0 -0
      quickspi_dma_deinit(qsdev);
 
@@ -747,6 +760,9 @@ static void quickspi_shutdown(struct pci_dev

*pdev)

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +3 -0
      if (!qsdev)
              return;
 
+     WRITE_ONCE(qsdev->recovery_disabled, true);
+     disable_irq(pdev->irq);
+
      quickspi_dev_deinit(qsdev);
 
      /* Must stop DMA before reboot to avoid DMA entering into

unknown state */

#7 lore raw

Re: [PATCH 1/2] HID: intel-thc-hid: quickspi: quiesce IRQs during teardown

Hi Even,

Thanks for testing. I've rebased both patches onto the latest mainline with no other code changes.

Best regards,
Myeonghun

2026년 10월 26일 (월) 오후 10:05, Xu, Even <[email protected]>님이 작성:

Quoted 203 lines

Hi, Myeonghun,

Validation passed, but I suppose you need rebase your patches on top of latest mainline kernel.

Best Regards,
Even Xu

Quoted 195 lines

-----Original Message-----
From: Xu, Even
Sent: Thursday, October 15, 2026 9:53 AM
To: 'Myeonghun Pak' <[email protected]>
Cc: Sun, Xinpeng <[email protected]>; Jiri Kosina <[email protected]>; Benjamin Tissoires <[email protected]>; Srinivas Pandruvada <[email protected]>; Mark Pearson <mpearson- [email protected]>; [email protected]; [email protected]; Ijae Kim <[email protected]>
Subject: RE: [PATCH 1/2] HID: intel-thc-hid: quickspi: quiesce IRQs during teardown

Hi, Myeonghun,

Then let me test it, it may take several days.
Will feedback once test finished.

Best Regards,
Even Xu

Quoted 48 lines

-----Original Message-----
From: Myeonghun Pak <[email protected]>
Sent: Thursday, October 15, 2026 8:36 AM
To: Xu, Even <[email protected]>
Cc: Sun, Xinpeng <[email protected]>; Jiri Kosina <[email protected]>; Benjamin Tissoires <[email protected]>; Srinivas Pandruvada <[email protected]>; Mark Pearson <mpearson- [email protected]>; [email protected]; [email protected]; Ijae Kim <[email protected]>
Subject: Re: [PATCH 1/2] HID: intel-thc-hid: quickspi: quiesce IRQs during teardown

Hi Even,

Thanks for reviewing the patch.

No, I haven't tested it on actual hardware. I have only compile-tested it with GCC and W=1 on x86_64.

Best regards,
Myeonghun

2026년 10월 12일 (월) 오후 8:52, Xu, Even <[email protected]>님이 작성:

Quoted 25 lines
Quoted 25 lines

-----Original Message-----
From: Myeonghun Pak <[email protected]>
Sent: Monday, October 12, 2026 6:06 AM
To: Xu, Even <[email protected]>; Sun, Xinpeng <[email protected]>; Jiri Kosina <[email protected]>; Benjamin Tissoires <[email protected]>
Cc: Srinivas Pandruvada <[email protected]>; Mark Pearson <[email protected]>; [email protected];
linux- [email protected]; Ijae Kim <[email protected]>
Subject: [PATCH 1/2] HID: intel-thc-hid: quickspi: quiesce IRQs during teardown

The managed IRQ can access HID/DMA buffers or queue recovery work while remove or probe unwind tears down those resources.

Disable and synchronize the IRQ, drain recovery work, then mask THC interrupts before freeing the IRQ and releasing HID/DMA resources. Track IRQ/DMA initialization for conditional probe cleanup.

Disable the IRQ before shutdown deinit as well. Keep IRQ disabling and release outside the shared hibernation helper.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

This issue was found by static analysis.

Thanks for your patch!

I think this patch is still necessary. It can prevent some extremely unlikely but

problematic cases, such as an interrupt already being queued in the thread before the THC interrupt is disabled. Have you tested this code on actual

hardware?

Quoted 104 lines
Quoted 104 lines

Best Regards,
Even Xu

Quoted 100 lines
Fixes 4138f21115ae ("HID: intel-thc-hid: intel-quickspi: Complete

THC QuickSPI
driver")

---
Compile-tested with GCC, W=1 (x86_64). No runtime testing.

Related recovery-work review and series:
https://lore-kernel.gnuweeb.org/linux-input/20260717035609.3874015
-1
-
[email protected]/T/
https://patchew.org/linux/[email protected]
om
/

 .../intel-quickspi/pci-quickspi.c             | 28 +++++++++++++++----
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c b/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c index 89226f5ce45e..0bd22f285c78 100644

drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +6 -2
@@ -597,6 +597,8 @@ static int quickspi_probe(struct pci_dev *pdev,
                        const struct pci_device_id *id)  {
      struct quickspi_device *qsdev;
+     bool dma_initialized = false;
+     bool irq_requested = false;
      void __iomem *mem_addr;
      int ret;
 
@@ -649,6 +651,7 @@ static int quickspi_probe(struct pci_dev *pdev,
                                      qsdev);
      if (ret)
              goto dev_deinit;
+     irq_requested = true;
 
      ret = reset_tic(qsdev);
      if (ret) {
@@ -667,17 +670,18 @@ static int quickspi_probe(struct pci_dev *pdev,
              dev_err(&pdev->dev, "Setup THC DMA failed, ret= %d\n", ret);
              goto dev_deinit;
      }
+     dma_initialized = true;
 
      ret = quickspi_get_report_descriptor(qsdev);
      if (ret) {
              dev_err(&pdev->dev, "Get report descriptor failed,
 ret = %d\n", ret);
-             goto dma_deinit;
+             goto dev_deinit;
      }
 
      ret = quickspi_hid_probe(qsdev);
      if (ret) {
              dev_err(&pdev->dev, "Failed to register HID device,
 ret = %d\n", ret);
-             goto dma_deinit;
+             goto dev_deinit;
      }
      qsdev->state = QUICKSPI_ENABLED; @@ -692,10 +696,16 @@

static int quickspi_probe(struct pci_dev *pdev,

      return 0;
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +13 -4
-dma_deinit:
-     quickspi_dma_deinit(qsdev);
 dev_deinit:
+     if (irq_requested) {
+             WRITE_ONCE(qsdev->recovery_disabled, true);
+             disable_irq(pdev->irq);
+     }
      quickspi_dev_deinit(qsdev);
+     if (irq_requested)
+             devm_free_irq(&pdev->dev, pdev->irq, qsdev);
+     if (dma_initialized)
+             quickspi_dma_deinit(qsdev);
 disable_pci_device:
      pci_clear_master(pdev);
@@ -718,9 +728,12 @@ static void quickspi_remove(struct pci_dev *pdev)
      if (!qsdev)
              return;
 
-     quickspi_hid_remove(qsdev);
-
+     WRITE_ONCE(qsdev->recovery_disabled, true);
+     disable_irq(pdev->irq);
      quickspi_dev_deinit(qsdev);
+     devm_free_irq(&pdev->dev, pdev->irq, qsdev);
+
+     quickspi_hid_remove(qsdev);
 
Quoted 3 lines
Quoted 3 lines

drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c static void quickspi_shutdown(struct pci_dev

Quoted 3 lines
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +0 -0
      quickspi_dma_deinit(qsdev);
 
@@ -747,6 +760,9 @@ static void quickspi_shutdown(struct pci_dev

*pdev)

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +3 -0
      if (!qsdev)
              return;
 
+     WRITE_ONCE(qsdev->recovery_disabled, true);
+     disable_irq(pdev->irq);
+
      quickspi_dev_deinit(qsdev);
 
      /* Must stop DMA before reboot to avoid DMA entering into

unknown state */

maintainer
#8 lore raw

RE: [PATCH 1/2] HID: intel-thc-hid: quickspi: quiesce IRQs during teardown

Hi, Myeonghun,

Got it, will review your new patches and feedback!

Best Regards,
Even Xu

Quoted 234 lines

-----Original Message-----
From: Myeonghun Pak <[email protected]>
Sent: Tuesday, November 10, 2026 12:43 PM
To: Xu, Even <[email protected]>
Cc: Sun, Xinpeng <[email protected]>; Jiri Kosina <[email protected]>; Benjamin Tissoires <[email protected]>; Srinivas Pandruvada <[email protected]>; Mark Pearson <mpearson- [email protected]>; [email protected]; [email protected]; Ijae Kim <[email protected]>
Subject: Re: [PATCH 1/2] HID: intel-thc-hid: quickspi: quiesce IRQs during teardown

Hi Even,

Thanks for testing. I've rebased both patches onto the latest mainline with no other code changes.

Best regards,
Myeonghun

2026년 10월 26일 (월) 오후 10:05, Xu, Even <[email protected]>님이 작성:

Quoted 4 lines

Hi, Myeonghun,

Validation passed, but I suppose you need rebase your patches on top of latest

mainline kernel.

Quoted 48 lines

Best Regards,
Even Xu

Quoted 44 lines

-----Original Message-----
From: Xu, Even
Sent: Thursday, October 15, 2026 9:53 AM
To: 'Myeonghun Pak' <[email protected]>
Cc: Sun, Xinpeng <[email protected]>; Jiri Kosina <[email protected]>; Benjamin Tissoires <[email protected]>; Srinivas Pandruvada <[email protected]>; Mark Pearson <mpearson- [email protected]>; [email protected]; [email protected]; Ijae Kim <[email protected]>
Subject: RE: [PATCH 1/2] HID: intel-thc-hid: quickspi: quiesce IRQs during teardown

Hi, Myeonghun,

Then let me test it, it may take several days.
Will feedback once test finished.

Best Regards,
Even Xu

Quoted 24 lines

-----Original Message-----
From: Myeonghun Pak <[email protected]>
Sent: Thursday, October 15, 2026 8:36 AM
To: Xu, Even <[email protected]>
Cc: Sun, Xinpeng <[email protected]>; Jiri Kosina <[email protected]>; Benjamin Tissoires <[email protected]>; Srinivas Pandruvada <[email protected]>; Mark Pearson
<mpearson- [email protected]>; [email protected]; [email protected]; Ijae Kim <[email protected]>
Subject: Re: [PATCH 1/2] HID: intel-thc-hid: quickspi: quiesce IRQs during teardown

Hi Even,

Thanks for reviewing the patch.

No, I haven't tested it on actual hardware. I have only compile-tested it with GCC and W=1 on x86_64.

Best regards,
Myeonghun

2026년 10월 12일 (월) 오후 8:52, Xu, Even <[email protected]>님이

작성:

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 15 lines

-----Original Message-----
From: Myeonghun Pak <[email protected]>
Sent: Monday, October 12, 2026 6:06 AM
To: Xu, Even <[email protected]>; Sun, Xinpeng <[email protected]>; Jiri Kosina <[email protected]>; Benjamin Tissoires <[email protected]>
Cc: Srinivas Pandruvada <[email protected]>; Mark Pearson <[email protected]>; [email protected];
linux- [email protected]; Ijae Kim <[email protected]>
Subject: [PATCH 1/2] HID: intel-thc-hid: quickspi: quiesce IRQs during teardown

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

The managed IRQ can access HID/DMA buffers or queue recovery work while remove or probe unwind tears down those resources.

Disable and synchronize the IRQ, drain recovery work, then mask THC interrupts before freeing the IRQ and releasing HID/DMA

resources.

Quoted 64 lines
Quoted 64 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines

Track IRQ/DMA initialization for conditional probe cleanup.

Disable the IRQ before shutdown deinit as well. Keep IRQ disabling and release outside the shared hibernation helper.

This issue was found by static analysis.

Quoted 7 lines
Quoted 4 lines

Thanks for your patch!

I think this patch is still necessary. It can prevent some extremely unlikely but

problematic cases, such as an interrupt already being queued in the thread before the THC interrupt is disabled. Have you tested this code on actual

hardware?

Quoted 49 lines
Quoted 49 lines

Best Regards,
Even Xu

Quoted 45 lines
Fixes 4138f21115ae ("HID: intel-thc-hid: intel-quickspi:

Complete THC QuickSPI
driver")

---
Compile-tested with GCC, W=1 (x86_64). No runtime testing.

Related recovery-work review and series:
https://lore-kernel.gnuweeb.org/linux-input/20260717035609.387
4015
-1
-
[email protected]/T/
https://patchew.org/linux/20260729050145.2272597-1-even.xu@int
el.c
om
/

 .../intel-quickspi/pci-quickspi.c             | 28 +++++++++++++++----
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c b/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c index 89226f5ce45e..0bd22f285c78 100644

drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +3 -0
@@ -597,6 +597,8 @@ static int quickspi_probe(struct pci_dev *pdev,
                        const struct pci_device_id *id)  {
      struct quickspi_device *qsdev;
+     bool dma_initialized = false;
+     bool irq_requested = false;
      void __iomem *mem_addr;
      int ret;
 
@@ -649,6 +651,7 @@ static int quickspi_probe(struct pci_dev *pdev,
                                      qsdev);
      if (ret)
              goto dev_deinit;
+     irq_requested = true;
 
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c static int quickspi_probe(struct pci_dev

Quoted 3 lines
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +0 -0
      ret = reset_tic(qsdev);
      if (ret) {
@@ -667,17 +670,18 @@ static int quickspi_probe(struct pci_dev

*pdev,

Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
Quoted 41 lines
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +3 -2
              dev_err(&pdev->dev, "Setup THC DMA failed, ret= %d\n", ret);
              goto dev_deinit;
      }
+     dma_initialized = true;
 
      ret = quickspi_get_report_descriptor(qsdev);
      if (ret) {
              dev_err(&pdev->dev, "Get report descriptor
 failed, ret = %d\n", ret);
-             goto dma_deinit;
+             goto dev_deinit;
      }
 
      ret = quickspi_hid_probe(qsdev);
      if (ret) {
              dev_err(&pdev->dev, "Failed to register HID
 device, ret = %d\n", ret);
-             goto dma_deinit;
+             goto dev_deinit;
      }
      qsdev->state = QUICKSPI_ENABLED; @@ -692,10 +696,16 @@

static int quickspi_probe(struct pci_dev *pdev,

      return 0;
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +8 -2
-dma_deinit:
-     quickspi_dma_deinit(qsdev);
 dev_deinit:
+     if (irq_requested) {
+             WRITE_ONCE(qsdev->recovery_disabled, true);
+             disable_irq(pdev->irq);
+     }
      quickspi_dev_deinit(qsdev);
+     if (irq_requested)
+             devm_free_irq(&pdev->dev, pdev->irq, qsdev);
+     if (dma_initialized)
+             quickspi_dma_deinit(qsdev);
 disable_pci_device:
      pci_clear_master(pdev);
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c static void quickspi_remove(struct pci_dev

Quoted 1 line
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +0 -0
@@ -718,9 +728,12 @@ static void quickspi_remove(struct pci_dev

*pdev)

Quoted 27 lines
Quoted 27 lines
Quoted 12 lines
Quoted 12 lines
Quoted 12 lines
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +5 -2
      if (!qsdev)
              return;
 
-     quickspi_hid_remove(qsdev);
-
+     WRITE_ONCE(qsdev->recovery_disabled, true);
+     disable_irq(pdev->irq);
      quickspi_dev_deinit(qsdev);
+     devm_free_irq(&pdev->dev, pdev->irq, qsdev);
+
+     quickspi_hid_remove(qsdev);
 
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +0 -0
      quickspi_dma_deinit(qsdev);
 
@@ -747,6 +760,9 @@ static void quickspi_shutdown(struct

pci_dev

*pdev)

Quoted 10 lines
Quoted 10 lines
Quoted 10 lines
      if (!qsdev)
              return;
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +3 -0
+     WRITE_ONCE(qsdev->recovery_disabled, true);
+     disable_irq(pdev->irq);
+
      quickspi_dev_deinit(qsdev);
 
      /* Must stop DMA before reboot to avoid DMA entering

into unknown state */

#9 lore raw

PATCH 2/2 HID: intel-thc-hid: quicki2c: quiesce IRQs during teardown

In reply to Myeonghun Pak

The managed IRQ can access HID/DMA buffers or queue recovery work while remove or probe unwind tears down those resources.

Disable and synchronize the IRQ, drain recovery work, then mask THC interrupts before freeing the IRQ and releasing HID/DMA resources. Track IRQ/DMA initialization for conditional probe cleanup.

Disable the IRQ before shutdown deinit as well. Keep IRQ disabling and release outside the shared hibernation helper.

This issue was found by static analysis.

Fixes 66b59bfce6d9 ("HID: intel-thc-hid: intel-quicki2c: Complete THC QuickI2C driver")
Assisted-by LLM

---
Compile-tested with GCC, W=1 (x86_64). No runtime testing.

Related recovery-work review and series:
https://lore-kernel.gnuweeb.org/linux-input/[email protected]/T/
https://patchew.org/linux/[email protected]/

 .../intel-quicki2c/pci-quicki2c.c             | 28 +++++++++++++++----
 1 file changed, 22 insertions(+), 6 deletions(-)
drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c +22 -6
index 0d2ad7bc3648..9a9b640f32b3 100644
@@ -648,6 +648,8 @@ static int quicki2c_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 {
 	const struct quicki2c_ddata *ddata = (const struct quicki2c_ddata *)id->driver_data;
 	struct quicki2c_device *qcdev;
+	bool dma_initialized = false;
+	bool irq_requested = false;
 	void __iomem *mem_addr;
 	int ret;
 
@@ -700,6 +702,7 @@ static int quicki2c_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 					qcdev);
 	if (ret)
 		goto dev_deinit;
+	irq_requested = true;
 
 	ret = quicki2c_get_device_descriptor(qcdev);
 	if (ret) {
@@ -718,6 +721,7 @@ static int quicki2c_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		dev_err(&pdev->dev, "Setup THC DMA failed, ret= %d\n", ret);
 		goto dev_deinit;
 	}
+	dma_initialized = true;
 
 	ret = thc_interrupt_quiesce(qcdev->thc_hw, false);
 	if (ret)
@@ -738,13 +742,13 @@ static int quicki2c_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	ret = quicki2c_get_report_descriptor(qcdev);
 	if (ret) {
 		dev_err(&pdev->dev, "Get report descriptor failed, ret = %d\n", ret);
-		goto dma_deinit;
+		goto dev_deinit;
 	}
 
 	ret = quicki2c_hid_probe(qcdev);
 	if (ret) {
 		dev_err(&pdev->dev, "Failed to register HID device, ret = %d\n", ret);
-		goto dma_deinit;
+		goto dev_deinit;
 	}
 
 	qcdev->state = QUICKI2C_ENABLED;
@@ -759,10 +763,16 @@ static int quicki2c_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 	return 0;
 
-dma_deinit:
-	quicki2c_dma_deinit(qcdev);
 dev_deinit:
+	if (irq_requested) {
+		WRITE_ONCE(qcdev->recovery_disabled, true);
+		disable_irq(pdev->irq);
+	}
 	quicki2c_dev_deinit(qcdev);
+	if (irq_requested)
+		devm_free_irq(&pdev->dev, pdev->irq, qcdev);
+	if (dma_initialized)
+		quicki2c_dma_deinit(qcdev);
 disable_pci_device:
 	pci_clear_master(pdev);
 
@@ -784,9 +794,12 @@ static void quicki2c_remove(struct pci_dev *pdev)
 	if (!qcdev)
 		return;
 
-	quicki2c_hid_remove(qcdev);
-
+	WRITE_ONCE(qcdev->recovery_disabled, true);
+	disable_irq(pdev->irq);
 	quicki2c_dev_deinit(qcdev);
+	devm_free_irq(&pdev->dev, pdev->irq, qcdev);
+
+	quicki2c_hid_remove(qcdev);
 
 	quicki2c_dma_deinit(qcdev);
 
@@ -811,6 +824,9 @@ static void quicki2c_shutdown(struct pci_dev *pdev)
 	if (!qcdev)
 		return;
 
+	WRITE_ONCE(qcdev->recovery_disabled, true);
+	disable_irq(pdev->irq);
+
 	quicki2c_dev_deinit(qcdev);
 
 	/* Must stop DMA before reboot to avoid DMA entering into unknown state */
#10 lore raw

Re: [PATCH 2/2] HID: intel-thc-hid: quicki2c: quiesce IRQs during teardown

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] hid: intel-thc: 1s timeout on HID teardown commands due to early IRQ disable --

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] hid: intel-thc: 1s timeout on HID teardown commands due to early IRQ disable --

commit 074bce22ab8075bef92df21dcd016a16b939a785
Author: Myeonghun Pak <[email protected]>

HID: intel-thc-hid: quicki2c: quiesce IRQs during teardown

This commit disables and synchronizes the IRQ, drains recovery work, and masks THC interrupts before freeing the IRQ and releasing HID/DMA resources. It tracks IRQ/DMA initialization for conditional probe cleanup and disables the IRQ during shutdown as well.

Quoted 4 lines
drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c +0 -0
index 7a913f717efaa..ac073be894817 100644

[ ... ]

drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c static void quicki2c_remove(struct pci_dev *pdev) · line 806

Quoted 12 lines
drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c +5 -2
@@ -788,9 +798,12 @@ static void quicki2c_remove(struct pci_dev *pdev)
 	if (!qcdev)
 		return;
 
-	quicki2c_hid_remove(qcdev);
-
+	WRITE_ONCE(qcdev->recovery_disabled, true);
+	disable_irq(pdev->irq);
 	quicki2c_dev_deinit(qcdev);
+	devm_free_irq(&pdev->dev, pdev->irq, qcdev);
+
+	quicki2c_hid_remove(qcdev);

[Severity: Medium]
Could moving the IRQ disable/free and device deinit before quicki2c_hid_remove() break any HID raw_requests issued during high-level driver teardown?

High-level HID drivers (like hid-multitouch) often send final commands (e.g., turning off LEDs or disabling features) during their remove callback, which is triggered by hid_destroy_device() inside quicki2c_hid_remove().

Since the patch moves disable_irq() and devm_free_irq() before quicki2c_hid_remove(), thc_dma_write() in intel-thc-dma.c will block for 1 second waiting for an IRQ completion that will never arrive:

	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;
	}

This might unconditionally introduce a 1-second delay per command during device unbind or system shutdown if the bound high-level HID driver issues any hardware commands in its remove callback.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2