Skip to contentSkip to conversation

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

PATCH In review Yi Lai 2 participants 2 messages Sep 3

Subsystems (2)
lore
Share & tools
lore

Yi Lai

author
#0 lore raw

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

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()")
---
 drivers/iommu/iommufd/selftest.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/iommu/iommufd/selftest.c +2 -4
index ee706f18f7e9..f6da927461b5 100644
@@ -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);
Signature · 1 line
2.43.0