From patchwork Sat Oct 14 12:14:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhang Shurong X-Patchwork-Id: 733783 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D0B15CDB465 for ; Sat, 14 Oct 2023 12:22:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233043AbjJNMWc (ORCPT ); Sat, 14 Oct 2023 08:22:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233033AbjJNMWb (ORCPT ); Sat, 14 Oct 2023 08:22:31 -0400 X-Greylist: delayed 448 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Sat, 14 Oct 2023 05:22:28 PDT Received: from out203-205-221-245.mail.qq.com (out203-205-221-245.mail.qq.com [203.205.221.245]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15CA0A9 for ; Sat, 14 Oct 2023 05:22:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foxmail.com; s=s201512; t=1697286145; bh=YQheIxJjOau1s9uk+wO2dkdpHL1+wExdCD1+23pg5Oc=; h=From:To:Cc:Subject:Date; b=PUkeA7PlH/JWuKrBQiUXxDdhK7tYU5DJUHzhZ6WFGlgRqCMlgcThNSgE/INJHu7+Z f+6KTkFGR2brHCouXenzUm8Tg+LVqiPcV6estqxaBGGbcz21L19QavvX3Xkz+7GHGf Bva/JHWlonPaG/VOBowoNmTy2EpbWr+1ADYmtkqQ= Received: from KernelDevBox.byted.org ([180.184.49.4]) by newxmesmtplogicsvrszb9-0.qq.com (NewEsmtp) with SMTP id 3B6A8E9A; S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dGM6Ok9boHcJb3JuvvMCpr0qOVHOq3AyYnD1RGzF 0YUZGzbA== X-QQ-XMRINFO: NS+P29fieYNw95Bth2bWPxk= From: Zhang Shurong To: daniel@ffwll.ch Cc: deller@gmx.de, linux-fbdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Zhang Shurong Subject: [PATCH] fbdev: fbmon: fix potential divide error in fb_validate_mode Date: Sat, 14 Oct 2023 20:14:53 +0800 X-OQ-MSGID: <20231014121453.3034941-1-zhang_shurong@foxmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org We can easily use FBIOPUT_VSCREENINFO set fb_var_screeninfo, so it's possible for a divide by zero error to occur. Fix this by making sure the divisor is non-zero before the computation. Signed-off-by: Zhang Shurong --- drivers/video/fbdev/core/fbmon.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/video/fbdev/core/fbmon.c b/drivers/video/fbdev/core/fbmon.c index 79e5bfbdd34c..bdd15b8e3a71 100644 --- a/drivers/video/fbdev/core/fbmon.c +++ b/drivers/video/fbdev/core/fbmon.c @@ -1470,6 +1470,9 @@ int fb_validate_mode(const struct fb_var_screeninfo *var, struct fb_info *info) if (var->vmode & FB_VMODE_DOUBLE) vtotal *= 2; + if (!htotal || !vtotal) + return -EINVAL; + hfreq = pixclock/htotal; hfreq = (hfreq + 500) / 1000 * 1000;