diff mbox series

fbdev: via: Fix potential divide by zero

Message ID 20250614005428.3112421-1-alexguo1023@gmail.com
State New
Headers show
Series fbdev: via: Fix potential divide by zero | expand

Commit Message

Alex Guo June 14, 2025, 12:54 a.m. UTC
Variable var->pixclock can be set by user. In case it equals to
zero, divide by zero would occur in viafb_dvi_set_mode. Similar
crashes have happened in other fbdev drivers. We fix this by
checking whether 'pixclock' is zero.

Signed-off-by: Alex Guo <alexguo1023@gmail.com>
---
 drivers/video/fbdev/via/dvi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/drivers/video/fbdev/via/dvi.c b/drivers/video/fbdev/via/dvi.c
index 27990a73bfa3..0ba248b7b360 100644
--- a/drivers/video/fbdev/via/dvi.c
+++ b/drivers/video/fbdev/via/dvi.c
@@ -166,7 +166,7 @@  void viafb_dvi_set_mode(const struct fb_var_screeninfo *var,
 	int maxPixelClock;
 
 	maxPixelClock = viaparinfo->shared->tmds_setting_info.max_pixel_clock;
-	if (maxPixelClock && PICOS2KHZ(var->pixclock) / 1000 > maxPixelClock) {
+	if (maxPixelClock && var->pixclock && PICOS2KHZ(var->pixclock) / 1000 > maxPixelClock) {
 		rb_mode = viafb_get_best_rb_mode(var->xres, var->yres, 60);
 		if (rb_mode)
 			viafb_fill_var_timing_info(&dvi_var, rb_mode);