Skip to contentSkip to conversation

drm/amdgpu: refine error handling in amdgpu_ttm_tt_pin_userptr

PATCH In review Lang Yu 2 participants 2 messages Oct 18, 2024

Subsystems (2)
lore
Share & tools
lore

Lang Yu

author
#0 lore raw

PATCH 1/1 drm/amdgpu: refine error handling in amdgpu_ttm_tt_pin_userptr

Free sg table when dma_map_sgtable() failed to avoid memory leak.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3 -1
index 74adb983ab03..0637414fc70e 100644
@@ -812,7 +812,7 @@ static int amdgpu_ttm_tt_pin_userptr(struct ttm_device *bdev,
 	/* Map SG to device */
 	r = dma_map_sgtable(adev->dev, ttm->sg, direction, 0);
 	if (r)
-		goto release_sg;
+		goto release_sg_table;
 
 	/* convert SG to linear array of pages and dma addresses */
 	drm_prime_sg_to_dma_addr_array(ttm->sg, gtt->ttm.dma_address,
@@ -820,6 +820,8 @@ static int amdgpu_ttm_tt_pin_userptr(struct ttm_device *bdev,
 
 	return 0;
 
+release_sg_table:
+	sg_free_table(ttm->sg);
 release_sg:
 	kfree(ttm->sg);
 	ttm->sg = NULL;
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Lang Yu

Free sg table when dma_map_sgtable() failed to avoid memory leak.

Quoted 29 lines
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c +3 -2
index 74adb983ab03..0637414fc70e 100644
@@ -812,7 +812,7 @@ static int amdgpu_ttm_tt_pin_userptr(struct ttm_device *bdev,
        /* Map SG to device */
        r = dma_map_sgtable(adev->dev, ttm->sg, direction, 0);
        if (r)
-               goto release_sg;
+               goto release_sg_table;
 
        /* convert SG to linear array of pages and dma addresses */
        drm_prime_sg_to_dma_addr_array(ttm->sg, gtt->ttm.dma_address,
@@ -820,6 +820,8 @@ static int amdgpu_ttm_tt_pin_userptr(struct ttm_device *bdev,
 
        return 0;
 
+release_sg_table:
+       sg_free_table(ttm->sg);
 release_sg:
        kfree(ttm->sg);
        ttm->sg = NULL;
--

2.25.1