HID: intel-thc-hid: quiesce IRQs during teardown
Subsystems (2)
v3 cover HID: intel-thc-hid: quiesce IRQs during teardown
This resends v2 with the probe cleanup formatting requested by Even. There are no functional changes from v2.
Changes in v3:
- Add blank lines in the probe error paths of both drivers (Even).
v2: https://lore.kernel.org/all/[email protected]/
No hardware testing.
Myeonghun Pak (2):
HID: intel-thc-hid: quickspi: quiesce IRQs during teardown
HID: intel-thc-hid: quicki2c: quiesce IRQs during teardown
.../intel-quicki2c/pci-quicki2c.c | 32 ++++++++++++++++++++++++++------ .../intel-quickspi/pci-quickspi.c | 32 ++++++++++++++++++++++++++------ 2 files changed, 52 insertions(+), 12 deletions(-)
base-commit: b3dfbde62cf1981c4638939c159dfd087b7a72e9
PATCH v3 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.
Found by a static analysis tool under development.
---
Changes in v3:
- Add blank lines in the probe error path (Even).
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-)
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +26 -6
@@ -600,6 +600,8 @@ const struct pci_device_id *id) {struct quickspi_device *qsdev; +bool dma_initialized = false; +bool irq_requested = false;void __iomem *mem_addr;int ret;
@@ -652,6 +654,7 @@ qsdev);if (ret) goto dev_deinit; + irq_requested = true; ret =reset_tic (qsdev);if (ret) {
@@ -670,17 +673,18 @@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 ;
@@ -695,10 +699,20 @@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);
@@ -721,9 +735,12 @@if (!qsdev)return ; +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_dev_deinit (qsdev);quickspi_dma_deinit (qsdev);
@@ -749,6 +766,9 @@ qsdev =pci_get_drvdata (pdev);if (!qsdev)return ; + +WRITE_ONCE (qsdev->recovery_disabled, true); +disable_irq (pdev->irq);quickspi_dev_deinit (qsdev);
base-commit: b3dfbde62cf1981c4638939c159dfd087b7a72e9
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 1/2] HID: intel-thc-hid: quickspi: quiesce IRQs during teardown
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] HID: intel-thc-hid: quickspi: broken HID teardown in quickspi_remove() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] HID: intel-thc-hid: quickspi: broken HID teardown in quickspi_remove()
--
commit c5d058390d4d45710eca02a89498e5e65474bafb
Author: Myeonghun Pak <[email protected]>
HID: intel-thc-hid: quickspi: quiesce IRQs during teardown
This commit disables and frees the device IRQ and drains recovery work during probe failure, driver removal, and shutdown before releasing HID and DMA resources.
Quoted 4 lines
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +0
-0
[ ... ]
Quoted 4 lines
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +0
-0@@ -721,9 +735,12 @@ static void quickspi_remove(struct pci_dev *pdev)if (!qsdev)return ;
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c static void quickspi_remove(struct pci_dev *pdev) · line 745
Quoted 10 lines
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +5
-2-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);
[Severity: Medium]
Does moving disable_irq(), quickspi_dev_deinit(), and devm_free_irq() ahead of quickspi_hid_remove() break HID teardown?
When a hid-multitouch input device is open during unbind, quickspi_hid_remove() -> hid_destroy_device() -> ... -> hid_hw_close() -> mt_on_hid_hw_close() -> mt_set_modes() synchronously calls quickspi_hid_raw_request() -> quickspi_set_report() -> write_cmd_to_txdma() -> thc_dma_write(). Because quickspi_hid_raw_request() does not check qsdev->state and THC_TXDMA remains enabled until quickspi_dma_deinit(), thc_dma_write() starts hardware TxDMA and blocks in wait_event_interruptible_timeout(dev->write_complete_wait, ...) waiting for a THC_TXDMA_INT completion interrupt that can no longer arrive. When thc_dma_write() times out or is interrupted by a signal, quickspi_dma_deinit() then unmaps and frees the TxDMA scatterlist and PRD table without clearing THC_M_PRT_WRITE_DMA_CNTRL_THC_WRDMA_START.
Calling quickspi_hid_remove() before disabling the IRQ and deinitializing the controller would avoid starting new transfers after interrupts are disabled.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
RE: [PATCH v3 1/2] HID: intel-thc-hid: quickspi: quiesce IRQs during teardown
In reply to Myeonghun PakQuoted 122 lines
-----Original Message-----
From: Myeonghun Pak <[email protected]>
Sent: Thursday, November 12, 2026 2:38 PM
To: Xu, Even <[email protected]>; Sun, Xinpeng <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: [PATCH v3 1/2] HID: intel-thc-hid: quickspi: quiesce IRQs during teardownThe 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.
Found by a static analysis tool under development.
Fixes 4138f21115ae ("HID: intel-thc-hid: intel-quickspi: Complete THC QuickSPIdriver")
Co-developed-by Ijae Kim <[email protected]>Signed-off-by Ijae Kim <[email protected]>Signed-off-by Myeonghun Pak <[email protected]>---
Changes in v3:
- Add blank lines in the probe error path (Even).drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-)drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +6
-2@@ -600,6 +600,8 @@ const struct pci_device_id *id) {struct quickspi_device *qsdev; +bool dma_initialized = false; +bool irq_requested = false;void __iomem *mem_addr;int ret;@@ -652,6 +654,7 @@ qsdev);if (ret) goto dev_deinit; + irq_requested = true; ret =reset_tic (qsdev);if (ret) {@@ -670,17 +673,18 @@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 +17
-4qsdev->state =QUICKSPI_ENABLED ;@@ -695,10 +699,20 @@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);@@ -721,9 +735,12 @@if (!qsdev)return ; +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_dev_deinit (qsdev);quickspi_dma_deinit (qsdev);
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c line 773
Quoted 8 lines
drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c +3
-0@@ -749,6 +766,9 @@ qsdev =pci_get_drvdata (pdev);if (!qsdev)return ; + +WRITE_ONCE (qsdev->recovery_disabled, true); +disable_irq (pdev->irq);quickspi_dev_deinit (qsdev);
Thanks for the patch!
Quoted 5 lines
base-commit:
b3dfbde62cf1981c4638939c159dfd087b7a72e9--
2.53.0
PATCH v3 2/2 HID: intel-thc-hid: quicki2c: quiesce IRQs during teardown
In reply to Myeonghun PakThe 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.
Found by a static analysis tool under development.
---
Changes in v3:
- Add blank lines in the probe error path (Even).
drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-)
drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c +26 -6
@@ -652,6 +652,8 @@ {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;
@@ -704,6 +706,7 @@ qcdev);if (ret) goto dev_deinit; + irq_requested = true; ret =quicki2c_get_device_descriptor (qcdev);if (ret) {
@@ -722,6 +725,7 @@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)
@@ -742,13 +746,13 @@ 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 ;
@@ -763,10 +767,20 @@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);
@@ -788,9 +802,12 @@if (!qcdev)return ; +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_dev_deinit (qcdev);quicki2c_dma_deinit (qcdev);
@@ -814,6 +831,9 @@ qcdev =pci_get_drvdata (pdev);if (!qcdev)return ; + +WRITE_ONCE (qcdev->recovery_disabled, true); +disable_irq (pdev->irq);quicki2c_dev_deinit (qcdev);
base-commit: b3dfbde62cf1981c4638939c159dfd087b7a72e9
Signature · 1 line
2.53.0
[email protected]
AI reviewRe: [PATCH v3 2/2] HID: intel-thc-hid: quicki2c: quiesce IRQs during teardown
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] HID: intel-thc-hid: quicki2c: premature IRQ/dev teardown in quicki2c_remove() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] HID: intel-thc-hid: quicki2c: premature IRQ/dev teardown in quicki2c_remove()
--
commit cd8b528b30521f872e42d4b36fda65f3e1f39085
Author: Myeonghun Pak <[email protected]>
HID: intel-thc-hid: quicki2c: quiesce IRQs during teardown
This commit disables and frees the device interrupt and deinitializes the controller before tearing down the hid and dma resources during probe unwind, remove, and shutdown.
Quoted 4 lines
drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c +0
-0
[ ... ]
Quoted 4 lines
drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c +0
-0@@ -788,9 +802,12 @@ static void quicki2c_remove(struct pci_dev *pdev)if (!qcdev)return ;
drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c static void quicki2c_remove(struct pci_dev *pdev) · line 812
Quoted 10 lines
drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c +5
-2-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);
[Severity: High]
Does tearing down pdev->irq and calling quicki2c_dev_deinit() before quicki2c_hid_remove() break synchronous transfers issued while hid_destroy_device() disconnects subdrivers and hidraw?
When quicki2c_hid_remove() runs hid_destroy_device(), bound subdrivers such as hid-multitouch close the device (mt_remove() -> hid_hw_stop() -> ... -> hid_hw_close() -> mt_on_hid_hw_close() -> mt_set_modes()) and send synchronous requests through quicki2c_hid_raw_request(). Because quicki2c_set_report() and quicki2c_get_report() rely on pdev->irq via thc_dma_write() and thc_swdma_read() to signal completion on dev->write_complete_wait and dev->swdma_complete_wait, starting those transfers after pdev->irq is disabled and freed stalls each request for its 1-second wait timeout.
On timeout, thc_swdma_read() skips thc_swdma_read_completion(), leaving the software dma engine started when quicki2c_dma_deinit() unmaps and frees the scatterlists and prd tables (as thc_dma_unconfigure() only stops the two receive dma engines):
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c:thc_swdma_read() {
...
ret = thc_swdma_read_start(dev, write_buff, write_len, prd_tbl_len);
if (ret)
goto end;
ret = wait_event_interruptible_timeout(dev->swdma_complete_wait, dev->swdma_done, 1 * HZ);
if (ret <= 0 || !dev->swdma_done) {
dev_err_once(dev->dev, "timeout for waiting SWDMA completion\n");
ret = -ETIMEDOUT;
goto end;
}
...
ret = thc_swdma_read_completion(dev);
...
}In addition, if an in-flight hidraw request in thc_swdma_read() receives its completion interrupt just before disable_irq(), thc_swdma_read_completion() can run after quicki2c_dev_deinit() while quicki2c_hid_remove() drains hidraw, restarting the receive dma engine and unquiescing interrupts right before quicki2c_dma_deinit() frees the dma buffers.
Keeping quicki2c_hid_remove(qcdev) before disabling pdev->irq and calling quicki2c_dev_deinit(qcdev) would let hid teardown finish while interrupts are still active.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
RE: [PATCH v3 2/2] HID: intel-thc-hid: quicki2c: quiesce IRQs during teardown
In reply to Myeonghun PakQuoted 126 lines
-----Original Message-----
From: Myeonghun Pak <[email protected]>
Sent: Thursday, November 12, 2026 2:38 PM
To: Xu, Even <[email protected]>; Sun, Xinpeng <[email protected]>; [email protected]; [email protected]
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]
Subject: [PATCH v3 2/2] HID: intel-thc-hid: quicki2c: quiesce IRQs during teardownThe 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.
Found by a static analysis tool under development.
Fixes 66b59bfce6d9 ("HID: intel-thc-hid: intel-quicki2c: Complete THC QuickI2Cdriver")
Co-developed-by Ijae Kim <[email protected]>Signed-off-by Ijae Kim <[email protected]>Signed-off-by Myeonghun Pak <[email protected]>---
Changes in v3:
- Add blank lines in the probe error path (Even).drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-)drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c +6
-2@@ -652,6 +652,8 @@ {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;@@ -704,6 +706,7 @@ qcdev);if (ret) goto dev_deinit; + irq_requested = true; ret =quicki2c_get_device_descriptor (qcdev);if (ret) {@@ -722,6 +725,7 @@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)@@ -742,13 +746,13 @@ 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; }drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c +17
-4qcdev->state =QUICKI2C_ENABLED ;@@ -763,10 +767,20 @@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);@@ -788,9 +802,12 @@if (!qcdev)return ; +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_dev_deinit (qcdev);quicki2c_dma_deinit (qcdev);
drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c line 838
Quoted 8 lines
drivers/hid/intel-thc-hid/intel-quicki2c/pci-quicki2c.c +3
-0@@ -814,6 +831,9 @@ qcdev =pci_get_drvdata (pdev);if (!qcdev)return ; + +WRITE_ONCE (qcdev->recovery_disabled, true); +disable_irq (pdev->irq);quicki2c_dev_deinit (qcdev);
Thanks for the patch!
Quoted 5 lines
base-commit:
b3dfbde62cf1981c4638939c159dfd087b7a72e9--
2.53.0
Quoted 6 lines · Myeonghun Pak
This resends v2 with the probe cleanup formatting requested by Even. There are no functional changes from v2.
Changes in v3:
- Add blank lines in the probe error paths of both drivers (Even).
Quoted 7 lines
v2: https://lore.kernel.org/all/[email protected]/
No hardware testing.
Myeonghun Pak (2):
HID: intel-thc-hid: quickspi: quiesce IRQs during teardown
HID: intel-thc-hid: quicki2c: quiesce IRQs during teardown
Applied, thanks.
Signature · 2 lines
Jiri Kosina SUSE Labs