Unverified Commit 34bea3c3 authored by openeuler-ci-bot's avatar openeuler-ci-bot Committed by Gitee
Browse files

!15020 drm/modes: Avoid divide by zero harder in drm_mode_vrefresh()

parents fdc8c83a 70b3778f
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -1285,14 +1285,11 @@ EXPORT_SYMBOL(drm_mode_set_name);
 */
int drm_mode_vrefresh(const struct drm_display_mode *mode)
{
	unsigned int num, den;
	unsigned int num = 1, den = 1;

	if (mode->htotal == 0 || mode->vtotal == 0)
		return 0;

	num = mode->clock;
	den = mode->htotal * mode->vtotal;

	if (mode->flags & DRM_MODE_FLAG_INTERLACE)
		num *= 2;
	if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
@@ -1300,6 +1297,12 @@ int drm_mode_vrefresh(const struct drm_display_mode *mode)
	if (mode->vscan > 1)
		den *= mode->vscan;

	if (check_mul_overflow(mode->clock, num, &num))
		return 0;

	if (check_mul_overflow(mode->htotal * mode->vtotal, den, &den))
		return 0;

	return DIV_ROUND_CLOSEST_ULL(mul_u32_u32(num, 1000), den);
}
EXPORT_SYMBOL(drm_mode_vrefresh);