drm/amd/display: Fix psr static frames calculation
authorRoman Li <roman.li@amd.com>
Tue, 14 Jan 2020 18:56:08 +0000 (13:56 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 11 Feb 2020 17:10:41 +0000 (12:10 -0500)
[Why]
Driver crash with psr feature enabled due to divide-by-zero error.
This is a regression after rework to calculate static screen frame
number entry time.

[How]
Correct order of operations to avoid divide-by-zero.

Signed-off-by: Roman Li <roman.li@amd.com>
Reviewed-by: Zhan Liu <Zhan.Liu@amd.com>
Acked-by: Bhawanpreet Lakha <Bhawanpreet.Lakha@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

index 2795415..63e8a12 100644 (file)
@@ -8408,7 +8408,6 @@ bool amdgpu_dm_psr_enable(struct dc_stream_state *stream)
        /* Calculate number of static frames before generating interrupt to
         * enter PSR.
         */
-       unsigned int frame_time_microsec = 1000000 / vsync_rate_hz;
        // Init fail safe of 2 frames static
        unsigned int num_frames_static = 2;
 
@@ -8423,8 +8422,10 @@ bool amdgpu_dm_psr_enable(struct dc_stream_state *stream)
         * Calculate number of frames such that at least 30 ms of time has
         * passed.
         */
-       if (vsync_rate_hz != 0)
+       if (vsync_rate_hz != 0) {
+               unsigned int frame_time_microsec = 1000000 / vsync_rate_hz;
                num_frames_static = (30000 / frame_time_microsec) + 1;
+       }
 
        params.triggers.cursor_update = true;
        params.triggers.overlay_update = true;