[PATCH] drm/radeon/rs780: prevent division by zero in refresh rate calculation

From: Evgenii Burenchev

Date: Thu Apr 30 2026 - 06:47:46 EST


drm_mode_vrefresh() may return zero when mode clock is zero even if
htotal and vtotal are non-zero. Current code checks only htotal and
vtotal, allowing refresh_rate to become zero and subsequently causing
division by zero in rs780_program_at().

Fix by adding mode clock validation and fallback to default 60Hz in
rs780_get_pm_mode_parameters(). Add WARN_ON in rs780_program_at() to
catch such cases during development, ensuring safe fallback in all
scenarios.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Reported-by: kernel test robot <lkp@xxxxxxxxx>
Closes: https://lore.kernel.org/oe-kbuild-all/202604300508.yXci8rey-lkp@xxxxxxxxx/

Signed-off-by: Evgenii Burenchev <evg28bur@xxxxxxxxx>
---
drivers/gpu/drm/radeon/rs780_dpm.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/radeon/rs780_dpm.c b/drivers/gpu/drm/radeon/rs780_dpm.c
index 64bb4cafb8b5..8713f3fd6268 100644
--- a/drivers/gpu/drm/radeon/rs780_dpm.c
+++ b/drivers/gpu/drm/radeon/rs780_dpm.c
@@ -63,8 +63,11 @@ static void rs780_get_pm_mode_parameters(struct radeon_device *rdev)
if (crtc && crtc->enabled) {
radeon_crtc = to_radeon_crtc(crtc);
pi->crtc_id = radeon_crtc->crtc_id;
- if (crtc->mode.htotal && crtc->mode.vtotal)
+ if (crtc->mode.htotal && crtc->mode.vtotal) {
pi->refresh_rate = drm_mode_vrefresh(&crtc->mode);
+ if (pi->refresh_rate == 0)
+ pi->refresh_rate = 60;
+ }
break;
}
}
@@ -363,6 +366,8 @@ static void rs780_program_at(struct radeon_device *rdev)
{
struct igp_power_info *pi = rs780_get_pi(rdev);

+ WARN_ON(pi->refresh_rate == 0);
+
WREG32(FVTHROT_TARGET_REG, 30000000 / pi->refresh_rate);
WREG32(FVTHROT_CB1, 1000000 * 5 / pi->refresh_rate);
WREG32(FVTHROT_CB2, 1000000 * 10 / pi->refresh_rate);

base-commit: a5640267d6d35b89ebe6418da90a952a247215a5
--
2.43.0