From patchwork Wed Jun 12 09:54:33 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: 13694724 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 F3525C2BA16 for ; Wed, 12 Jun 2024 09:54:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7B98410E818; Wed, 12 Jun 2024 09:54:41 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="CQqivRdG"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.16]) by gabe.freedesktop.org (Postfix) with ESMTPS id D216410E809; Wed, 12 Jun 2024 09:54:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1718186075; x=1749722075; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=To9DU10Zhe8E/I7Qn0M/0vjZR5mT3ISO+qho+zaXReQ=; b=CQqivRdG4z4AL/n+UqnXP8UZH2dfVtDO/cnuFrwzDUHGlsqnD3zkDD1g WKzQbhfGuwSR6+GaKURE07j3oaoaMUoHM7PsbXCcdhyWzWFbVdhlV8Kms Upidd7Y2PLKl1MeTKpZH59dNFYgUd8Ge0sWgswNP7BHWApSwo+GmLtxh1 H1X9P1KaE+lIAWmCzZM8wQ1UeARkjgmQDke50cvDR1FXdYjI8F7Of51lR NjEGZLXF+qWA2Zz8CxCb/wzuE8NGyx9Trzho+O+zchmqzOVYfaAHYEHMr BnMWKisXxYOUJ1PVYnaLi4I4+bOwICJ1sZxTpWnC4Ph8tIkoyUyabmd8q g==; X-CSE-ConnectionGUID: j3tTnqTJQ3GkoGQibZ+wLA== X-CSE-MsgGUID: sUzkI1tAQTugkpOG5jj8eQ== X-IronPort-AV: E=McAfee;i="6600,9927,11100"; a="15068941" X-IronPort-AV: E=Sophos;i="6.08,232,1712646000"; d="scan'208";a="15068941" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa108.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jun 2024 02:54:34 -0700 X-CSE-ConnectionGUID: qQ7ze+SwRuaM3SfJ8iReew== X-CSE-MsgGUID: fNWL6necQ5uUdNH1llGPxg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.08,232,1712646000"; d="scan'208";a="40441635" Received: from mgolanimitul-x299-ud4-pro.iind.intel.com ([10.190.239.114]) by orviesa007.jf.intel.com with ESMTP; 12 Jun 2024 02:54:32 -0700 From: Mitul Golani To: intel-gfx@lists.freedesktop.org, intel-xe@lists.freedesktop.org, dri-devel@lists.freedesktop.org Cc: mitulkumar.ajitkumar.golani@intel.com, ankit.k.nautiyal@intel.com, suraj.kandpal@intel.com, jani.nikula@linux.intel.com, rodrigo.vivi@intel.com, sfr@canb.auug.org.au Subject: [PATCH 3/3] drm/i915/display: Update calculation to avoid overflow Date: Wed, 12 Jun 2024 15:24:33 +0530 Message-ID: <20240612095433.323342-4-mitulkumar.ajitkumar.golani@intel.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240612095433.323342-1-mitulkumar.ajitkumar.golani@intel.com> References: <20240612095433.323342-1-mitulkumar.ajitkumar.golani@intel.com> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 dc9cf7ddafe9..5da9d5b9936e 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;