]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
drm/amd/display: fix bug of accessing invalid memory
authorSu Sung Chung <Su.Chung@amd.com>
Thu, 20 Sep 2018 19:03:27 +0000 (15:03 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 15 Oct 2018 21:17:17 +0000 (16:17 -0500)
[Why]
A loop inside of build_evenly_distributed_points function that traverse through
the array of points become an infinite loop when m_GammaUpdates does not
get assigned to any value.

[How]
In DMColor, clear m_gammaIsValid bit just before writting all Zeromem for
m_GammaUpdates, to prevent calling build_evenly_distributed_points
before m_GammaUpdates gets assigned to some value.

Signed-off-by: Su Sung Chung <Su.Chung@amd.com>
Reviewed-by: Aric Cyr <Aric.Cyr@amd.com>
Acked-by: Bhawanpreet Lakha <Bhawanpreet.Lakha@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/modules/color/color_gamma.c

index 15427f4fc9900344d2bd5ba4f530588f35023eff..cdcefd08748784b353bed088aab4ed642213b8c9 100644 (file)
@@ -1069,10 +1069,14 @@ static void build_evenly_distributed_points(
        struct dividers dividers)
 {
        struct gamma_pixel *p = points;
-       struct gamma_pixel *p_last = p + numberof_points - 1;
+       struct gamma_pixel *p_last;
 
        uint32_t i = 0;
 
+       // This function should not gets called with 0 as a parameter
+       ASSERT(numberof_points > 0);
+       p_last = p + numberof_points - 1;
+
        do {
                struct fixed31_32 value = dc_fixpt_from_fraction(i,
                        numberof_points - 1);
@@ -1083,7 +1087,7 @@ static void build_evenly_distributed_points(
 
                ++p;
                ++i;
-       } while (i != numberof_points);
+       } while (i < numberof_points);
 
        p->r = dc_fixpt_div(p_last->r, dividers.divider1);
        p->g = dc_fixpt_div(p_last->g, dividers.divider1);