All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] amdgpu: fixes memleak issue when init failed
@ 2020-04-21 11:17 ` Bernard Zhao
  0 siblings, 0 replies; 30+ messages in thread
From: Bernard Zhao @ 2020-04-21 11:17 UTC (permalink / raw)
  To: Alex Deucher, Christian König, David (ChunMing) Zhou,
	David Airlie, Daniel Vetter, Tom St Denis, Ori Messinger,
	Sam Ravnborg, Bernard Zhao, amd-gfx, dri-devel, linux-kernel
  Cc: opensource.kernel

VRAM manager and DRM MM when init failed, there is no operaction
to free kzalloc memory & remove device file.
This will lead to memleak & cause stability issue.

Signed-off-by: Bernard Zhao <bernard@vivo.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 24 ++++++++++++++++----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index 82a3299e53c0..4c5fb153e6b4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -175,30 +175,44 @@ static int amdgpu_vram_mgr_init(struct ttm_mem_type_manager *man,
 	ret = device_create_file(adev->dev, &dev_attr_mem_info_vram_total);
 	if (ret) {
 		DRM_ERROR("Failed to create device file mem_info_vram_total\n");
-		return ret;
+		goto VRAM_TOTAL_FAIL;
 	}
 	ret = device_create_file(adev->dev, &dev_attr_mem_info_vis_vram_total);
 	if (ret) {
 		DRM_ERROR("Failed to create device file mem_info_vis_vram_total\n");
-		return ret;
+		goto VIS_VRAM_TOTA_FAIL;
 	}
 	ret = device_create_file(adev->dev, &dev_attr_mem_info_vram_used);
 	if (ret) {
 		DRM_ERROR("Failed to create device file mem_info_vram_used\n");
-		return ret;
+		goto VRAM_USED_FAIL;
 	}
 	ret = device_create_file(adev->dev, &dev_attr_mem_info_vis_vram_used);
 	if (ret) {
 		DRM_ERROR("Failed to create device file mem_info_vis_vram_used\n");
-		return ret;
+		goto VIS_VRAM_USED_FAIL;
 	}
 	ret = device_create_file(adev->dev, &dev_attr_mem_info_vram_vendor);
 	if (ret) {
 		DRM_ERROR("Failed to create device file mem_info_vram_vendor\n");
-		return ret;
+		goto VRAM_VERDOR_FAIL;
 	}
 
 	return 0;
+
+VRAM_VERDOR_FAIL:
+	device_remove_file(adev->dev, &dev_attr_mem_info_vis_vram_used);
+VIS_VRAM_USED_FAIL:
+	device_remove_file(adev->dev, &dev_attr_mem_info_vram_used);
+RVAM_USED_FAIL:
+	device_remove_file(adev->dev, &dev_attr_mem_info_vis_vram_total);
+VIS_VRAM_TOTA_FAIL:
+	device_remove_file(adev->dev, &dev_attr_mem_info_vram_total);
+VRAM_TOTAL_FAIL:
+	kfree(mgr);
+	man->priv = NULL;
+
+	return ret;
 }
 
 /**
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 30+ messages in thread

end of thread, other threads:[~2020-04-22 18:28 UTC | newest]

Thread overview: 30+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-21 11:17 [PATCH] amdgpu: fixes memleak issue when init failed Bernard Zhao
2020-04-21 11:17 ` Bernard Zhao
2020-04-21 11:17 ` Bernard Zhao
2020-04-21 11:22 ` Christian König
2020-04-21 11:22   ` Christian König
2020-04-21 11:22   ` Christian König
2020-04-21 12:09   ` 赵军奎
2020-04-21 12:09     ` 赵军奎
2020-04-21 12:09     ` 赵军奎
2020-04-21 13:02     ` Christian König
2020-04-21 13:02       ` Christian König
2020-04-21 13:02       ` Christian König
2020-04-21 13:39       ` 赵军奎
2020-04-21 13:39         ` 赵军奎
2020-04-21 13:39         ` 赵军奎
2020-04-21 14:53         ` Christian König
2020-04-21 14:53           ` Christian König
2020-04-21 14:53           ` Christian König
2020-04-22  0:56           ` 赵军奎
2020-04-22  0:56             ` 赵军奎
2020-04-22  0:56             ` 赵军奎
2020-04-22  7:27             ` Christian König
2020-04-22  7:27               ` Christian König
2020-04-22  7:27               ` Christian König
2020-04-22 15:51 ` Ruhl, Michael J
2020-04-22 15:51   ` Ruhl, Michael J
2020-04-22 15:51   ` Ruhl, Michael J
2020-04-22 18:28   ` Christian König
2020-04-22 18:28     ` Christian König
2020-04-22 18:28     ` Christian König

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.