[PATCH] drm/radeon: fix reference count leak in cik_sdma_ib_test()

Xin Xiong xiongx18 at fudan.edu.cn
Fri Apr 29 08:53:32 UTC 2022


The issue takes place in several error handling paths in
cik_sdma_ib_test(). For example, when radeon_fence_wait_timeout()
returns a value no greater than zero, the function simply returns an
error code, forgetting to decrease the reference count of the object
"ib", which is incremented by radeon_ib_get() earlier. This may
result in memory leaks.

Fix it by decrementing the reference count of "ib" in those paths.

Fixes: 04db4caf5c83 ("drm/radeon: Avoid double gpu reset by adding a timeout on IB ring tests.")
Signed-off-by: Xin Xiong <xiongx18 at fudan.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf at gmail.com>
---
 drivers/gpu/drm/radeon/cik_sdma.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/radeon/cik_sdma.c b/drivers/gpu/drm/radeon/cik_sdma.c
index 919b14845c3c..d0e7323cdd42 100644
--- a/drivers/gpu/drm/radeon/cik_sdma.c
+++ b/drivers/gpu/drm/radeon/cik_sdma.c
@@ -732,18 +732,18 @@ int cik_sdma_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
 
 	r = radeon_ib_schedule(rdev, &ib, NULL, false);
 	if (r) {
-		radeon_ib_free(rdev, &ib);
 		DRM_ERROR("radeon: failed to schedule ib (%d).\n", r);
-		return r;
+		goto out;
 	}
 	r = radeon_fence_wait_timeout(ib.fence, false, usecs_to_jiffies(
 		RADEON_USEC_IB_TEST_TIMEOUT));
 	if (r < 0) {
 		DRM_ERROR("radeon: fence wait failed (%d).\n", r);
-		return r;
+		goto out;
 	} else if (r == 0) {
 		DRM_ERROR("radeon: fence wait timed out.\n");
-		return -ETIMEDOUT;
+		r = -ETIMEDOUT;
+		goto out;
 	}
 	r = 0;
 	for (i = 0; i < rdev->usec_timeout; i++) {
@@ -758,6 +758,7 @@ int cik_sdma_ib_test(struct radeon_device *rdev, struct radeon_ring *ring)
 		DRM_ERROR("radeon: ib test failed (0x%08X)\n", tmp);
 		r = -EINVAL;
 	}
+out:
 	radeon_ib_free(rdev, &ib);
 	return r;
 }
-- 
2.25.1



More information about the amd-gfx mailing list