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....@amd.com>
Cc: George Shen <george.s...@amd.com>
Cc: Michael Strauss <michael.stra...@amd.com>
Cc: Mike Katsnelson <mike.katsnel...@amd.com>
Cc: Alvin Lee <alvin.l...@amd.com>
Cc: Ray Wu <ray...@amd.com>
Cc: Wenjing Liu <wenjing....@amd.com>
Cc: Harry Wentland <harry.wentl...@amd.com>
Cc: Tom Chung <chiahsuan.ch...@amd.com>
Cc: Roman Li <roman...@amd.com>
Cc: Alex Hung <alex.h...@amd.com>
Cc: Aurabindo Pillai <aurabindo.pil...@amd.com>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmu...@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);
+       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)
-- 
2.34.1

Reply via email to