Skip to contentSkip to conversation

drm/amd/display: make PSR static screen entry within 30 ms

PATCH In review Colin Ian King 3 participants 3 messages Jan 17, 2020 – Jan 27, 2020

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

Hi,

Static analysis with Coverity has detected a division by zero in the following commit:

commit 5b5abe9526073ccbf3032d27b5864520829cdd9c

Author: Anthony Koo <[email protected]>
Date:   Mon Dec 9 17:26:34 2019 -0500

drm/amd/display: make PSR static screen entry within 30 ms

Specifically:

       unsigned int vsync_rate_hz = 0;
       struct dc_static_screen_params params = {0};
       /* Calculate number of static frames before generating interrupt to
        * enter PSR.
        */
       unsigned int frame_time_microsec = 1000000 / vsync_rate_hz;

vsync_rate_hz is zero, and frame_time_microsec is being assigned a value that is being divided by zero. I'm not sure why this is coded this way and not sure what the fix is, hence I'm reporting the issue.

Colin
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer
#1 lore raw

PATCH 1/1 drm/amd/display: Fix psr static frames calculation

From: Roman Li <[email protected]>

[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.

Cc Colin Ian King <[email protected]>
Fixes 5b5abe952607 drm/amd/display: make PSR static screen entry within 30 ms
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +3 -2
index eed3ed7180fd..61c36c1520c2 100644
@@ -8491,7 +8491,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;
 
@@ -8506,8 +8505,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;
Signature · 6 lines
2.25.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Acked-by on v1 1/1
#2 lore raw

Re: [PATCH] drm/amd/display: Fix psr static frames calculation

Quoted 8 lines · Harry Wentland

From: Roman Li <[email protected]>

[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.

Quoted 8 lines

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

Cc Colin Ian King <[email protected]>
Fixes 5b5abe952607 drm/amd/display: make PSR static screen entry within 30 ms
Quoted 35 lines
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +3 -3
index eed3ed7180fd..61c36c1520c2 100644
@@ -8491,7 +8491,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;
 
@@ -8506,8 +8505,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;
--

2.25.0

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx