[PATCH 2/4] HID: Intel-thc-hid: Intel-quickspi: Use safe RXDMA reads
From: Even Xu
Date: Mon Nov 16 2026 - 03:27:34 EST
Use thc_rxdma_read_safe() and pass the full input_buf allocation,
including the body header. Handle -EMSGSIZE in the receive loop by
skipping the discarded frame and continuing pending reports instead
of scheduling a full RXDMA recovery.
Fixes: 4138f21115ae ("HID: intel-thc-hid: intel-quickspi: Complete THC QuickSPI driver")
Signed-off-by: Even Xu <even.xu@xxxxxxxxx>
Tested-by: Rui Zhang <rui1.zhang@xxxxxxxxx>
---
.../hid/intel-thc-hid/intel-quickspi/pci-quickspi.c | 12 ++++++++----
.../hid/intel-thc-hid/intel-quickspi/quickspi-dev.h | 7 +++++++
2 files changed, 15 insertions(+), 4 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 ec974d549a92..703ba238c02a 100644
--- a/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c
+++ b/drivers/hid/intel-thc-hid/intel-quickspi/pci-quickspi.c
@@ -324,8 +324,12 @@ static irqreturn_t quickspi_irq_thread_handler(int irq, void *dev_id)
if (int_mask & BIT(THC_RXDMA2_INT)) {
while (!read_finished) {
- ret = thc_rxdma_read(qsdev->thc_hw, THC_RXDMA2, qsdev->input_buf,
- &input_len, &read_finished);
+ ret = thc_rxdma_read_safe(qsdev->thc_hw, THC_RXDMA2, qsdev->input_buf,
+ HIDSPI_INPUT_BODY_SIZE(qsdev->input_len),
+ &input_len, &read_finished);
+ if (ret == -EMSGSIZE)
+ continue;
+
if (ret) {
err_recover = 1;
goto end;
@@ -550,7 +554,7 @@ static int quickspi_alloc_report_buf(struct quickspi_device *qsdev)
return -ENOMEM;
max_input_len = max(le16_to_cpu(qsdev->dev_desc.rep_desc_len),
- le16_to_cpu(qsdev->dev_desc.max_input_len));
+ le16_to_cpu(qsdev->dev_desc.max_input_len)) + QUICKSPI_DMA_EXTRA_BYTE;
qsdev->input_buf = devm_kzalloc(qsdev->dev,
HIDSPI_INPUT_BODY_SIZE(max_input_len), GFP_KERNEL);
@@ -560,7 +564,7 @@ static int quickspi_alloc_report_buf(struct quickspi_device *qsdev)
qsdev->input_len = max_input_len;
max_report_len = max(le16_to_cpu(qsdev->dev_desc.max_output_len),
- le16_to_cpu(qsdev->dev_desc.max_input_len));
+ le16_to_cpu(qsdev->dev_desc.max_input_len)) + QUICKSPI_DMA_EXTRA_BYTE;
qsdev->report_buf = devm_kzalloc(qsdev->dev,
HIDSPI_OUTPUT_REPORT_SIZE(max_report_len), GFP_KERNEL);
diff --git a/drivers/hid/intel-thc-hid/intel-quickspi/quickspi-dev.h b/drivers/hid/intel-thc-hid/intel-quickspi/quickspi-dev.h
index 4362ac568bda..e8ddb504ccc7 100644
--- a/drivers/hid/intel-thc-hid/intel-quickspi/quickspi-dev.h
+++ b/drivers/hid/intel-thc-hid/intel-quickspi/quickspi-dev.h
@@ -54,6 +54,13 @@
#define MAX_PACKET_SIZE_VALUE_MTL 128
#define MAX_PACKET_SIZE_VALUE_LNL 256
+/*
+ * During HID-over-SPI transfers, THC DMA may also read bytes that aren’t
+ * part of the actual data, such as a placeholder byte used for timing
+ * control (8 clock cycles).
+ */
+#define QUICKSPI_DMA_EXTRA_BYTE 1
+
/*
* THC uses runtime auto suspend to dynamically switch between THC active LTR
* and low power LTR to save CPU power.
--
2.43.0