* [PATCH] drm/amd/display: prevent potential division by zero errors
@ 2023-09-05 18:53 Hamza Mahfooz
2023-09-05 19:28 ` Aurabindo Pillai
0 siblings, 1 reply; 2+ messages in thread
From: Hamza Mahfooz @ 2023-09-05 18:53 UTC (permalink / raw)
To: amd-gfx
Cc: Aurabindo Pillai, Hamza Mahfooz, stable, Harry Wentland, Leo Li,
Rodrigo Siqueira, Alex Deucher, Christian König, Pan,
Xinhui, David Airlie, Daniel Vetter, Tom Rix, Qingqing Zhuo,
Aric Cyr, Austin Zheng, Mike Hsieh, Leo (Hanghong) Ma,
Dillon Varone, Bayan Zabihiyan, Amanda Liu, dri-devel,
linux-kernel
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: a463b263032f ("drm/amd/display: Fix frames_to_insert math")
Fixes: ded6119e825a ("drm/amd/display: Reinstate LFC optimization")
Signed-off-by: Hamza Mahfooz <hamza.mahfooz@amd.com>
---
drivers/gpu/drm/amd/display/modules/freesync/freesync.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/amd/display/modules/freesync/freesync.c b/drivers/gpu/drm/amd/display/modules/freesync/freesync.c
index dbd60811f95d..ef3a67409021 100644
--- a/drivers/gpu/drm/amd/display/modules/freesync/freesync.c
+++ b/drivers/gpu/drm/amd/display/modules/freesync/freesync.c
@@ -338,7 +338,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.
@@ -385,8 +387,9 @@ 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 <
- in_out_vrr->min_duration_in_us){
+ 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;
}
--
2.41.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] drm/amd/display: prevent potential division by zero errors
2023-09-05 18:53 [PATCH] drm/amd/display: prevent potential division by zero errors Hamza Mahfooz
@ 2023-09-05 19:28 ` Aurabindo Pillai
0 siblings, 0 replies; 2+ messages in thread
From: Aurabindo Pillai @ 2023-09-05 19:28 UTC (permalink / raw)
To: Hamza Mahfooz, amd-gfx
Cc: stable, Harry Wentland, Leo Li, Rodrigo Siqueira, Alex Deucher,
Christian König, Pan, Xinhui, David Airlie, Daniel Vetter,
Tom Rix, Qingqing Zhuo, Aric Cyr, Austin Zheng, Mike Hsieh,
Leo (Hanghong) Ma, Dillon Varone, Bayan Zabihiyan, Amanda Liu,
dri-devel, linux-kernel
On 2023-09-05 14:53, Hamza Mahfooz wrote:
> 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: a463b263032f ("drm/amd/display: Fix frames_to_insert math")
> Fixes: ded6119e825a ("drm/amd/display: Reinstate LFC optimization")
> Signed-off-by: Hamza Mahfooz <hamza.mahfooz@amd.com>
> ---
> drivers/gpu/drm/amd/display/modules/freesync/freesync.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/display/modules/freesync/freesync.c b/drivers/gpu/drm/amd/display/modules/freesync/freesync.c
> index dbd60811f95d..ef3a67409021 100644
> --- a/drivers/gpu/drm/amd/display/modules/freesync/freesync.c
> +++ b/drivers/gpu/drm/amd/display/modules/freesync/freesync.c
> @@ -338,7 +338,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.
> @@ -385,8 +387,9 @@ 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 <
> - in_out_vrr->min_duration_in_us){
> + 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;
> }
Reviewed-by: Aurabindo Pillai <aurabindo.pillai@amd.com>
--
Thanks & Regards,
Jay
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-09-05 19:28 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-05 18:53 [PATCH] drm/amd/display: prevent potential division by zero errors Hamza Mahfooz
2023-09-05 19:28 ` Aurabindo Pillai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®