Skip to contentSkip to conversation

drm/amd/display: Fix logger leak on perf trace allocation failure

PATCH In review Jackie Liu 3 participants 4 messages Oct 26 – Nov 16

Subsystems (3)
lore
Share & tools
lore

Jackie Liu

author
#0 lore raw

PATCH 1/1 drm/amd/display: Fix logger leak on perf trace allocation failure

From: Jackie Liu <[email protected]>

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")
---
 drivers/gpu/drm/amd/display/dc/core/dc.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/display/dc/core/dc.c +2 -0
index 1143916391e79..03179633cd036 100644
@@ -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;
Signature · 1 line
2.43.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 35 lines · Jackie Liu

From: Jackie Liu <[email protected]>

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")
---
 drivers/gpu/drm/amd/display/dc/core/dc.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/amd/display/dc/core/dc.c +2 -0
index 1143916391e79..03179633cd036 100644
@@ -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;
Signature · 1 line
2.43.0
#2 lore raw
In reply to Jackie Liu

…

Quoted 2 lines

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

author
#3 lore raw

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

Quoted 10 lines

…

Quoted 4 lines

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

Quoted 6 lines

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

Regards,
Markus