* [PATCH] HID: Intel-thc-hid: Intel-thc: fix dma_unmap_sg() nents value
@ 2025-12-03 16:56 Thomas Fourier
2025-12-03 17:02 ` Andy Shevchenko
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Thomas Fourier @ 2025-12-03 16:56 UTC (permalink / raw)
Cc: Thomas Fourier, Even Xu, Xinpeng Sun, Jiri Kosina,
Benjamin Tissoires, Andy Shevchenko, Mark Pearson,
Srinivas Pandruvada, linux-input, linux-kernel
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>
---
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c | 4 +++-
drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.h | 2 ++
2 files changed, 5 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 82b8854843e0..a0c368aa7979 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
@@ -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]);
diff --git a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.h b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.h
index 78917400492c..541d33995baf 100644
--- a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.h
+++ b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.h
@@ -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;
--
2.43.0
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] HID: Intel-thc-hid: Intel-thc: fix dma_unmap_sg() nents value
2025-12-03 16:56 [PATCH] HID: Intel-thc-hid: Intel-thc: fix dma_unmap_sg() nents value Thomas Fourier
@ 2025-12-03 17:02 ` Andy Shevchenko
2025-12-04 1:09 ` Xu, Even
2025-12-19 13:05 ` Benjamin Tissoires
2 siblings, 0 replies; 4+ messages in thread
From: Andy Shevchenko @ 2025-12-03 17:02 UTC (permalink / raw)
To: Thomas Fourier
Cc: Even Xu, Xinpeng Sun, Jiri Kosina, Benjamin Tissoires,
Mark Pearson, Srinivas Pandruvada, linux-input, linux-kernel
On Wed, Dec 03, 2025 at 05:56:35PM +0100, Thomas Fourier wrote:
> 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.
Your email has an empty To:. Some spamfilters may be triggered by this.
I recommend to use `b4` tool to handle the patches.
The change LGTM,
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH] HID: Intel-thc-hid: Intel-thc: fix dma_unmap_sg() nents value
2025-12-03 16:56 [PATCH] HID: Intel-thc-hid: Intel-thc: fix dma_unmap_sg() nents value Thomas Fourier
2025-12-03 17:02 ` Andy Shevchenko
@ 2025-12-04 1:09 ` Xu, Even
2025-12-19 13:05 ` Benjamin Tissoires
2 siblings, 0 replies; 4+ messages in thread
From: Xu, Even @ 2025-12-04 1:09 UTC (permalink / raw)
To: Thomas Fourier
Cc: Sun, Xinpeng, Jiri Kosina, Benjamin Tissoires, Andy Shevchenko,
Mark Pearson, Srinivas Pandruvada, linux-input@vger.kernel.org,
linux-kernel@vger.kernel.org
> -----Original Message-----
> From: Thomas Fourier <fourier.thomas@gmail.com>
> Sent: Thursday, December 4, 2025 12:57 AM
> Cc: Thomas Fourier <fourier.thomas@gmail.com>; Xu, Even
> <even.xu@intel.com>; Sun, Xinpeng <xinpeng.sun@intel.com>; Jiri Kosina
> <jikos@kernel.org>; Benjamin Tissoires <bentiss@kernel.org>; Andy Shevchenko
> <andriy.shevchenko@linux.intel.com>; Mark Pearson <mpearson-
> lenovo@squebb.ca>; Srinivas Pandruvada
> <srinivas.pandruvada@linux.intel.com>; linux-input@vger.kernel.org; linux-
> kernel@vger.kernel.org
> Subject: [PATCH] HID: Intel-thc-hid: Intel-thc: fix dma_unmap_sg() nents value
>
> 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>
Thanks for the fix!
Looks good to me.
Reviewed-by: Even Xu <even.xu@intel.com>
> ---
> drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.c | 4 +++- drivers/hid/intel-thc-
> hid/intel-thc/intel-thc-dma.h | 2 ++
> 2 files changed, 5 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 82b8854843e0..a0c368aa7979 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
> @@ -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]);
> diff --git a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.h b/drivers/hid/intel-
> thc-hid/intel-thc/intel-thc-dma.h
> index 78917400492c..541d33995baf 100644
> --- a/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.h
> +++ b/drivers/hid/intel-thc-hid/intel-thc/intel-thc-dma.h
> @@ -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;
>
> --
> 2.43.0
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] HID: Intel-thc-hid: Intel-thc: fix dma_unmap_sg() nents value
2025-12-03 16:56 [PATCH] HID: Intel-thc-hid: Intel-thc: fix dma_unmap_sg() nents value Thomas Fourier
2025-12-03 17:02 ` Andy Shevchenko
2025-12-04 1:09 ` Xu, Even
@ 2025-12-19 13:05 ` Benjamin Tissoires
2 siblings, 0 replies; 4+ messages in thread
From: Benjamin Tissoires @ 2025-12-19 13:05 UTC (permalink / raw)
To: Thomas Fourier
Cc: Even Xu, Xinpeng Sun, Jiri Kosina, Andy Shevchenko, Mark Pearson,
Srinivas Pandruvada, linux-input, linux-kernel
On Wed, 03 Dec 2025 17:56:35 +0100, Thomas Fourier wrote:
> 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.
>
>
Applied to hid/hid.git (for-6.19/upstream-fixes), thanks!
[1/1] HID: Intel-thc-hid: Intel-thc: fix dma_unmap_sg() nents value
https://git.kernel.org/hid/hid/c/0e13150c1a13
Cheers,
--
Benjamin Tissoires <bentiss@kernel.org>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-12-19 13:06 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-03 16:56 [PATCH] HID: Intel-thc-hid: Intel-thc: fix dma_unmap_sg() nents value Thomas Fourier
2025-12-03 17:02 ` Andy Shevchenko
2025-12-04 1:09 ` Xu, Even
2025-12-19 13:05 ` Benjamin Tissoires
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox