Message ID | 20250308195451.14853-1-v.shevtsov@mt-integration.ru (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | drm/mgag200: fix division by zero in mgag200_g200_pixpllc_atomic_check() | expand |
diff --git a/drivers/gpu/drm/mgag200/mgag200_g200.c b/drivers/gpu/drm/mgag200/mgag200_g200.c index f874e2949840..484b22930ce1 100644 --- a/drivers/gpu/drm/mgag200/mgag200_g200.c +++ b/drivers/gpu/drm/mgag200/mgag200_g200.c @@ -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;
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. 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") Signed-off-by: Vitaliy Shevtsov <v.shevtsov@mt-integration.ru> --- drivers/gpu/drm/mgag200/mgag200_g200.c | 4 ++++ 1 file changed, 4 insertions(+)