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 <[email protected]>
Cc: George Shen <[email protected]>
Cc: Michael Strauss <[email protected]>
Cc: Mike Katsnelson <[email protected]>
Cc: Alvin Lee <[email protected]>
Cc: Ray Wu <[email protected]>
Cc: Wenjing Liu <[email protected]>
Cc: Harry Wentland <[email protected]>
Cc: Tom Chung <[email protected]>
Cc: Roman Li <[email protected]>
Cc: Alex Hung <[email protected]>
Cc: Aurabindo Pillai <[email protected]>
Signed-off-by: Srinivasan Shanmugam <[email protected]>
---
 .../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