Skip to content

Commit 07e388a

Browse files
effective-lightalexdeucher
authored andcommitted
drm/amd/display: prevent potential division by zero errors
There are two places in apply_below_the_range() where it's possible for a divide by zero error to occur. So, to fix this make sure the divisor is non-zero before attempting the computation in both cases. Cc: stable@vger.kernel.org Link: https://gitlab.freedesktop.org/drm/amd/-/issues/2637 Fixes: a463b26 ("drm/amd/display: Fix frames_to_insert math") Fixes: ded6119 ("drm/amd/display: Reinstate LFC optimization") Reviewed-by: Aurabindo Pillai <aurabindo.pillai@amd.com> Signed-off-by: Hamza Mahfooz <hamza.mahfooz@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
1 parent 57a943e commit 07e388a

File tree

1 file changed

+6
-3
lines changed
  • drivers/gpu/drm/amd/display/modules/freesync

1 file changed

+6
-3
lines changed

drivers/gpu/drm/amd/display/modules/freesync/freesync.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,9 @@ static void apply_below_the_range(struct core_freesync *core_freesync,
338338
* - Delta for CEIL: delta_from_mid_point_in_us_1
339339
* - Delta for FLOOR: delta_from_mid_point_in_us_2
340340
*/
341-
if ((last_render_time_in_us / mid_point_frames_ceil) < in_out_vrr->min_duration_in_us) {
341+
if (mid_point_frames_ceil &&
342+
(last_render_time_in_us / mid_point_frames_ceil) <
343+
in_out_vrr->min_duration_in_us) {
342344
/* Check for out of range.
343345
* If using CEIL produces a value that is out of range,
344346
* then we are forced to use FLOOR.
@@ -385,8 +387,9 @@ static void apply_below_the_range(struct core_freesync *core_freesync,
385387
/* Either we've calculated the number of frames to insert,
386388
* or we need to insert min duration frames
387389
*/
388-
if (last_render_time_in_us / frames_to_insert <
389-
in_out_vrr->min_duration_in_us){
390+
if (frames_to_insert &&
391+
(last_render_time_in_us / frames_to_insert) <
392+
in_out_vrr->min_duration_in_us){
390393
frames_to_insert -= (frames_to_insert > 1) ?
391394
1 : 0;
392395
}

0 commit comments

Comments
 (0)