git: 091ca09a0a66 - stable/15 - LinuxKPI: Correct nents passed to dma_{un,}map_sg_attrs()

From: Bjoern A. Zeeb <bz_at_FreeBSD.org>
Date: Thu, 10 Sep 2026 09:48:44 UTC
The branch stable/15 has been updated by bz:

URL: https://cgit.FreeBSD.org/src/commit/?id=091ca09a0a66f16f793c5e1bbe7e96498f07d737

commit 091ca09a0a66f16f793c5e1bbe7e96498f07d737
Author:     Zishun Yi <zis@FreeBSD.org>
AuthorDate: 2026-09-05 20:12:38 +0000
Commit:     Bjoern A. Zeeb <bz@FreeBSD.org>
CommitDate: 2026-09-10 09:46:54 +0000

    LinuxKPI: Correct nents passed to dma_{un,}map_sg_attrs()
    
    According to Linux documentation the nents argument to dma_unmap_sg()
    must be the number one passed in, not the number of DMA addresses.
    
    In LinuxKPI this means orig_nents and not nents, so adjust this.
    
    Given nents and orig_nents should always be the same in LinuxKPI,
    this should only be a NOP for correctness.
    
    Reviewed by:    bz, aokblast (LGTM)
    Differential Revision: https://reviews.freebsd.org/D57842
    
    (cherry picked from commit 33574d47d9dea317b9a4bfe543c4f20be6a565ef)
---
 sys/compat/linuxkpi/common/include/linux/dma-mapping.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sys/compat/linuxkpi/common/include/linux/dma-mapping.h b/sys/compat/linuxkpi/common/include/linux/dma-mapping.h
index f26bb0e6eb99..173b3e8d3c96 100644
--- a/sys/compat/linuxkpi/common/include/linux/dma-mapping.h
+++ b/sys/compat/linuxkpi/common/include/linux/dma-mapping.h
@@ -431,7 +431,7 @@ dma_map_sgtable(struct device *dev, struct sg_table *sgt,
 {
 	int nents;
 
-	nents = dma_map_sg_attrs(dev, sgt->sgl, sgt->nents, dir, attrs);
+	nents = dma_map_sg_attrs(dev, sgt->sgl, sgt->orig_nents, dir, attrs);
 	if (nents < 0)
 		return (nents);
 	sgt->nents = nents;
@@ -444,7 +444,7 @@ dma_unmap_sgtable(struct device *dev, struct sg_table *sgt,
     unsigned long attrs)
 {
 
-	dma_unmap_sg_attrs(dev, sgt->sgl, sgt->nents, dir, attrs);
+	dma_unmap_sg_attrs(dev, sgt->sgl, sgt->orig_nents, dir, attrs);
 }