Fix memory leaks in DCN clock source creation functions #438
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch fixes multiple memory leak issues in several DCN3.x clock_source_create() and create_resource_pool() implementations. These functions allocate clk_src via kzalloc(), but on construct failure some of them return NULL without freeing the allocated memory. This mirrors the same class of issue previously fixed in commit 055e547 ("drm/amd/display: fix leak in clock_source_create()"), which addressed leaks in earlier DCE/DCN generations.
For consistency and correctness, this patch ensures that all affected DCE80/DCN30/DCN31/DCN32/DCN3xx clock_source_create() functions explicitly call kfree() before hitting BREAK_TO_DEBUGGER() and returning NULL.
No functional behavior is changed in the success path. Only failure paths are corrected to guarantee proper cleanup.
Files and functions updated:
resource pool fixes:
Motivation
All these clock_source_create() functions follow the same ownership model as earlier DCE/DCN implementations: the allocation is local to the function, and a failure during construct() does not hand the pointer to any external structure. Thus the caller becomes the sole owner of clk_src during the failure path, and it must be freed explicitly before returning NULL.
Missing kfree() results in memory leaks, especially during repeated resource pool construction attempts or probe retries. The fix aligns these implementations with the correct error-handling pattern already established in upstream DC/DCE code.
Similarly, dce83_create_resource_pool() in the DCE80 path suffered from the same class of leak, which is now fixed by adding the missing kfree(pool), and dcn31_create_resource_pool() now frees its pool before BREAK_TO_DEBUGGER() is hit on failure.
Changes
kfree(clk_src);beforeBREAK_TO_DEBUGGER();and safe cleanup semantics across all DCN3.x implementations.
kfree(pool);in dce83_create_resource_pool(), matching theupstream fix for the memleak in this path.
dcn31_create_resource_pool() so that cleanup is guaranteed to happen
before any debug break.