From patchwork Fri Jun 14 03:40:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Golani, Mitulkumar Ajitkumar" X-Patchwork-Id: 13697831 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 E2073C27C6E for ; Fri, 14 Jun 2024 03:40:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EFAC910EC0F; Fri, 14 Jun 2024 03:40:38 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="KNipTqwo"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id BBA0C10E068; Fri, 14 Jun 2024 03:40: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=1718336437; x=1749872437; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=OZBtXAMCtAdeOMqNCZ4pBFqxx7eEzPwFu88Hq+F5bS8=; b=KNipTqwoM8XqKRtv96e6B+f6XBGUQT1GlwSKcE51ijwv15vV4jFmugMU 6AX0EWZgMqzmD3a+ZhJPQy210GUKIz30yo+/hhq7CEHz60UcMQSn+HGDT KA2wvZSO4eIr6AD1tJbvADLJRQUbgzKuTF6bwdUwTiiZQG0PAE2wUBVVJ 5tKexrWCXhZXUnXv4GqbG1w1/uibcpEPwKKiFu4fR8iv8khuIILh5kuEN pA4vnYECIzPW5YQUnxYHEggu3mLX3UjIpLUIZwUrOvskCOQNYogBF+hKe 9eRmfJRQCCgB+gVA16SPsTY3oFvAeDbxrcg01JaOGuHlvhYDAX1dq+1M3 w==; X-CSE-ConnectionGUID: 59Cs99HcTESSFBH0IuGnwg== X-CSE-MsgGUID: NT6bxF3MS1W0yfr4cJdCCA== X-IronPort-AV: E=McAfee;i="6700,10204,11102"; a="15340918" X-IronPort-AV: E=Sophos;i="6.08,236,1712646000"; d="scan'208";a="15340918" Received: from fmviesa003.fm.intel.com ([10.60.135.143]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jun 2024 20:40:36 -0700 X-CSE-ConnectionGUID: 6tRhqG8gR+qXJmIRaiMRkw== X-CSE-MsgGUID: jl5gSU9xTqCp9BK3UlwgFQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,236,1712646000"; d="scan'208";a="44747509" Received: from mgolanimitul-x299-ud4-pro.iind.intel.com ([10.190.239.114]) by fmviesa003.fm.intel.com with ESMTP; 13 Jun 2024 20:40:34 -0700 From: Mitul Golani To: intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org Cc: mitulkumar.ajitkumar.golani@intel.com, ankit.k.nautiyal@intel.com, suraj.kandpal@intel.com, sfr@canb.auug.org.au Subject: [PATCH] drm/i915/display: Update calculation to avoid overflow Date: Fri, 14 Jun 2024 09:10:46 +0530 Message-ID: <20240614034046.375797-1-mitulkumar.ajitkumar.golani@intel.com> X-Mailer: git-send-email 2.45.2 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" Update calculation to avoid overflow. Fixes: 1676ecd303ac ("drm/i915: Compute CMRR and calculate vtotal") Cc: Mitul Golani Cc: Ankit Nautiyal Cc: Suraj Kandpal Cc: Jani Nikula Cc: Stephen Rothwell Signed-off-by: Mitul Golani Reviewed-by: Ankit Nautiyal --- drivers/gpu/drm/i915/display/intel_vrr.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/display/intel_vrr.c b/drivers/gpu/drm/i915/display/intel_vrr.c index eb5b62b54d32..6430da25957d 100644 --- a/drivers/gpu/drm/i915/display/intel_vrr.c +++ b/drivers/gpu/drm/i915/display/intel_vrr.c @@ -147,10 +147,11 @@ cmrr_get_vtotal(struct intel_crtc_state *crtc_state, bool video_mode_required) multiplier_n = 1000; } - crtc_state->cmrr.cmrr_n = - desired_refresh_rate * adjusted_mode->crtc_htotal * multiplier_n; - vtotal = (adjusted_mode->crtc_clock * 1000 * multiplier_n) / crtc_state->cmrr.cmrr_n; - adjusted_pixel_rate = adjusted_mode->crtc_clock * 1000 * multiplier_m; + crtc_state->cmrr.cmrr_n = mul_u32_u32(desired_refresh_rate * adjusted_mode->crtc_htotal, + multiplier_n); + vtotal = DIV_ROUND_UP_ULL(mul_u32_u32(adjusted_mode->crtc_clock * 1000, multiplier_n), + crtc_state->cmrr.cmrr_n); + adjusted_pixel_rate = mul_u32_u32(adjusted_mode->crtc_clock * 1000, multiplier_m); crtc_state->cmrr.cmrr_m = do_div(adjusted_pixel_rate, crtc_state->cmrr.cmrr_n); return vtotal;