From 08c8a9a5283802b531153c154cc89fbf9f03c708 Mon Sep 17 00:00:00 2001 From: technosf <535060+technosf@users.noreply.github.com> Date: Mon, 2 Nov 2026 16:39:19 -0800 Subject: [PATCH] HID: intel-thc-hid: intel-thc: Use page count when copying read DMA buffer sg_copy_to_buffer() walks the CPU-side scatterlist, so it needs the number of pages passed to dma_map_sg(), not the number of mapped entries that calc_message_len() derives from the PRD table. With an IOMMU, dma_map_sg() can merge pages, so the PRD table holds fewer entries than the scatterlist has pages. The copy then stops early (e.g. "Copied 4096 bytes instead of requested 7492") and the read fails with -EIO, which leaves the touch controller stuck when a stylus sends large reports. Use the page count stored in sgls_nent_pages[] instead. Fixes: a688404b2e20 ("HID: intel-thc-hid: intel-thc: Add THC DMA interfaces") Link: https://github.com/linux-surface/linux-surface/issues/2261 Patchset: intel-thc Signed-off-by: technosf <535060+technosf@users.noreply.github.com> --- drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 6ee675e0a738..0db38a93790f 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 @@ -590,7 +590,8 @@ static int read_dma_buffer(struct thc_device *dev, } sg = read_config->sgls[prd_table_index]; - ret = sg_copy_to_buffer(sg, nent, read_buff, mes_len); + ret = sg_copy_to_buffer(sg, read_config->sgls_nent_pages[prd_table_index], + read_buff, mes_len); if (ret != mes_len) { dev_err_once(dev->dev, "Copied %zu bytes instead of requested %zu\n", ret, mes_len);