linux-fbdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alex Guo <alexguo1023@gmail.com>
To: deller@gmx.de
Cc: alexguo1023@gmail.com, linux-fbdev@vger.kernel.org,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org
Subject: [PATCH] fbdev: sm501: Fix potential divide by zero
Date: Sat, 14 Jun 2025 01:11:00 -0400	[thread overview]
Message-ID: <20250614051100.3501316-1-alexguo1023@gmail.com> (raw)

Variable var->pixclock can be set by user. In case it equals to
zero, divide by zero would occur in sm501fb_set_par_common.
Similar crashes have happened in other fbdev drivers.
We cannot find the default vaild value for pixclock for driver
sm501, so 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/sm501fb.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/video/fbdev/sm501fb.c b/drivers/video/fbdev/sm501fb.c
index ed6f4f43e2d5..a294b4e1c4aa 100644
--- a/drivers/video/fbdev/sm501fb.c
+++ b/drivers/video/fbdev/sm501fb.c
@@ -506,7 +506,9 @@ static int sm501fb_set_par_common(struct fb_info *info,
 			fbi->regs + head_addr);
 
 	/* program CRT clock  */
-
+	
+	if (!var->pixclock)
+		return -EINVAL;
 	pixclock = sm501fb_ps_to_hz(var->pixclock);
 
 	sm501pixclock = sm501_set_clock(fbi->dev->parent, clock_type,
-- 
2.34.1


                 reply	other threads:[~2025-06-14  5:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250614051100.3501316-1-alexguo1023@gmail.com \
    --to=alexguo1023@gmail.com \
    --cc=deller@gmx.de \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-fbdev@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).