Skip to content

Commit 9398332

Browse files
committed
drm/modes: Avoid divide by zero harder in drm_mode_vrefresh()
drm_mode_vrefresh() is trying to avoid divide by zero by checking whether htotal or vtotal are zero. But we may still end up with a div-by-zero of vtotal*htotal*... Cc: [email protected] Reported-by: [email protected] Closes: https://syzkaller.appspot.com/bug?extid=622bba18029bcde672e1 Signed-off-by: Ville Syrjälä <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Reviewed-by: Jani Nikula <[email protected]>
1 parent 080b2e7 commit 9398332

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

drivers/gpu/drm/drm_modes.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1287,21 +1287,24 @@ EXPORT_SYMBOL(drm_mode_set_name);
12871287
*/
12881288
int drm_mode_vrefresh(const struct drm_display_mode *mode)
12891289
{
1290-
unsigned int num, den;
1290+
unsigned int num = 1, den = 1;
12911291

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

1295-
num = mode->clock;
1296-
den = mode->htotal * mode->vtotal;
1297-
12981295
if (mode->flags & DRM_MODE_FLAG_INTERLACE)
12991296
num *= 2;
13001297
if (mode->flags & DRM_MODE_FLAG_DBLSCAN)
13011298
den *= 2;
13021299
if (mode->vscan > 1)
13031300
den *= mode->vscan;
13041301

1302+
if (check_mul_overflow(mode->clock, num, &num))
1303+
return 0;
1304+
1305+
if (check_mul_overflow(mode->htotal * mode->vtotal, den, &den))
1306+
return 0;
1307+
13051308
return DIV_ROUND_CLOSEST_ULL(mul_u32_u32(num, 1000), den);
13061309
}
13071310
EXPORT_SYMBOL(drm_mode_vrefresh);

0 commit comments

Comments
 (0)