iommu/dma: Fix check for error return from iommu_map_sg_atomic()
Subsystems (2)
PATCH 1/1 iommu/dma: Fix check for error return from iommu_map_sg_atomic()
In __iommu_dma_alloc_noncontiguous() the value returned by iommu_map_sg_atomic() is checked for being smaller than size. Before commit ad8f36e4b6b1 ("iommu: return full error code from iommu_map_sg[_atomic]()") this simply checked if the requested size was successfully mapped.
After that commit iommu_map_sg_atomic() may also return a negative error value. In principle this too would be covered by the existing check. There is one problem however, as size is of type size_t while the return type of iommu_map_sg_atomic() is now of type ssize_t the latter gets converted to size_t and negative error values end up as very large positive values making the check succeed. Fix this by making the return type visible with a local variable and add an explicit cast to ssize_t.
--- drivers/iommu/dma-iommu.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/iommu/dma-iommu.c +3 -2
@@ -776,6 +776,7 @@ static struct page **__iommu_dma_alloc_noncontiguous(struct device *dev,unsigned int count, min_size, alloc_sizes = domain->pgsize_bitmap;struct page **pages;dma_addr_t iova; +ssize_t mapped;if (static_branch_unlikely (&iommu_deferred_attach_enabled) &&iommu_deferred_attach (dev, domain))
@@ -813,8 +814,8 @@ static struct page **__iommu_dma_alloc_noncontiguous(struct device *dev,arch_dma_prep_coherent (sg_page (sg), sg->length); } -if (iommu_map_sg_atomic (domain, iova, sgt->sgl, sgt->orig_nents, ioprot) - < size) + mapped =iommu_map_sg_atomic (domain, iova, sgt->sgl, sgt->orig_nents, ioprot); +if (mapped < (ssize_t )size) goto out_free_sg; sgt->sgl->dma_address = iova;
Signature · 6 lines
2.32.0 _______________________________________________ iommu mailing list [email protected] https://lists.linuxfoundation.org/mailman/listinfo/iommu
Quoted 14 lines · Niklas Schnelle
In
__iommu_dma_alloc_noncontiguous()the value returned byiommu_map_sg_atomic()is checked for being smaller than size. Before commitad8f36e4b6b1("iommu: return full error code from iommu_map_sg[_atomic]()") this simply checked if the requested size was successfully mapped.After that commit
iommu_map_sg_atomic()may also return a negative error value. In principle this too would be covered by the existing check. There is one problem however, as size is of typesize_twhile the return type ofiommu_map_sg_atomic()is now of typessize_tthe latter gets converted tosize_tand negative error values end up as very large positive values making the check succeed. Fix this by making the return type visible with a local variable and add an explicit cast tossize_t.
Quoted 3 lines
Fixes ad8f36e4b6b1 ("iommu: return full error code from iommu_map_sg[_atomic]()")Signed-off-by Niklas Schnelle <[email protected]>
I don't see what the point of the newly added local variable is here. Just casting size should be all that is needed as far as I can tell.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Quoted 15 lines · Christoph Hellwig
Quoted 14 lines · Niklas Schnelle
In
__iommu_dma_alloc_noncontiguous()the value returned byiommu_map_sg_atomic()is checked for being smaller than size. Before commitad8f36e4b6b1("iommu: return full error code from iommu_map_sg[_atomic]()") this simply checked if the requested size was successfully mapped.After that commit
iommu_map_sg_atomic()may also return a negative error value. In principle this too would be covered by the existing check. There is one problem however, as size is of typesize_twhile the return type ofiommu_map_sg_atomic()is now of typessize_tthe latter gets converted tosize_tand negative error values end up as very large positive values making the check succeed. Fix this by making the return type visible with a local variable and add an explicit cast tossize_t.
Quoted 6 lines
Quoted 3 lines
Fixes ad8f36e4b6b1 ("iommu: return full error code from iommu_map_sg[_atomic]()")Signed-off-by Niklas Schnelle <[email protected]>I don't see what the point of the newly added local variable is here. Just casting size should be all that is needed as far as I can tell.
No technical reason just found it easier to read and more descriptive. I'll sent a v2 with just the cast, it does simplify the commit message.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Robin Murphy
maintainerQuoted 20 lines · Niklas Schnelle
Quoted 19 lines · Christoph Hellwig
Quoted 17 lines · Niklas Schnelle
In
__iommu_dma_alloc_noncontiguous()the value returned byiommu_map_sg_atomic()is checked for being smaller than size. Before commitad8f36e4b6b1("iommu: return full error code from iommu_map_sg[_atomic]()") this simply checked if the requested size was successfully mapped.After that commit
iommu_map_sg_atomic()may also return a negative error value. In principle this too would be covered by the existing check. There is one problem however, as size is of typesize_twhile the return type ofiommu_map_sg_atomic()is now of typessize_tthe latter gets converted tosize_tand negative error values end up as very large positive values making the check succeed. Fix this by making the return type visible with a local variable and add an explicit cast tossize_t.Fixes ad8f36e4b6b1 ("iommu: return full error code from iommu_map_sg[_atomic]()")Signed-off-by Niklas Schnelle <[email protected]>
Quoted 5 lines
Quoted 2 lines
I don't see what the point of the newly added local variable is here. Just casting size should be all that is needed as far as I can tell.
No technical reason just found it easier to read and more descriptive. I'll sent a v2 with just the cast, it does simplify the commit message.
Note that this is already fixed upstream, though:
Robin.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu
Quoted 24 lines · Robin Murphy
Quoted 23 lines · Niklas Schnelle
Quoted 21 lines · Christoph Hellwig
Quoted 14 lines · Niklas Schnelle
In
__iommu_dma_alloc_noncontiguous()the value returned byiommu_map_sg_atomic()is checked for being smaller than size. Before commitad8f36e4b6b1("iommu: return full error code from iommu_map_sg[_atomic]()") this simply checked if the requested size was successfully mapped.After that commit
iommu_map_sg_atomic()may also return a negative error value. In principle this too would be covered by the existing check. There is one problem however, as size is of typesize_twhile the return type ofiommu_map_sg_atomic()is now of typessize_tthe latter gets converted tosize_tand negative error values end up as very large positive values making the check succeed. Fix this by making the return type visible with a local variable and add an explicit cast tossize_t.Quoted 3 lines
Fixes ad8f36e4b6b1 ("iommu: return full error code from iommu_map_sg[_atomic]()")Signed-off-by Niklas Schnelle <[email protected]>I don't see what the point of the newly added local variable is here. Just casting size should be all that is needed as far as I can tell.
Quoted 8 lines
Quoted 2 lines
No technical reason just found it easier to read and more descriptive. I'll sent a v2 with just the cast, it does simplify the commit message.
Note that this is already fixed upstream, though:
Robin.
Ah oh well then nevermind and you can of course also ignore the v2 I sent out a minute ago.
_______________________________________________
iommu mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/iommu