<div dir="ltr"><div>> bpp = var->bits_per_pixel;<br>> + if (!var->pixclock){<br>> + dev_err(info->device, "pixclock must not be zero\n");<br>> + return -EINVAL;<br>> + }<br>> switch (bpp) {<br>> case 1 ... 8:<br>> bpp = 8;</div><div><br></div><div>The value used in the switch condition is var->bits_per_pixel. I can not find a deterministic relationship between var->bits_per_pixel and var->pixclock.</div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Sun, Jun 15, 2025 at 4:30 AM David Laight <<a href="mailto:david.laight.linux@gmail.com">david.laight.linux@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Sat, 14 Jun 2025 01:18:37 -0400<br>
Alex Guo <<a href="mailto:alexguo1023@gmail.com" target="_blank">alexguo1023@gmail.com</a>> wrote:<br>
<br>
> Variable var->pixclock can be set by user. In case it equals to<br>
> zero, divide by zero would occur in 4 switch branches in<br>
> i740fb_decode_var.<br>
> Similar crashes have happened in other fbdev drivers. We fix this<br>
> by checking whether 'pixclock' is zero.<br>
<br>
Doesn't it already hit the 'default' clause of the switch statement?<br>
<br>
David<br>
<br>
> <br>
> Similar commit: commit 16844e58704 ("video: fbdev: tridentfb:<br>
> Error out if 'pixclock' equals zero")<br>
> <br>
> Signed-off-by: Alex Guo <<a href="mailto:alexguo1023@gmail.com" target="_blank">alexguo1023@gmail.com</a>><br>
> ---<br>
> drivers/video/fbdev/i740fb.c | 4 ++++<br>
> 1 file changed, 4 insertions(+)<br>
> <br>
> diff --git a/drivers/video/fbdev/i740fb.c b/drivers/video/fbdev/i740fb.c<br>
> index 9b74dae71472..861e9e397b4e 100644<br>
> --- a/drivers/video/fbdev/i740fb.c<br>
> +++ b/drivers/video/fbdev/i740fb.c<br>
> @@ -419,6 +419,10 @@ static int i740fb_decode_var(const struct fb_var_screeninfo *var,<br>
> <br>
> <br>
> bpp = var->bits_per_pixel;<br>
> + if (!var->pixclock){<br>
> + dev_err(info->device, "pixclock must not be zero\n");<br>
> + return -EINVAL;<br>
> + }<br>
> switch (bpp) {<br>
> case 1 ... 8:<br>
> bpp = 8;<br>
<br>
</blockquote></div></div>