Skip to contentSkip to conversation

drm/msm: dpu: Fix memory leak caused by dropped reference

PATCH In review Sean Paul 2 participants 5 messages Oct 4, 2018 – Oct 9, 2018 3 messages not in the archive

Subsystems (3)
lore
Share & tools
lore

Sean Paul

author
#0 lore raw

PATCH 1/2 drm/msm: dpu: Fix memory leak caused by dropped reference

From: Sean Paul <[email protected]>

We are currently leaking a drm_crtc_commit struct for every atomic commit containing plane state. The dpu plane destroy function cleans up the fb reference manually, but fails to release the commit ref. As a result, we just keep allocating drm_crtc_commits without ever freeing them. Fortunately there's a helper function which will clean up all of our mess at once, so use that.

Thanks to Doug Anderson for reporting the memory leak (and leaving breadcrumbs from kmemleak!).

---
 drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c +1 -3
index fc59a69aa832..f549daf30fe6 100644
@@ -1203,9 +1203,7 @@ static void dpu_plane_destroy_state(struct drm_plane *plane,
 
 	pstate = to_dpu_plane_state(state);
 
-	/* remove ref count for frame buffers */
-	if (state->fb)
-		drm_framebuffer_put(state->fb);
+	__drm_atomic_helper_plane_destroy_state(state);
 
 	kfree(pstate);
 }
Signature · 6 lines
Sean Paul, Software Engineer, Google / Chromium OS

_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno

A message that is not in the archive (sent off-list or not yet received): 20181004180945.46132-1-sean-p7yTbzM4H96eqtR555YLDQ@public.gmane.org

author
#2 lore raw

PATCH 2/2 drm/msm: dpu: Remove checks from dpu_plane_destroy_state()

From: Sean Paul <[email protected]>

They're not needed.

---
 drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c +1 -12
index f549daf30fe6..4213e7a8e525 100644
@@ -1193,19 +1193,8 @@ static void dpu_plane_destroy(struct drm_plane *plane)
 static void dpu_plane_destroy_state(struct drm_plane *plane,
 		struct drm_plane_state *state)
 {
-	struct dpu_plane_state *pstate;
-
-	if (!plane || !state) {
-		DPU_ERROR("invalid arg(s), plane %d state %d\n",
-				plane != 0, state != 0);
-		return;
-	}
-
-	pstate = to_dpu_plane_state(state);
-
 	__drm_atomic_helper_plane_destroy_state(state);
-
-	kfree(pstate);
+	kfree(to_dpu_plane_state(state));
 }
 
 static struct drm_plane_state *
Signature · 6 lines
Sean Paul, Software Engineer, Google / Chromium OS

_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno

A message that is not in the archive (sent off-list or not yet received): 20181004180945.46132-2-sean-p7yTbzM4H96eqtR555YLDQ@public.gmane.org

Reviewed-by
#4 lore raw

Re: [PATCH 2/2] drm/msm: dpu: Remove checks from dpu_plane_destroy_state()

Quoted 6 lines · Sean Paul

From: Sean Paul <[email protected]>

They're not needed.

---

Quoted 30 lines
 drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c +1 -12
index f549daf30fe6..4213e7a8e525 100644
@@ -1193,19 +1193,8 @@ static void dpu_plane_destroy(struct drm_plane
 *plane)
 static void dpu_plane_destroy_state(struct drm_plane *plane,
 		struct drm_plane_state *state)
 {
-	struct dpu_plane_state *pstate;
-
-	if (!plane || !state) {
-		DPU_ERROR("invalid arg(s), plane %d state %d\n",
-				plane != 0, state != 0);
-		return;
-	}
-
-	pstate = to_dpu_plane_state(state);
-
 	__drm_atomic_helper_plane_destroy_state(state);
-
-	kfree(pstate);
+	kfree(to_dpu_plane_state(state));
 }
 

static struct drm_plane_state *

Signature · 5 lines
Jeykumar S
_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno
Reviewed-by
#5 lore raw
In reply to a message not in the archive
Quoted 4 lines · Sean Paul

From: Sean Paul <[email protected]>

We are currently leaking a drm_crtc_commit struct for every atomic commit containing plane state. The dpu plane destroy function cleans up

dpu plane destroy -> dpu_plane_destroy_state

Quoted 11 lines

the fb reference manually, but fails to release the commit ref. As a result, we just keep allocating drm_crtc_commits without ever freeing them. Fortunately there's a helper function which will clean up all of our mess at once, so use that.

Thanks to Doug Anderson for reporting the memory leak (and leaving breadcrumbs from kmemleak!).

---

With the nit addressed:

Quoted 21 lines
 drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c +0 -0
index fc59a69aa832..f549daf30fe6 100644
@@ -1203,9 +1203,7 @@ static void dpu_plane_destroy_state(struct 

drm_plane
*plane,

drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c +1 -3
 	pstate = to_dpu_plane_state(state);
 
-	/* remove ref count for frame buffers */
-	if (state->fb)
-		drm_framebuffer_put(state->fb);
+	__drm_atomic_helper_plane_destroy_state(state);
 
 	kfree(pstate);
 }
Signature · 5 lines
Jeykumar S
_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno

A message that is not in the archive (sent off-list or not yet received): 97dcf11ad4358eb4bf198048602da801-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org

author
#7 lore raw
Quoted 11 lines · Jeykumar Sankaran
Quoted 4 lines · Sean Paul

From: Sean Paul <[email protected]>

We are currently leaking a drm_crtc_commit struct for every atomic commit containing plane state. The dpu plane destroy function cleans up

dpu plane destroy -> dpu_plane_destroy_state

Quoted 5 lines

the fb reference manually, but fails to release the commit ref. As a result, we just keep allocating drm_crtc_commits without ever freeing them. Fortunately there's a helper function which will clean up all of our mess at once, so use that.

Quoted 7 lines
Quoted 6 lines

Thanks to Doug Anderson for reporting the memory leak (and leaving breadcrumbs from kmemleak!).

---

With the nit addressed:

FYI, this already picked up in msm-next last week.

Quoted 27 lines
Quoted 21 lines
 drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c +0 -0
index fc59a69aa832..f549daf30fe6 100644
@@ -1203,9 +1203,7 @@ static void dpu_plane_destroy_state(struct

drm_plane
*plane,

drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c +1 -3
 	pstate = to_dpu_plane_state(state);
 
-	/* remove ref count for frame buffers */
-	if (state->fb)
-		drm_framebuffer_put(state->fb);
+	__drm_atomic_helper_plane_destroy_state(state);
 
 	kfree(pstate);
 }
Signature · 1 line
Jeykumar S
Signature · 5 lines
Sean Paul, Software Engineer, Google / Chromium OS
_______________________________________________
Freedreno mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/freedreno