mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/amd/display: Fix logger leak on perf trace allocation failure
@ 2026-10-26 11:10 Jackie Liu
  2026-11-15  7:08 ` Wayne Lin
  2026-11-16  6:57 ` Markus Elfring
  0 siblings, 2 replies; 4+ messages in thread
From: Jackie Liu @ 2026-10-26 11:10 UTC (permalink / raw)
  To: harry.wentland
  Cc: sunpeng.li, alexander.deucher, christian.koenig, amd-gfx,
	dri-devel, linux-kernel

From: Jackie Liu <liuyun01@kylinos.cn>

dc_construct_ctx() allocates a logger and stores an alias in dc->dml.logger
before allocating the performance trace object. If dc_perf_trace_create()
fails, the function frees dc_ctx without releasing the logger. Since
dc->ctx is assigned only after the trace allocation succeeds,
dc_destruct() cannot reclaim the logger on this error path.

Free the logger before discarding dc_ctx and clear dc->dml.logger to avoid
leaving a dangling alias after the failed construction.

Fixes: 5d72e247e58c ("drm/amd/display: switch DC over to the new DRM logging macros")
Cc: stable@vger.kernel.org
Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
---
 drivers/gpu/drm/amd/display/dc/core/dc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/amd/display/dc/core/dc.c b/drivers/gpu/drm/amd/display/dc/core/dc.c
index 1143916391e79..03179633cd036 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc.c
@@ -1022,6 +1022,8 @@ static bool dc_construct_ctx(struct dc *dc,
 
 	dc_ctx->perf_trace = dc_perf_trace_create();
 	if (!dc_ctx->perf_trace) {
+		kfree(dc_ctx->logger);
+		dc->dml.logger = NULL;
 		kfree(dc_ctx);
 		ASSERT_CRITICAL(false);
 		return false;
-- 
2.43.0


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

* Re: [PATCH] drm/amd/display: Fix logger leak on perf trace allocation failure
  2026-10-26 11:10 [PATCH] drm/amd/display: Fix logger leak on perf trace allocation failure Jackie Liu
@ 2026-11-15  7:08 ` Wayne Lin
  2026-11-16  6:57 ` Markus Elfring
  1 sibling, 0 replies; 4+ messages in thread
From: Wayne Lin @ 2026-11-15  7:08 UTC (permalink / raw)
  To: amd-gfx
  Cc: Jackie Liu, Jackie Liu, harry.wentland, sunpeng.li,
	alexander.deucher, christian.koenig, dri-devel, linux-kernel

Reviewed-by: Wayne Lin <Wayne.Lin@amd.com>

On Mon, 26 Oct 2026 19:10:47 +0800, Jackie Liu wrote:
> From: Jackie Liu <liuyun01@kylinos.cn>
>
> dc_construct_ctx() allocates a logger and stores an alias in dc->dml.logger
> before allocating the performance trace object. If dc_perf_trace_create()
> fails, the function frees dc_ctx without releasing the logger. Since
> dc->ctx is assigned only after the trace allocation succeeds,
> dc_destruct() cannot reclaim the logger on this error path.
>
> Free the logger before discarding dc_ctx and clear dc->dml.logger to avoid
> leaving a dangling alias after the failed construction.
>
> Fixes: 5d72e247e58c ("drm/amd/display: switch DC over to the new DRM logging macros")
> Cc: stable@vger.kernel.org
> Signed-off-by: Jackie Liu <liuyun01@kylinos.cn>
> ---
>  drivers/gpu/drm/amd/display/dc/core/dc.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/drivers/gpu/drm/amd/display/dc/core/dc.c b/drivers/gpu/drm/amd/display/dc/core/dc.c
> index 1143916391e79..03179633cd036 100644
> --- a/drivers/gpu/drm/amd/display/dc/core/dc.c
> +++ b/drivers/gpu/drm/amd/display/dc/core/dc.c
> @@ -1022,6 +1022,8 @@ static bool dc_construct_ctx(struct dc *dc,
>  
>  	dc_ctx->perf_trace = dc_perf_trace_create();
>  	if (!dc_ctx->perf_trace) {
> +		kfree(dc_ctx->logger);
> +		dc->dml.logger = NULL;
>  		kfree(dc_ctx);
>  		ASSERT_CRITICAL(false);
>  		return false;
> -- 
> 2.43.0
>
>

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

* Re: [PATCH] drm/amd/display: Fix logger leak on perf trace allocation failure
  2026-10-26 11:10 [PATCH] drm/amd/display: Fix logger leak on perf trace allocation failure Jackie Liu
  2026-11-15  7:08 ` Wayne Lin
@ 2026-11-16  6:57 ` Markus Elfring
  2026-11-16  7:42   ` Jackie Liu
  1 sibling, 1 reply; 4+ messages in thread
From: Markus Elfring @ 2026-11-16  6:57 UTC (permalink / raw)
  To: Jackie Liu, amd-gfx, dri-devel, Alex Deucher,
	Christian König, Harry Wentland, Leo Li, Wayne Lin
  Cc: Jackie Liu, LKML

…
> Free the logger before discarding dc_ctx and clear dc->dml.logger to avoid
> leaving a dangling alias after the failed construction.

Would there be a need to complete the exception handling also after a failed
link_create_link_service() call in the implementation of the function “dc_construct_ctx”?
https://elixir.bootlin.com/linux/v7.4-rc1/source/drivers/gpu/drm/amd/display/dc/core/dc.c#L990-L1037

How do you think about to avoid duplicate source code another bit?

Regards,
Markus

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

* Re: [PATCH] drm/amd/display: Fix logger leak on perf trace allocation failure
  2026-11-16  6:57 ` Markus Elfring
@ 2026-11-16  7:42   ` Jackie Liu
  0 siblings, 0 replies; 4+ messages in thread
From: Jackie Liu @ 2026-11-16  7:42 UTC (permalink / raw)
  To: Markus Elfring, Jackie Liu, amd-gfx, dri-devel, Alex Deucher,
	Christian König, Harry Wentland, Leo Li, Wayne Lin
  Cc: LKML

2026年11月16日 14:57, "Markus Elfring" <Markus.Elfring@web.de mailto:Markus.Elfring@web.de?to=%22Markus%20Elfring%22%20%3CMarkus.Elfring%40web.de%3E > 写到:


> 
> …
> 
> > 
> > Free the logger before discarding dc_ctx and clear dc->dml.logger to avoid
> >  leaving a dangling alias after the failed construction.
> > 
> Would there be a need to complete the exception handling also after a failed
> link_create_link_service() call in the implementation of the function “dc_construct_ctx”?
> https://elixir.bootlin.com/linux/v7.4-rc1/source/drivers/gpu/drm/amd/display/dc/core/dc.c#L990-L1037

Hi Markus,

Thanks for taking a look.

The link_create_link_service() failure is already covered by the
caller's cleanup. dc->ctx is assigned before that call. On failure,
both the normal and virtual hardware paths reach the destruct_dc
label in dc_create(), where dc_destruct() releases the logger,
perf_trace, and context.

The perf_trace allocation failure happens before dc->ctx is assigned,
so dc_destruct() cannot reach the logger in that case. That is the
leak this patch addresses.

Using common cleanup labels for the early failure paths would be a
reasonable separate cleanup. For this stable-targeted fix, I would
prefer to keep the change limited to the missing logger cleanup.

Best regards,
Jackie

> 
> How do you think about to avoid duplicate source code another bit?
> 
> Regards,
> Markus
>

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

end of thread, other threads:[~2026-11-16  7:42 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-26 11:10 [PATCH] drm/amd/display: Fix logger leak on perf trace allocation failure Jackie Liu
2026-11-15  7:08 ` Wayne Lin
2026-11-16  6:57 ` Markus Elfring
2026-11-16  7:42   ` Jackie Liu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®