Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 617a89ff authored by Hamza Mahfooz's avatar Hamza Mahfooz Committed by Greg Kroah-Hartman
Browse files

drm/amd/display: prevent potential division by zero errors

[ Upstream commit 07e388aab042774f284a2ad75a70a194517cdad4 ]

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: a463b263 ("drm/amd/display: Fix frames_to_insert math")
Fixes: ded6119e825a ("drm/amd/display: Reinstate LFC optimization")
Reviewed-by: default avatarAurabindo Pillai <aurabindo.pillai@amd.com>
Signed-off-by: default avatarHamza Mahfooz <hamza.mahfooz@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 07b63a3d
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -323,7 +323,9 @@ static void apply_below_the_range(struct core_freesync *core_freesync,
		 *  - Delta for CEIL: delta_from_mid_point_in_us_1
		 *  - Delta for FLOOR: delta_from_mid_point_in_us_2
		 */
		if ((last_render_time_in_us / mid_point_frames_ceil) < in_out_vrr->min_duration_in_us) {
		if (mid_point_frames_ceil &&
		    (last_render_time_in_us / mid_point_frames_ceil) <
		    in_out_vrr->min_duration_in_us) {
			/* Check for out of range.
			 * If using CEIL produces a value that is out of range,
			 * then we are forced to use FLOOR.
@@ -370,7 +372,8 @@ static void apply_below_the_range(struct core_freesync *core_freesync,
		/* Either we've calculated the number of frames to insert,
		 * or we need to insert min duration frames
		 */
		if (last_render_time_in_us / frames_to_insert <
		if (frames_to_insert &&
		    (last_render_time_in_us / frames_to_insert) <
		    in_out_vrr->min_duration_in_us){
			frames_to_insert -= (frames_to_insert > 1) ?
					1 : 0;