diff mbox series

fbdev: Fix potential divide by zero

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

Commit Message

Alex Guo June 14, 2025, 5:29 a.m. UTC
Variable var->pixclock can be set by user. In case it equals to
zero, divide by zero would occur in acornfb_validate_timing.
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@gmail.com>
---
 drivers/video/fbdev/acornfb.c | 2 ++
 1 file changed, 2 insertions(+)
diff mbox series

Patch

diff --git a/drivers/video/fbdev/acornfb.c b/drivers/video/fbdev/acornfb.c
index f0600f6ca254..2dc0e64137e5 100644
--- a/drivers/video/fbdev/acornfb.c
+++ b/drivers/video/fbdev/acornfb.c
@@ -421,6 +421,8 @@  acornfb_validate_timing(struct fb_var_screeninfo *var,
 	 * No need to do long long divisions or anything
 	 * like that if you factor it correctly
 	 */
+	if (!var->pixclock)
+		return -EINVAL;
 	hs = 1953125000 / var->pixclock;
 	hs = hs * 512 /
 	     (var->xres + var->left_margin + var->right_margin + var->hsync_len);