[PATCH] fbdev: via: Fix potential divide by zero in get_var_refresh

Alex Guo alexguo1023 at gmail.com
Sat Jun 14 04:57:39 UTC 2025


Variable var->pixclock can be set by user. In case it equals to
zero, divide by zero would occur in get_var_refresh.
Similar crashes have happened in other fbdev drivers. We fix this
by checking whether 'pixclock' is zero.

Similar commit: commit 16844e58704 ("video: fbdev: tridentfb:
Error out if 'pixclock' equals zero")

Signed-off-by: Alex Guo <alexguo1023 at gmail.com>
---
 drivers/video/fbdev/via/viafbdev.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/video/fbdev/via/viafbdev.c b/drivers/video/fbdev/via/viafbdev.c
index 6da5ae7d229a..5b58e93f8c28 100644
--- a/drivers/video/fbdev/via/viafbdev.c
+++ b/drivers/video/fbdev/via/viafbdev.c
@@ -179,6 +179,8 @@ static inline int get_var_refresh(struct fb_var_screeninfo *var)
 		+ var->hsync_len;
 	vtotal = var->upper_margin + var->yres + var->lower_margin
 		+ var->vsync_len;
+	if (!var->pixclock)
+		return -EINVAL;
 	return PICOS2KHZ(var->pixclock) * 1000 / (htotal * vtotal);
 }
 
-- 
2.34.1



More information about the dri-devel mailing list