Skip to contentSkip to conversation

drm/mgag200: Apply upper limit for clock variable

PATCH Superseded Murad Masimov 2 participants 2 messages Nov 11, 2024

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/mgag200: Apply upper limit for clock variable

If the value of the clock variable is higher than 800000, the value of the variable m, which is used as a divisor, will remain zero, because (clock * testp) will be higher than vcomax in every loop iteration, which leads to skipping every iteration and leaving variable m unmodified.

Clamp value of the clock variable to the upper limit, the same way it's done with the lower limit.

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

Fixes 877507bb954e ("drm/mgag200: Provide per-device callbacks for PIXPLLC")
---
 drivers/gpu/drm/mgag200/mgag200_g200se.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/mgag200/mgag200_g200se.c +2 -0
index 7a32d3b1d226..69402a591f59 100644
@@ -218,6 +218,8 @@ static int mgag200_g200se_04_pixpllc_atomic_check(struct drm_crtc *crtc,
 
 	if (clock < 25000)
 		clock = 25000;
+	else if (clock > 800000)
+		clock = 800000;
 	clock = clock * 2;
 
 	/* Permited delta is 0.5% as VESA Specification */

--
2.39.2

#1 lore raw

Le 11/11/2024 à 14:46, Murad Masimov a écrit :

Quoted 21 lines

If the value of the clock variable is higher than 800000, the value of the variable m, which is used as a divisor, will remain zero, because (clock * testp) will be higher than vcomax in every loop iteration, which leads to skipping every iteration and leaving variable m unmodified.

Clamp value of the clock variable to the upper limit, the same way it's done with the lower limit.

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

Fixes 877507bb954e ("drm/mgag200: Provide per-device callbacks for PIXPLLC")
---
  drivers/gpu/drm/mgag200/mgag200_g200se.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/gpu/drm/mgag200/mgag200_g200se.c +0 -0
index 7a32d3b1d226..69402a591f59 100644

drivers/gpu/drm/mgag200/mgag200_g200se.c static int mgag200_g200se_04_pixpllc_atomic_check(struct drm_crtc *crtc, · line 222

Quoted 5 lines
drivers/gpu/drm/mgag200/mgag200_g200se.c +2 -0
@@ -218,6 +218,8 @@ static int mgag200_g200se_04_pixpllc_atomic_check(struct drm_crtc *crtc,
 
  	if (clock < 25000)
  		clock = 25000;
+	else if (clock > 800000)
+		clock = 800000;

Maybe:

	clock = clamp(clock, 25000, 800000);

to be less verbose?

CJ

Quoted 8 lines
drivers/gpu/drm/mgag200/mgag200_g200se.c +0 -1
  	clock = clock * 2;
 
  	/* Permited delta is 0.5% as VESA Specification */
--

2.39.2