Skip to contentSkip to conversation

drm/mgag200: Apply upper limit for clock variable

PATCH In review Murad Masimov 2 participants 2 messages Nov 15, 2024

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v3 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.

Return -EINVAL just after the loop, if m is still 0.

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

Fixes e829d7ef9f17 ("drm/mgag200: Add support for a new rev of G200e")
---
 drivers/gpu/drm/mgag200/mgag200_g200se.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/mgag200/mgag200_g200se.c +3 -0
index 7a32d3b1d226..4d65ead63d66 100644
@@ -249,6 +249,9 @@ static int mgag200_g200se_04_pixpllc_atomic_check(struct drm_crtc *crtc,
 		}
 	}
 
+	if (m == 0)
+		return -EINVAL;
+
 	fvv = pllreffreq * n / m;
 	fvv = (fvv - 800000) / 50000;
 	if (fvv > 15)

--
2.39.2

reviewer Reviewed-by on v3 1/1
#1 lore raw
Quoted 8 lines · Murad Masimov

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.

Return -EINVAL just after the loop, if m is still 0.

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

Thanks for this patch.

Quoted 24 lines
Fixes e829d7ef9f17 ("drm/mgag200: Add support for a new rev of G200e")
---
  drivers/gpu/drm/mgag200/mgag200_g200se.c | 3 +++
  1 file changed, 3 insertions(+)
drivers/gpu/drm/mgag200/mgag200_g200se.c +3 -1
index 7a32d3b1d226..4d65ead63d66 100644
@@ -249,6 +249,9 @@ static int mgag200_g200se_04_pixpllc_atomic_check(struct drm_crtc *crtc,
  		}
  	}
 
+	if (m == 0)
+		return -EINVAL;
+
  	fvv = pllreffreq * n / m;
  	fvv = (fvv - 800000) / 50000;
  	if (fvv > 15)
--

2.39.2