]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
HID: Intel-thc-hid: Intel-thc: fix dma_unmap_sg() nents value
authorThomas Fourier <fourier.thomas@gmail.com>
Wed, 3 Dec 2025 16:56:35 +0000 (17:56 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 17 Jan 2026 15:35:19 +0000 (16:35 +0100)
[ Upstream commit 0e13150c1a13a3a3d6184c24bfd080d5999945d1 ]

The `dma_unmap_sg()` functions should be called with the same nents as the
`dma_map_sg()`, not the value the map function returned.

Save the number of entries in struct thc_dma_configuration.

Fixes: a688404b2e20 ("HID: intel-thc-hid: intel-thc: Add THC DMA interfaces")
Signed-off-by: Thomas Fourier <fourier.thomas@gmail.com>
Reviewed-by: Even Xu <even.xu@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Benjamin Tissoires <bentiss@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.h

index 82b8854843e052e4a5eb4b437a59f6c030041346..a0c368aa7979c44a743d59967854aefda46ebb96 100644 (file)
@@ -232,6 +232,7 @@ static int setup_dma_buffers(struct thc_device *dev,
                return 0;
 
        memset(config->sgls, 0, sizeof(config->sgls));
+       memset(config->sgls_nent_pages, 0, sizeof(config->sgls_nent_pages));
        memset(config->sgls_nent, 0, sizeof(config->sgls_nent));
 
        cpu_addr = dma_alloc_coherent(dev->dev, prd_tbls_size,
@@ -254,6 +255,7 @@ static int setup_dma_buffers(struct thc_device *dev,
                }
                count = dma_map_sg(dev->dev, config->sgls[i], nent, dir);
 
+               config->sgls_nent_pages[i] = nent;
                config->sgls_nent[i] = count;
        }
 
@@ -299,7 +301,7 @@ static void release_dma_buffers(struct thc_device *dev,
                        continue;
 
                dma_unmap_sg(dev->dev, config->sgls[i],
-                            config->sgls_nent[i],
+                            config->sgls_nent_pages[i],
                             config->dir);
 
                sgl_free(config->sgls[i]);
index 78917400492caf314e36f2f1d738f4ef47039697..541d33995baf360fcd6effa74befc3a07bd6971a 100644 (file)
@@ -91,6 +91,7 @@ struct thc_prd_table {
  * @dir: Direction of DMA for this config
  * @prd_tbls: PRD tables for current DMA
  * @sgls: Array of pointers to scatter-gather lists
+ * @sgls_nent_pages: Number of pages per scatter-gather list
  * @sgls_nent: Actual number of entries per scatter-gather list
  * @prd_tbl_num: Actual number of PRD tables
  * @max_packet_size: Size of the buffer needed for 1 DMA message (1 PRD table)
@@ -107,6 +108,7 @@ struct thc_dma_configuration {
 
        struct thc_prd_table *prd_tbls;
        struct scatterlist *sgls[PRD_TABLES_NUM];
+       u8 sgls_nent_pages[PRD_TABLES_NUM];
        u8 sgls_nent[PRD_TABLES_NUM];
        u8 prd_tbl_num;