Skip to contentSkip to conversation

drm/msm: fix potential memleak issue

PATCH New Bernard Zhao 1 participant 1 message Jun 12, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/msm: fix potential memleak issue

Function msm_gpu_crashstate_capture maybe called for several times, and then the state->bos is a potential memleak. Also the state->pos maybe alloc failed, but now without any handle. This change is to fix some potential memleak and add error handle when alloc failed.

---
 drivers/gpu/drm/msm/msm_gpu.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/msm/msm_gpu.c +3 -0
index a22d30622306..d67a9933f3ce 100644
@@ -366,8 +366,11 @@ static void msm_gpu_crashstate_capture(struct msm_gpu *gpu,
 			if (!should_dump(submit, submit->cmd[i].idx))
 				nr++;
 
+		kfree(state->bos);
 		state->bos = kcalloc(nr,
 			sizeof(struct msm_gpu_state_bo), GFP_KERNEL);
+		if (!state->bos)
+			return;
 
 		for (i = 0; i < submit->nr_bos; i++) {
 			if (should_dump(submit, i)) {
Signature · 1 line
2.17.1