Skip to content

Commit c2d9532

Browse files
RSmirnov512hdeller
authored andcommitted
fbmon: prevent division by zero in fb_videomode_from_videomode()
The expression htotal * vtotal can have a zero value on overflow. It is necessary to prevent division by zero like in fb_var_to_videomode(). Found by Linux Verification Center (linuxtesting.org) with Svace. Signed-off-by: Roman Smirnov <r.smirnov@omp.ru> Reviewed-by: Sergey Shtylyov <s.shtylyov@omp.ru> Signed-off-by: Helge Deller <deller@gmx.de>
1 parent 1526097 commit c2d9532

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/video/fbdev/core/fbmon.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ int fb_get_mode(int flags, u32 val, struct fb_var_screeninfo *var, struct fb_inf
13111311
int fb_videomode_from_videomode(const struct videomode *vm,
13121312
struct fb_videomode *fbmode)
13131313
{
1314-
unsigned int htotal, vtotal;
1314+
unsigned int htotal, vtotal, total;
13151315

13161316
fbmode->xres = vm->hactive;
13171317
fbmode->left_margin = vm->hback_porch;
@@ -1344,8 +1344,9 @@ int fb_videomode_from_videomode(const struct videomode *vm,
13441344
vtotal = vm->vactive + vm->vfront_porch + vm->vback_porch +
13451345
vm->vsync_len;
13461346
/* prevent division by zero */
1347-
if (htotal && vtotal) {
1348-
fbmode->refresh = vm->pixelclock / (htotal * vtotal);
1347+
total = htotal * vtotal;
1348+
if (total) {
1349+
fbmode->refresh = vm->pixelclock / total;
13491350
/* a mode must have htotal and vtotal != 0 or it is invalid */
13501351
} else {
13511352
fbmode->refresh = 0;

0 commit comments

Comments
 (0)