Skip to contentSkip to conversation

drm/mgag200: fix division by zero in mgag200_g200_pixpllc_atomic_check()

PATCH New Vitaliy Shevtsov 1 participant 1 message Mar 8, 2025

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

PATCH v2 1/1 drm/mgag200: fix division by zero in mgag200_g200_pixpllc_atomic_check()

There is a small chance to perform a division by zero. According to the driver code, clock may have a value less than (p_clk_min >> 3). p_clk_min itself may have a value up to 2032000 in case of a BIOS PINS version 5.

If this is the case, then f_vco gets the value greater than delta and the condition (tmp_delta < delta) is always false because the variable computed is always less than f_vco. This was tested with ref_clk = 27050 and 14318.

As a result variable m remains zero and then is used as a divisor.

Check if m is zero before performing a possibly unsafe division.

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

Fixes 877507bb954e ("drm/mgag200: Provide per-device callbacks for PIXPLLC")

---
v2: Change the commit description to mention both ref_clk values 27050 and

    14318.
 drivers/gpu/drm/mgag200/mgag200_g200.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/gpu/drm/mgag200/mgag200_g200.c +4 -0
index f874e2949840..484b22930ce1 100644
@@ -115,6 +115,10 @@ static int mgag200_g200_pixpllc_atomic_check(struct drm_crtc *crtc, struct drm_a
 			}
 		}
 	}
+
+	if (!m)
+		return -EINVAL;
+
 	f_vco = ref_clk * n / m;
 	if (f_vco < 100000)
 		s = 0;
Signature · 1 line
2.48.1