From patchwork Fri Nov 29 04:26:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ville Syrjala X-Patchwork-Id: 13888405 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 00149D70E16 for ; Fri, 29 Nov 2024 04:26:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3A45610ED8E; Fri, 29 Nov 2024 04:26:37 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="gWjQXRQ5"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) by gabe.freedesktop.org (Postfix) with ESMTPS id 396B610ED8E; Fri, 29 Nov 2024 04:26:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1732854396; x=1764390396; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=0s4InliC6VAvu6bYSTO0TI4H7F1qiAT6qTeTPxYWch4=; b=gWjQXRQ56H7LPXTqQtBE82k25yMFSM+d6FB44vL6WxxQ8ShhmsSXg4o2 4JqS86SsHKTEuo9AwQkM2phpeZbHBm5OdPMkg4/jgn3/InHWvw3HnXDO/ GBaXhlB7dfB44kvbOoaIqAwlR6yDTT2/T9jnr5KpX6FYu1DCNV8OR7zuI 8wVppq1bImebYINpWXzlsQjZsgbQ5x1DMGP4nQb6THXBcVq4pEQsWa6ca TpsuF/SYwsKFOBLSmE9YO66rldJBpwFCyq4hyEf9CZR3JfS9i0NGqCvkQ 5O5c97soC7QI9RWpVTuHoGMqSNxQ4dYO/H83oVHhInJXXNobB3JyLeDhg A==; X-CSE-ConnectionGUID: h0o2YIUSTIeAzlBuyTSbsg== X-CSE-MsgGUID: 35cylbsGRCKlXTlD8irvig== X-IronPort-AV: E=McAfee;i="6700,10204,11270"; a="33028017" X-IronPort-AV: E=Sophos;i="6.12,194,1728975600"; d="scan'208";a="33028017" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Nov 2024 20:26:36 -0800 X-CSE-ConnectionGUID: rpl4Y5T+Thy0tlTqzqppyw== X-CSE-MsgGUID: TxGKJZhHQqqP+fHo5jULyA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,194,1728975600"; d="scan'208";a="92567174" Received: from stinkpipe.fi.intel.com (HELO stinkbox) ([10.237.72.74]) by fmviesa008.fm.intel.com with SMTP; 28 Nov 2024 20:26:33 -0800 Received: by stinkbox (sSMTP sendmail emulation); Fri, 29 Nov 2024 06:26:32 +0200 From: Ville Syrjala To: dri-devel@lists.freedesktop.org Cc: intel-gfx@lists.freedesktop.org, stable@vger.kernel.org, syzbot+622bba18029bcde672e1@syzkaller.appspotmail.com Subject: [PATCH 1/2] drm/modes: Avoid divide by zero harder in drm_mode_vrefresh() Date: Fri, 29 Nov 2024 06:26:28 +0200 Message-ID: <20241129042629.18280-2-ville.syrjala@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241129042629.18280-1-ville.syrjala@linux.intel.com> References: <20241129042629.18280-1-ville.syrjala@linux.intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Ville Syrjälä drm_mode_vrefresh() is trying to avoid divide by zero by checking whether htotal or vtotal are zero. But we may still end up with a div-by-zero of vtotal*htotal*... Cc: stable@vger.kernel.org Reported-by: syzbot+622bba18029bcde672e1@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=622bba18029bcde672e1 Signed-off-by: Ville Syrjälä --- drivers/gpu/drm/drm_modes.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c index 6ba167a33461..71573b85d924 100644 --- a/drivers/gpu/drm/drm_modes.c +++ b/drivers/gpu/drm/drm_modes.c @@ -1287,14 +1287,11 @@ EXPORT_SYMBOL(drm_mode_set_name); */ int drm_mode_vrefresh(const struct drm_display_mode *mode) { - unsigned int num, den; + unsigned int num = 1, den = 1; if (mode->htotal == 0 || mode->vtotal == 0) return 0; - num = mode->clock; - den = mode->htotal * mode->vtotal; - if (mode->flags & DRM_MODE_FLAG_INTERLACE) num *= 2; if (mode->flags & DRM_MODE_FLAG_DBLSCAN) @@ -1302,6 +1299,12 @@ int drm_mode_vrefresh(const struct drm_display_mode *mode) if (mode->vscan > 1) den *= mode->vscan; + if (check_mul_overflow(mode->clock, num, &num)) + return 0; + + if (check_mul_overflow(mode->htotal * mode->vtotal, den, &den)) + return 0; + return DIV_ROUND_CLOSEST_ULL(mul_u32_u32(num, 1000), den); } EXPORT_SYMBOL(drm_mode_vrefresh); From patchwork Fri Nov 29 04:26:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ville Syrjala X-Patchwork-Id: 13888406 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 gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 03F1BD70E1A for ; Fri, 29 Nov 2024 04:26:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7C0C910ED9B; Fri, 29 Nov 2024 04:26:40 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="URzILDjO"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2716210ED94; Fri, 29 Nov 2024 04:26:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1732854399; x=1764390399; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=wji6YjIlnqf6O8bWabr5lR8AcVZ13iQ7V74zkDuDvts=; b=URzILDjO7cwwatlmsJEMjKGvxrSb7hQJFqoa6NYZqvE9Vd8XJ20ng0ym j6Xpkdc/8/E7MvNmvTJzoFVjmbpb+3EO5RBJnxt0aPLVfG6MQnfwbiW5b 3Sg1kNr39kCdAWKj6/bBIxGjgorT1/8er2uPLX52uGOXQ9oj7NvGSqSWW WYFr3VJt6anFdc6x6f9m3AOCYNh+KQYMhrZmPzFkUZOD8DagME+qzh+F7 fnCwgIvRBIwRCsCC/KNh53oCtlm+4nx+Jf33HTPcLXRd+fB1hwN1TSiWb PYU/PDfvlx5Lm7GslZdCdYlXoCknzWnRjkZAhxJsNJHJ8AmiYSdxXP4nJ g==; X-CSE-ConnectionGUID: 3lAQFvAlQhCBFVlH80GdAA== X-CSE-MsgGUID: Q9mllJGtQ4anVSwkNQ2QlQ== X-IronPort-AV: E=McAfee;i="6700,10204,11270"; a="33028021" X-IronPort-AV: E=Sophos;i="6.12,194,1728975600"; d="scan'208";a="33028021" Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Nov 2024 20:26:39 -0800 X-CSE-ConnectionGUID: TEDfzqKDS2iSEsNmY6AuUQ== X-CSE-MsgGUID: C1bjbqXhRTGF/Fy0ApUm0Q== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,194,1728975600"; d="scan'208";a="92567177" Received: from stinkpipe.fi.intel.com (HELO stinkbox) ([10.237.72.74]) by fmviesa008.fm.intel.com with SMTP; 28 Nov 2024 20:26:37 -0800 Received: by stinkbox (sSMTP sendmail emulation); Fri, 29 Nov 2024 06:26:36 +0200 From: Ville Syrjala To: dri-devel@lists.freedesktop.org Cc: intel-gfx@lists.freedesktop.org Subject: [PATCH 2/2] drm/modes: Fix drm_mode_vrefres() docs Date: Fri, 29 Nov 2024 06:26:29 +0200 Message-ID: <20241129042629.18280-3-ville.syrjala@linux.intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241129042629.18280-1-ville.syrjala@linux.intel.com> References: <20241129042629.18280-1-ville.syrjala@linux.intel.com> MIME-Version: 1.0 X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" From: Ville Syrjälä We no longer store a cache vrefresh value in the mode. Remove the stale information from drm_vrefresh() docs. Signed-off-by: Ville Syrjälä --- drivers/gpu/drm/drm_modes.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c index 71573b85d924..e72f855fc495 100644 --- a/drivers/gpu/drm/drm_modes.c +++ b/drivers/gpu/drm/drm_modes.c @@ -1282,8 +1282,7 @@ EXPORT_SYMBOL(drm_mode_set_name); * @mode: mode * * Returns: - * @modes's vrefresh rate in Hz, rounded to the nearest integer. Calculates the - * value first if it is not yet set. + * @modes's vrefresh rate in Hz, rounded to the nearest integer. */ int drm_mode_vrefresh(const struct drm_display_mode *mode) {