Fix checking of iommu_map_sgtable return value
Subsystems (7)
Mikko Perttunen
maintainercover Fix checking of iommu_map_sgtable return value
The return value of iommu_map_sgtable changed from unsigned to signed quite a while ago, but not all callers were updated. Do that.
Each patch is independent of each other. The drm/msm patch additionally changes from WARNing in case of mapping error to returning the error code now available.
Best regards
Mikko
---
Mikko Perttunen (4):
gpu: host1x: Fix iommu_map_sgtable() return value check drm/tegra: Fix iommu_map_sgtable() return value check drm/msm: Fix iommu_map_sgtable() return value check and avoid WARN
media: nvidia: tegra-vde: Fix iommu_map_sgtable() return value check
drivers/gpu/drm/msm/msm_iommu.c | 5 +++-- drivers/gpu/drm/tegra/gem.c | 9 ++++++--- drivers/gpu/host1x/job.c | 10 ++++++---- drivers/media/platform/nvidia/tegra-vde/iommu.c | 9 +++++---- 4 files changed, 20 insertions(+), 13 deletions(-)
---
base-commit: 028ef9c96e96197026887c0f092424679298aae8
change-id: 20260417-iommu_map_sgtable-return-a8d3cd591fbc
Mikko Perttunen
maintainerPATCH 1/4 gpu: host1x: Fix iommu_map_sgtable() return value check
Commit "iommu: return full error code from iommu_map_sg[_atomic]()" changed iommu_map_sgtable() to return an ssize_t and negative values in error cases, rather than a size_t and a zero.
pin_job() also was incorrectly assigning to 'int', which could cause overflows into negative values.
Update pin_job() to correctly check for errors from iommu_map_sgtable.
--- drivers/gpu/host1x/job.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
drivers/gpu/host1x/job.c +6 -4
@@ -235,6 +235,8 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job) }if (host->domain) { +ssize_t map_err; +for_each_sgtable_sg (map->sgt, sg, j) gather_size += sg->length;
@@ -248,11 +250,11 @@ static unsigned int pin_job(struct host1x *host, struct host1x_job *job) goto put; } - err =iommu_map_sgtable (host->domain,iova_dma_addr (&host->iova, alloc), - map->sgt,IOMMU_READ ); -if (err ==0 ) { + map_err =iommu_map_sgtable (host->domain,iova_dma_addr (&host->iova, alloc), + map->sgt,IOMMU_READ ); +if (map_err <0 ) {__free_iova (&host->iova, alloc); - err = -EINVAL ; + err = map_err; goto put; }
Signature · 1 line
2.53.0
Re: [PATCH 1/4] gpu: host1x: Fix iommu_map_sgtable() return value check
Quoted 7 lines · Mikko Perttunen
Commit "iommu: return full error code from iommu_map_sg[_atomic]()" changed
iommu_map_sgtable()to return anssize_tand negative values in error cases, rather than asize_tand a zero.
pin_job()also was incorrectly assigning to 'int', which could cause overflows into negative values.
Quoted 7 lines
Update
pin_job()to correctly check for errors fromiommu_map_sgtable.Fixes ad8f36e4b6b1 ("iommu: return full error code from iommu_map_sg[_atomic]()")Signed-off-by Mikko Perttunen <[email protected]>--- drivers/gpu/host1x/job.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-)
Applied, thanks.
Thierry
Mikko Perttunen
maintainerPATCH 2/4 drm/tegra: Fix iommu_map_sgtable() return value check
In reply to Mikko PerttunenCommit "iommu: return full error code from iommu_map_sg[_atomic]()" changed iommu_map_sgtable() to return an ssize_t and negative values in error cases, rather than a size_t and a zero.
Update tegra_bo_iommu_map() to correctly check for errors from iommu_map_sgtable.
--- drivers/gpu/drm/tegra/gem.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/tegra/gem.c +6 -3
@@ -235,6 +235,7 @@ static const struct host1x_bo_ops tegra_bo_ops = {static int tegra_bo_iommu_map (struct tegra_drm *tegra,struct tegra_bo *bo) {int prot =IOMMU_READ |IOMMU_WRITE ; +ssize_t size;int err;if (bo->mm)
@@ -256,13 +257,15 @@ static int tegra_bo_iommu_map(struct tegra_drm *tegra, struct tegra_bo *bo) bo->iova = bo->mm->start; - bo->size =iommu_map_sgtable (tegra->domain, bo->iova, bo->sgt, prot); -if (!bo->size) { + size =iommu_map_sgtable (tegra->domain, bo->iova, bo->sgt, prot); +if (size <0 ) {dev_err (tegra->drm->dev,"failed to map buffer\n" ); - err = -ENOMEM ; + err = size; goto remove; } + bo->size = size; +mutex_unlock (&tegra->mm_lock);return 0 ;
Signature · 1 line
2.53.0
Re: [PATCH 2/4] drm/tegra: Fix iommu_map_sgtable() return value check
Quoted 4 lines · Mikko Perttunen
Commit "iommu: return full error code from iommu_map_sg[_atomic]()" changed
iommu_map_sgtable()to return anssize_tand negative values in error cases, rather than asize_tand a zero.
Quoted 8 lines
Update
tegra_bo_iommu_map()to correctly check for errors fromiommu_map_sgtable.Fixes ad8f36e4b6b1 ("iommu: return full error code from iommu_map_sg[_atomic]()")Signed-off-by Mikko Perttunen <[email protected]>--- drivers/gpu/drm/tegra/gem.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
Applied, thanks.
Thierry
Mikko Perttunen
maintainerPATCH 3/4 drm/msm: Fix iommu_map_sgtable() return value check and avoid WARN
In reply to Mikko PerttunenCommit "iommu: return full error code from iommu_map_sg[_atomic]()" changed iommu_map_sgtable() to return an ssize_t and negative values in error cases, rather than a size_t and a zero.
Store the return value in the appropriate type and in case of error, return it rather than WARNing.
--- drivers/gpu/drm/msm/msm_iommu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/msm/msm_iommu.c +3 -2
@@ -677,7 +677,7 @@ static int msm_iommu_map(struct msm_mmu *mmu, uint64_t iova, int prot) {struct msm_iommu *iommu =to_msm_iommu (mmu); -size_t ret; +ssize_t ret;WARN_ON (off !=0 );
@@ -686,7 +686,8 @@ static int msm_iommu_map(struct msm_mmu *mmu, uint64_t iova, iova |=GENMASK_ULL (63 ,49 ); ret =iommu_map_sgtable (iommu->domain, iova, sgt, prot); -WARN_ON (!ret); +if (ret <0 ) +return ret;return (ret == len) ?0 : -EINVAL ; }
Signature · 1 line
2.53.0
Mikko Perttunen
maintainerPATCH 4/4 media: nvidia: tegra-vde: Fix iommu_map_sgtable() return value check
In reply to Mikko PerttunenCommit "iommu: return full error code from iommu_map_sg[_atomic]()" changed iommu_map_sgtable() to return an ssize_t and negative values in error cases, rather than a size_t and a zero.
Update tegra_vde_iommu_map() to correctly check for errors from iommu_map_sgtable.
--- drivers/media/platform/nvidia/tegra-vde/iommu.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
drivers/media/platform/nvidia/tegra-vde/iommu.c +5 -4
@@ -25,6 +25,7 @@ int tegra_vde_iommu_map(struct tegra_vde *vde,unsigned long shift;unsigned long end;dma_addr_t addr; +ssize_t map_err; end = vde->domain->geometry.aperture_end; size =iova_align (&vde->iova, size);
@@ -36,11 +37,11 @@ int tegra_vde_iommu_map(struct tegra_vde *vde, addr =iova_dma_addr (&vde->iova, iova); - size =iommu_map_sgtable (vde->domain, addr, sgt, -IOMMU_READ |IOMMU_WRITE ); -if (!size) { + map_err =iommu_map_sgtable (vde->domain, addr, sgt, +IOMMU_READ |IOMMU_WRITE ); +if (map_err <0 ) {__free_iova (&vde->iova, iova); -return -ENXIO ; +return map_err; } *iovap = iova;
Signature · 1 line
2.53.0
Re: [PATCH 4/4] media: nvidia: tegra-vde: Fix iommu_map_sgtable() return value check
21.04.2026 07:02, Mikko Perttunen пишет:
Quoted 32 lines
Commit "iommu: return full error code from iommu_map_sg[_atomic]()" changed
iommu_map_sgtable()to return anssize_tand negative values in error cases, rather than asize_tand a zero.Update
tegra_vde_iommu_map()to correctly check for errors fromiommu_map_sgtable.Fixes ad8f36e4b6b1 ("iommu: return full error code from iommu_map_sg[_atomic]()")Signed-off-by Mikko Perttunen <[email protected]>--- drivers/media/platform/nvidia/tegra-vde/iommu.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)drivers/media/platform/nvidia/tegra-vde/iommu.c +1
-2@@ -25,6 +25,7 @@ int tegra_vde_iommu_map(struct tegra_vde *vde,unsigned long shift;unsigned long end;dma_addr_t addr; +ssize_t map_err; end = vde->domain->geometry.aperture_end; size =iova_align (&vde->iova, size);@@ -36,11 +37,11 @@ int tegra_vde_iommu_map(struct tegra_vde *vde, addr =iova_dma_addr (&vde->iova, iova); - size =iommu_map_sgtable (vde->domain, addr, sgt, -IOMMU_READ |IOMMU_WRITE );
drivers/media/platform/nvidia/tegra-vde/iommu.c int tegra_vde_iommu_map(struct tegra_vde *vde, · line 47
Quoted 10 lines
drivers/media/platform/nvidia/tegra-vde/iommu.c +4
-2-if (!size) { + map_err =iommu_map_sgtable (vde->domain, addr, sgt, +IOMMU_READ |IOMMU_WRITE ); +if (map_err <0 ) {__free_iova (&vde->iova, iova); -return -ENXIO ; +return map_err; } *iovap = iova;