]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/amd/display: Check num_valid_sets before accessing reader_wm_sets[]
authorAlex Hung <alex.hung@amd.com>
Tue, 16 Apr 2024 22:22:35 +0000 (16:22 -0600)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 2 May 2024 20:18:17 +0000 (16:18 -0400)
[WHY & HOW]
num_valid_sets needs to be checked to avoid a negative index when
accessing reader_wm_sets[num_valid_sets - 1].

This fixes an OVERRUN issue reported by Coverity.

Reviewed-by: Harry Wentland <harry.wentland@amd.com>
Acked-by: Tom Chung <chiahsuan.chung@amd.com>
Signed-off-by: Alex Hung <alex.hung@amd.com>
Tested-by: Daniel Wheeler <daniel.wheeler@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/dc/clk_mgr/dcn21/rn_clk_mgr.c

index 5ef0879f6ad9c136b0bdfb29023a64e7775e2974..aea4bb46856eff15fe8684281853fa09a5ec231a 100644 (file)
@@ -484,7 +484,8 @@ static void build_watermark_ranges(struct clk_bw_params *bw_params, struct pp_sm
                        ranges->reader_wm_sets[num_valid_sets].max_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
 
                        /* Modify previous watermark range to cover up to max */
-                       ranges->reader_wm_sets[num_valid_sets - 1].max_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
+                       if (num_valid_sets > 0)
+                               ranges->reader_wm_sets[num_valid_sets - 1].max_fill_clk_mhz = PP_SMU_WM_SET_RANGE_CLK_UNCONSTRAINED_MAX;
                }
                num_valid_sets++;
        }