[PATCH] drm/amd/display: Reduce Stack Usage in 'dp_retrain_link_dp_test' by heap-allocating 'audio_output'
Alex Hung
alex.hung at amd.com
Thu Jul 24 01:47:42 UTC 2025
On 7/21/25 07:06, Srinivasan Shanmugam wrote:
> The function dp_retrain_link_dp_test currently allocates a large
> audio_output array on the stack, causing the stack frame size to exceed
> the compiler limit (1080 bytes > 1024 bytes).
>
> This change prevents stack overflow issues:
> amdgpu/../display/dc/link/accessories/link_dp_cts.c:65:13: warning: stack frame size (1080) exceeds limit (1024) in 'dp_retrain_link_dp_test' [-Wframe-larger-than]
> static void dp_retrain_link_dp_test(struct dc_link *link,
>
> This commit refactors the function to dynamically allocate the
> audio_output array using kmalloc/kfree, significantly reducing stack
> usage.
>
> - Allocates audio_output on the heap instead of stack
> - Adds error handling for allocation failure
> - Frees allocated memory before function return
>
> Fixes: 9437059b4bfb ("drm/amd/display: Fix Link Override Sequencing When Switching Between DIO/HPO")
> Switching Between DIO/HPO")
> Cc: Wayne Lin <wayne.lin at amd.com>
> Cc: George Shen <george.shen at amd.com>
> Cc: Michael Strauss <michael.strauss at amd.com>
> Cc: Mike Katsnelson <mike.katsnelson at amd.com>
> Cc: Alvin Lee <Alvin.Lee2 at amd.com>
> Cc: Ray Wu <ray.wu at amd.com>
> Cc: Wenjing Liu <wenjing.liu at amd.com>
> Cc: Harry Wentland <harry.wentland at amd.com>
> Cc: Tom Chung <chiahsuan.chung at amd.com>
> Cc: Roman Li <roman.li at amd.com>
> Cc: Alex Hung <alex.hung at amd.com>
> Cc: Aurabindo Pillai <aurabindo.pillai at amd.com>
> Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam at amd.com>
> ---
> .../amd/display/dc/link/accessories/link_dp_cts.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/amd/display/dc/link/accessories/link_dp_cts.c b/drivers/gpu/drm/amd/display/dc/link/accessories/link_dp_cts.c
> index 2956c2b3ad1a..c4db61cb5079 100644
> --- a/drivers/gpu/drm/amd/display/dc/link/accessories/link_dp_cts.c
> +++ b/drivers/gpu/drm/amd/display/dc/link/accessories/link_dp_cts.c
> @@ -75,7 +75,16 @@ static void dp_retrain_link_dp_test(struct dc_link *link,
> bool is_hpo_acquired;
> uint8_t count;
> int i;
> - struct audio_output audio_output[MAX_PIPES];
> +
> + /* Dynamically allocate audio_output to reduce stack usage */
> + struct audio_output *audio_output;
> +
> + audio_output = kmalloc(sizeof(*audio_output) * MAX_PIPES, GFP_KERNEL);
This file is shared with another OS which has no kmalloc call, and
unfortunately this change does not pass CI.
> + if (!audio_output) {
> + /* Allocation failed, handle error gracefully */
> + DC_LOG_ERROR("%s: Failed to allocate audio_output", __func__);
> + return;
> + }
>
> needs_divider_update = (link->dc->link_srv->dp_get_encoding_format(link_setting) !=
> link->dc->link_srv->dp_get_encoding_format((const struct dc_link_settings *) &link->cur_link_settings));
> @@ -144,6 +153,8 @@ static void dp_retrain_link_dp_test(struct dc_link *link,
> stream_update.dpms_off = &dpms_off;
> dc_update_planes_and_stream(state->clk_mgr->ctx->dc, NULL, 0, state->streams[i], &stream_update);
> }
> +
> + kfree(audio_output);
> }
>
> static void dp_test_send_link_training(struct dc_link *link)
More information about the amd-gfx
mailing list