drm/amd/display: Fix potential access beyond end of array in CM
authorHarry Wentland <harry.wentland@amd.com>
Wed, 14 Mar 2018 19:54:27 +0000 (15:54 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 11 Apr 2018 18:08:04 +0000 (13:08 -0500)
Signed-off-by: Harry Wentland <harry.wentland@amd.com>
CC: Dan Carpenter <dan.carpenter@oracle.com>
Reviewed-by: Tony Cheng <Tony.Cheng@amd.com>
Acked-by: Harry Wentland <harry.wentland@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/dc/dcn10/dcn10_cm_common.c

index 881a1bff94d2ce065ffe2438391e280da6acd5ea..96d5878e9ccd2523f4704fd87b5e22b998cef005 100644 (file)
@@ -367,15 +367,15 @@ bool cm_helper_translate_curve_to_hw_format(
 
        lut_params->hw_points_num = hw_points;
 
-       i = 1;
-       for (k = 0; k < MAX_REGIONS_NUMBER && i < MAX_REGIONS_NUMBER; k++) {
+       k = 0;
+       for (i = 1; i < MAX_REGIONS_NUMBER; i++) {
                if (seg_distr[k] != -1) {
                        lut_params->arr_curve_points[k].segments_num =
                                        seg_distr[k];
                        lut_params->arr_curve_points[i].offset =
                                        lut_params->arr_curve_points[k].offset + (1 << seg_distr[k]);
                }
-               i++;
+               k++;
        }
 
        if (seg_distr[k] != -1)
@@ -529,15 +529,15 @@ bool cm_helper_translate_curve_to_degamma_hw_format(
 
        lut_params->hw_points_num = hw_points;
 
-       i = 1;
-       for (k = 0; k < MAX_REGIONS_NUMBER && i < MAX_REGIONS_NUMBER; k++) {
+       k = 0;
+       for (i = 1; i < MAX_REGIONS_NUMBER; i++) {
                if (seg_distr[k] != -1) {
                        lut_params->arr_curve_points[k].segments_num =
                                        seg_distr[k];
                        lut_params->arr_curve_points[i].offset =
                                        lut_params->arr_curve_points[k].offset + (1 << seg_distr[k]);
                }
-               i++;
+               k++;
        }
 
        if (seg_distr[k] != -1)