[PATCH] dma-debug: fix physical address retrieval in debug_dma_sync_sg_for_device

lirongqing posted 1 patch 4 days, 17 hours ago
kernel/dma/debug.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] dma-debug: fix physical address retrieval in debug_dma_sync_sg_for_device
Posted by lirongqing 4 days, 17 hours ago
From: Li RongQing <lirongqing@baidu.com>

In debug_dma_sync_sg_for_device(), when iterating over a scatterlist,
the debug entry population mistakenly uses the head of the scatterlist
'sg' to fetch the physical address via sg_phys(), instead of using the
current iterator variable 's'.

This causes dma-debug to track the physical address of the very first
scatterlist entry for all subsequent entries in the list.

Fix this by passing the correct loop iterator 's' to sg_phys()

Fixes: 9d4f645a1fd49ee ("dma-debug: store a phys_addr_t in struct dma_debug_entry")
Signed-off-by: Li RongQing <lirongqing@baidu.com>
---
 kernel/dma/debug.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c
index 3248f8b..2c0e2cd 100644
--- a/kernel/dma/debug.c
+++ b/kernel/dma/debug.c
@@ -1556,7 +1556,7 @@ void debug_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
 		struct dma_debug_entry ref = {
 			.type           = dma_debug_sg,
 			.dev            = dev,
-			.paddr		= sg_phys(sg),
+			.paddr		= sg_phys(s),
 			.dev_addr       = sg_dma_address(s),
 			.size           = sg_dma_len(s),
 			.direction      = direction,
-- 
2.9.4
Re: [PATCH] dma-debug: fix physical address retrieval in debug_dma_sync_sg_for_device
Posted by Marek Szyprowski 4 days, 14 hours ago
On 03.06.2026 14:37, lirongqing wrote:
> From: Li RongQing <lirongqing@baidu.com>
>
> In debug_dma_sync_sg_for_device(), when iterating over a scatterlist,
> the debug entry population mistakenly uses the head of the scatterlist
> 'sg' to fetch the physical address via sg_phys(), instead of using the
> current iterator variable 's'.
>
> This causes dma-debug to track the physical address of the very first
> scatterlist entry for all subsequent entries in the list.
>
> Fix this by passing the correct loop iterator 's' to sg_phys()
>
> Fixes: 9d4f645a1fd49ee ("dma-debug: store a phys_addr_t in struct dma_debug_entry")
> Signed-off-by: Li RongQing <lirongqing@baidu.com>

Nice catch! Applied to dma-mapping-fixes, thanks!


> ---
>  kernel/dma/debug.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/kernel/dma/debug.c b/kernel/dma/debug.c
> index 3248f8b..2c0e2cd 100644
> --- a/kernel/dma/debug.c
> +++ b/kernel/dma/debug.c
> @@ -1556,7 +1556,7 @@ void debug_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg,
>  		struct dma_debug_entry ref = {
>  			.type           = dma_debug_sg,
>  			.dev            = dev,
> -			.paddr		= sg_phys(sg),
> +			.paddr		= sg_phys(s),
>  			.dev_addr       = sg_dma_address(s),
>  			.size           = sg_dma_len(s),
>  			.direction      = direction,

Best regards
-- 
Marek Szyprowski, PhD
Samsung R&D Institute Poland