public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/radeon/rs780: prevent division by zero in refresh rate calculation
@ 2026-04-28 19:03 Evgenii Burenchev
  2026-04-29 19:04 ` kernel test robot
  2026-04-29 21:46 ` kernel test robot
  0 siblings, 2 replies; 4+ messages in thread
From: Evgenii Burenchev @ 2026-04-28 19:03 UTC (permalink / raw)
  To: stable, Greg Kroah-Hartman
  Cc: Evgenii Burenchev, alexander.deucher, christian.koenig, airlied,
	simona, amd-gfx, dri-devel, linux-kernel

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.

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

diff --git a/drivers/gpu/drm/radeon/rs780_dpm.c b/drivers/gpu/drm/radeon/rs780_dpm.c
index 64bb4cafb8b5..fe45b7dac9f4 100644
--- a/drivers/gpu/drm/radeon/rs780_dpm.c
+++ b/drivers/gpu/drm/radeon/rs780_dpm.c
@@ -65,6 +65,8 @@ static void rs780_get_pm_mode_parameters(struct radeon_device *rdev)
 			pi->crtc_id = radeon_crtc->crtc_id;
 			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 +365,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);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/radeon/rs780: prevent division by zero in refresh rate calculation
  2026-04-28 19:03 [PATCH] drm/radeon/rs780: prevent division by zero in refresh rate calculation Evgenii Burenchev
@ 2026-04-29 19:04 ` kernel test robot
  2026-04-29 21:46 ` kernel test robot
  1 sibling, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-04-29 19:04 UTC (permalink / raw)
  To: Evgenii Burenchev, stable, Greg Kroah-Hartman
  Cc: oe-kbuild-all, Evgenii Burenchev, alexander.deucher,
	christian.koenig, airlied, simona, amd-gfx, dri-devel,
	linux-kernel

Hi Evgenii,

kernel test robot noticed the following build warnings:

[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on linus/master v7.1-rc1 next-20260428]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Evgenii-Burenchev/drm-radeon-rs780-prevent-division-by-zero-in-refresh-rate-calculation/20260429-055830
base:   https://gitlab.freedesktop.org/drm/misc/kernel.git drm-misc-next
patch link:    https://lore.kernel.org/r/20260428190318.34413-1-evg28bur%40yandex.ru
patch subject: [PATCH] drm/radeon/rs780: prevent division by zero in refresh rate calculation
config: parisc-defconfig (https://download.01.org/0day-ci/archive/20260430/202604300247.Gzeia1bh-lkp@intel.com/config)
compiler: hppa-linux-gcc (GCC) 15.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260430/202604300247.Gzeia1bh-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202604300247.Gzeia1bh-lkp@intel.com/

All warnings (new ones prefixed by >>):

   drivers/gpu/drm/radeon/rs780_dpm.c: In function 'rs780_get_pm_mode_parameters':
>> drivers/gpu/drm/radeon/rs780_dpm.c:66:25: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
      66 |                         if (crtc->mode.htotal && crtc->mode.vtotal)
         |                         ^~
   drivers/gpu/drm/radeon/rs780_dpm.c:68:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
      68 |                                 if (pi->refresh_rate == 0)
         |                                 ^~


vim +/if +66 drivers/gpu/drm/radeon/rs780_dpm.c

9d67006e6ebc6c Alex Deucher      2013-04-12  48  
9d67006e6ebc6c Alex Deucher      2013-04-12  49  static void rs780_get_pm_mode_parameters(struct radeon_device *rdev)
9d67006e6ebc6c Alex Deucher      2013-04-12  50  {
9d67006e6ebc6c Alex Deucher      2013-04-12  51  	struct igp_power_info *pi = rs780_get_pi(rdev);
9d67006e6ebc6c Alex Deucher      2013-04-12  52  	struct radeon_mode_info *minfo = &rdev->mode_info;
9d67006e6ebc6c Alex Deucher      2013-04-12  53  	struct drm_crtc *crtc;
9d67006e6ebc6c Alex Deucher      2013-04-12  54  	struct radeon_crtc *radeon_crtc;
9d67006e6ebc6c Alex Deucher      2013-04-12  55  	int i;
9d67006e6ebc6c Alex Deucher      2013-04-12  56  
9d67006e6ebc6c Alex Deucher      2013-04-12  57  	/* defaults */
9d67006e6ebc6c Alex Deucher      2013-04-12  58  	pi->crtc_id = 0;
9d67006e6ebc6c Alex Deucher      2013-04-12  59  	pi->refresh_rate = 60;
9d67006e6ebc6c Alex Deucher      2013-04-12  60  
9d67006e6ebc6c Alex Deucher      2013-04-12  61  	for (i = 0; i < rdev->num_crtc; i++) {
9d67006e6ebc6c Alex Deucher      2013-04-12  62  		crtc = (struct drm_crtc *)minfo->crtcs[i];
9d67006e6ebc6c Alex Deucher      2013-04-12  63  		if (crtc && crtc->enabled) {
9d67006e6ebc6c Alex Deucher      2013-04-12  64  			radeon_crtc = to_radeon_crtc(crtc);
9d67006e6ebc6c Alex Deucher      2013-04-12  65  			pi->crtc_id = radeon_crtc->crtc_id;
9d67006e6ebc6c Alex Deucher      2013-04-12 @66  			if (crtc->mode.htotal && crtc->mode.vtotal)
c3eaa088277709 Alex Deucher      2013-09-13  67  				pi->refresh_rate = drm_mode_vrefresh(&crtc->mode);
0d99a77de43b3f Evgenii Burenchev 2026-04-28  68  				if (pi->refresh_rate == 0)
0d99a77de43b3f Evgenii Burenchev 2026-04-28  69  					pi->refresh_rate = 60;
9d67006e6ebc6c Alex Deucher      2013-04-12  70  			break;
9d67006e6ebc6c Alex Deucher      2013-04-12  71  		}
9d67006e6ebc6c Alex Deucher      2013-04-12  72  	}
9d67006e6ebc6c Alex Deucher      2013-04-12  73  }
9d67006e6ebc6c Alex Deucher      2013-04-12  74  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] drm/radeon/rs780: prevent division by zero in refresh rate calculation
  2026-04-28 19:03 [PATCH] drm/radeon/rs780: prevent division by zero in refresh rate calculation Evgenii Burenchev
  2026-04-29 19:04 ` kernel test robot
@ 2026-04-29 21:46 ` kernel test robot
  1 sibling, 0 replies; 4+ messages in thread
From: kernel test robot @ 2026-04-29 21:46 UTC (permalink / raw)
  To: Evgenii Burenchev, stable, Greg Kroah-Hartman
  Cc: llvm, oe-kbuild-all, Evgenii Burenchev, alexander.deucher,
	christian.koenig, airlied, simona, amd-gfx, dri-devel,
	linux-kernel

Hi Evgenii,

kernel test robot noticed the following build warnings:

[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on linus/master v7.1-rc1 next-20260429]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Evgenii-Burenchev/drm-radeon-rs780-prevent-division-by-zero-in-refresh-rate-calculation/20260429-055830
base:   https://gitlab.freedesktop.org/drm/misc/kernel.git drm-misc-next
patch link:    https://lore.kernel.org/r/20260428190318.34413-1-evg28bur%40yandex.ru
patch subject: [PATCH] drm/radeon/rs780: prevent division by zero in refresh rate calculation
config: riscv-defconfig (https://download.01.org/0day-ci/archive/20260430/202604300508.yXci8rey-lkp@intel.com/config)
compiler: clang version 23.0.0git (https://github.com/llvm/llvm-project 5bac06718f502014fade905512f1d26d578a18f3)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260430/202604300508.yXci8rey-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202604300508.yXci8rey-lkp@intel.com/

All warnings (new ones prefixed by >>):

>> drivers/gpu/drm/radeon/rs780_dpm.c:68:5: warning: misleading indentation; statement is not part of the previous 'if' [-Wmisleading-indentation]
      68 |                                 if (pi->refresh_rate == 0)
         |                                 ^
   drivers/gpu/drm/radeon/rs780_dpm.c:66:4: note: previous statement is here
      66 |                         if (crtc->mode.htotal && crtc->mode.vtotal)
         |                         ^
   1 warning generated.


vim +/if +68 drivers/gpu/drm/radeon/rs780_dpm.c

    48	
    49	static void rs780_get_pm_mode_parameters(struct radeon_device *rdev)
    50	{
    51		struct igp_power_info *pi = rs780_get_pi(rdev);
    52		struct radeon_mode_info *minfo = &rdev->mode_info;
    53		struct drm_crtc *crtc;
    54		struct radeon_crtc *radeon_crtc;
    55		int i;
    56	
    57		/* defaults */
    58		pi->crtc_id = 0;
    59		pi->refresh_rate = 60;
    60	
    61		for (i = 0; i < rdev->num_crtc; i++) {
    62			crtc = (struct drm_crtc *)minfo->crtcs[i];
    63			if (crtc && crtc->enabled) {
    64				radeon_crtc = to_radeon_crtc(crtc);
    65				pi->crtc_id = radeon_crtc->crtc_id;
    66				if (crtc->mode.htotal && crtc->mode.vtotal)
    67					pi->refresh_rate = drm_mode_vrefresh(&crtc->mode);
  > 68					if (pi->refresh_rate == 0)
    69						pi->refresh_rate = 60;
    70				break;
    71			}
    72		}
    73	}
    74	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] drm/radeon/rs780: prevent division by zero in refresh rate calculation
@ 2026-04-30 10:46 Evgenii Burenchev
  0 siblings, 0 replies; 4+ messages in thread
From: Evgenii Burenchev @ 2026-04-30 10:46 UTC (permalink / raw)
  To: stable, Greg Kroah-Hartman
  Cc: Evgenii Burenchev, kernel test robot, alexander.deucher,
	christian.koenig, airlied, simona, amd-gfx, dri-devel,
	linux-kernel

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@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202604300508.yXci8rey-lkp@intel.com/

Signed-off-by: Evgenii Burenchev <evg28bur@yandex.ru>
---
 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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-04-30 10:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-28 19:03 [PATCH] drm/radeon/rs780: prevent division by zero in refresh rate calculation Evgenii Burenchev
2026-04-29 19:04 ` kernel test robot
2026-04-29 21:46 ` kernel test robot
  -- strict thread matches above, loose matches on Subject: below --
2026-04-30 10:46 Evgenii Burenchev

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox