[PATCH v2 1/5] HID: intel-thc-hid: intel-thc: keep TxDMA write errors

From: Emfox Zhou

Date: Wed Nov 18 2026 - 00:32:23 EST


thc_dma_write() reports success after a timeout: the cleanup at the end
overwrites the error with the result of thc_interrupt_quiesce(), so a
frame that never left the device is taken as sent.

That wait also ends on a signal, and the no-completion branch folds the
result into -ETIMEDOUT. There is nothing to restart here: the frame is
already in the engine, so a restarted write() would hand the same report
to the controller twice. Wait without interruption, the window is one
second, and report a failing interrupt restore instead of dropping it.

The completion interrupt wakes the queue with wake_up_interruptible(),
whose mask does not intersect TASK_UNINTERRUPTIBLE: a completion that
arrives after the task sleeps is dropped, and the write waits out its
timer with the bus lock held. Wake all waiters instead.

Fixes: a688404b2e20 ("HID: intel-thc-hid: intel-thc: Add THC DMA interfaces")
Signed-off-by: Emfox Zhou <emfox@xxxxxxxxxx>
---
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c | 2 +-
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c | 9 +++++----
2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c
index 7feda4160..7429f851c 100644
--- a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c
+++ b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dev.c
@@ -990,7 +990,7 @@ int thc_interrupt_handler(struct thc_device *dev)
THC_M_PRT_WRITE_INT_STS_OFFSET, write_sts);

dev->write_done = true;
- wake_up_interruptible(&dev->write_complete_wait);
+ wake_up(&dev->write_complete_wait);

interrupt_type |= BIT(THC_TXDMA_INT);
}
diff --git a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c
index c80ef8c20..c0dc44e26 100644
--- a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c
+++ b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c
@@ -1045,8 +1045,9 @@ int thc_dma_write(struct thc_device *dev, void *buffer, size_t buf_len)

dma_set_start_bit(dev, &dev->dma_ctx->dma_config[THC_TXDMA]);

- ret = wait_event_interruptible_timeout(dev->write_complete_wait, dev->write_done, 1 * HZ);
- if (ret <= 0 || !dev->write_done) {
+ ret = wait_event_timeout(dev->write_complete_wait,
+ dev->write_done, 1 * HZ);
+ if (!ret || !dev->write_done) {
dev_err_once(dev->dev, "timeout for waiting TxDMA completion\n");
ret = -ETIMEDOUT;
goto end;
@@ -1059,8 +1060,8 @@ int thc_dma_write(struct thc_device *dev, void *buffer, size_t buf_len)
end:
mutex_unlock(&dev->thc_bus_lock);

- if (restore_interrupts)
- ret = thc_interrupt_quiesce(dev, false);
+ if (restore_interrupts && thc_interrupt_quiesce(dev, false))
+ dev_err(dev->dev, "failed to restore interrupts after TxDMA write\n");

return ret;
}