[PATCH] iommufd/selftest: Fix wrong return value in iommufd_test_dmabuf_get()

Yi Lai posted 1 patch 3 weeks, 2 days ago
drivers/iommu/iommufd/selftest.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
[PATCH] iommufd/selftest: Fix wrong return value in iommufd_test_dmabuf_get()
Posted by Yi Lai 3 weeks, 2 days ago
Commit dba4254e216d ("iommufd/selftest: Fix dmabuf leak in
iommufd_test_dmabuf_get()") broke the success path: it changed the
function to always "return 0" instead of returning the fd produced
by dma_buf_fd().

Userspace obtains the dmabuf fd from the ioctl() return value, so every
successful IOMMU_TEST_OP_DMABUF_GET now reports fd 0 instead of the real
fd, causing iommufd selftests to fail, such as:
  not ok 67 iommufd_ioas.mock_domain.dmabuf_simple
  not ok 94 iommufd_ioas.two_mock_domain.dmabuf_simple

Fix by returning rc unconditionally: on error it is the negative
errno from dma_buf_fd(), and on success it is the valid dmabuf fd.

Fixes: dba4254e216d ("iommufd/selftest: Fix dmabuf leak in iommufd_test_dmabuf_get()")
Signed-off-by: Yi Lai <yi1.lai@intel.com>
---
 drivers/iommu/iommufd/selftest.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/iommu/iommufd/selftest.c b/drivers/iommu/iommufd/selftest.c
index ee706f18f7e9..f6da927461b5 100644
--- a/drivers/iommu/iommufd/selftest.c
+++ b/drivers/iommu/iommufd/selftest.c
@@ -2056,11 +2056,9 @@ static int iommufd_test_dmabuf_get(struct iommufd_ucmd *ucmd,
 	}
 
 	rc = dma_buf_fd(dmabuf, open_flags);
-	if (rc < 0) {
+	if (rc < 0)
 		dma_buf_put(dmabuf);
-		return rc;
-	}
-	return 0;
+	return rc;
 
 err_free:
 	kfree(priv->memory);
-- 
2.43.0
Re: [PATCH] iommufd/selftest: Fix wrong return value in iommufd_test_dmabuf_get()
Posted by Yee Li 3 weeks, 2 days ago
Please refer,
https://lore.kernel.org/linux-iommu/20260902085414.549830-1-qinyuntan@linux.alibaba.com/