]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
accel/amdxdna: Fix iommu_map_sgtable() return value handling
authorLizhi Hou <lizhi.hou@amd.com>
Mon, 13 Apr 2026 18:02:38 +0000 (11:02 -0700)
committerLizhi Hou <lizhi.hou@amd.com>
Tue, 14 Apr 2026 16:10:47 +0000 (09:10 -0700)
iommu_map_sgtable() returns negative error codes on failure, but the
result is stored in an unsigned variable. This prevents proper error
detection.

Change the variable type to ssize_t so negative error values can be
handled correctly.

Fixes: ece3e8980907 ("accel/amdxdna: Allow forcing IOVA-based DMA via module parameter")
Reported-by: Dan Carpenter <error27@gmail.com>
Closes: https://lore.kernel.org/all/adk7kOUBwIyYnX1M@stanley.mountain/
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
Signed-off-by: Wendy Liang <wendy.liang@amd.com>
Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
Link: https://patch.msgid.link/20260413180238.668441-1-lizhi.hou@amd.com
drivers/accel/amdxdna/amdxdna_iommu.c

index 4626434d4180cf46cb2f2e613863a541fe788af7..2676cfcfabee0d22dccb78c56332da158a304e1b 100644 (file)
@@ -40,7 +40,7 @@ int amdxdna_iommu_map_bo(struct amdxdna_dev *xdna, struct amdxdna_gem_obj *abo)
        struct sg_table *sgt;
        dma_addr_t dma_addr;
        struct iova *iova;
-       size_t size;
+       ssize_t size;
 
        if (abo->type != AMDXDNA_BO_DEV_HEAP && abo->type != AMDXDNA_BO_SHMEM)
                return 0;
@@ -65,7 +65,14 @@ int amdxdna_iommu_map_bo(struct amdxdna_dev *xdna, struct amdxdna_gem_obj *abo)
 
        size = iommu_map_sgtable(xdna->domain, dma_addr, sgt,
                                 IOMMU_READ | IOMMU_WRITE);
+       if (size < 0) {
+               XDNA_ERR(xdna, "iommu_map_sgtable failed: %zd", size);
+               __free_iova(&xdna->iovad, iova);
+               return size;
+       }
+
        if (size < abo->mem.size) {
+               iommu_unmap(xdna->domain, dma_addr, size);
                __free_iova(&xdna->iovad, iova);
                return -ENXIO;
        }