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 161DACD1292 for ; Thu, 4 Apr 2024 09:58:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A005311B25E; Thu, 4 Apr 2024 09:58:20 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=intel.com header.i=@intel.com header.b="D7a/4a3J"; dkim-atps=neutral Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.9]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7A34211B246 for ; Thu, 4 Apr 2024 09:58:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1712224696; x=1743760696; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ZtJctbHttsxo7hcyHdmYyRDi9NMbtujnAT7so/0W1Tc=; b=D7a/4a3JOwdHpQdvrT20XvgCADWaBczOHmlg7p7bfXg/hkOYttyt5Rzm XA1GgSTheW2tcbJEh0Nbsg5pG6nP+XKOemuSFN0upPPxD+vDnDDLlLqMs u+yki3sylQ6N+EXtAJdUfhw0upJKLGVedODOVzlhfIlNLNgOllZPqKBhq p5FvW6Ym8FtQLUwp4qpZREZmL+x5H0IDexG3i4OepIr9Fm9BmXf5Z6abD KBNmyMbZq1Zg8kDv8B8tZh+tmNlRkq3RV/buDGWjGD5ta+ehA2MnheX2u n9b2PxCg+643+VBQmgOulITeUdpqANb1YXdZgzuoYKrHtPfhG7TSZo8e8 A==; X-CSE-ConnectionGUID: N3wUwNdQRZCOK7ZG01G6dg== X-CSE-MsgGUID: Jf+qqEY7Sx+PykzlBa9bOQ== X-IronPort-AV: E=McAfee;i="6600,9927,11033"; a="18227773" X-IronPort-AV: E=Sophos;i="6.07,179,1708416000"; d="scan'208";a="18227773" Received: from orviesa005.jf.intel.com ([10.64.159.145]) by fmvoesa103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2024 02:58:16 -0700 X-CSE-ConnectionGUID: OK/JB++vRQq9d+FBervLQA== X-CSE-MsgGUID: IUzWVffmTomDeuXdGyLQSg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.07,179,1708416000"; d="scan'208";a="23422248" Received: from sinjan-super-server.iind.intel.com ([10.145.169.153]) by orviesa005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2024 02:58:11 -0700 From: Karthik Poosa To: intel-xe@lists.freedesktop.org Cc: anshuman.gupta@intel.com, badal.nilawar@intel.com, rodrigo.vivi@intel.com, lucas.demarchi@intel.com, Karthik Poosa Subject: [PATCH v6 4/4] drm/xe/hwmon: Cast to output precision before multiplying operands Date: Thu, 4 Apr 2024 15:38:27 +0530 Message-Id: <20240404100827.1109447-5-karthik.poosa@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240404100827.1109447-1-karthik.poosa@intel.com> References: <20240404100827.1109447-1-karthik.poosa@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: intel-xe-bounces@lists.freedesktop.org Sender: "Intel-xe" Address potential overflow in result of multiplication of two lower precision (u32) operands before widening it to higher precision (u64). Fixes: 4446fcf220ce ("drm/xe/hwmon: Expose power1_max_interval") Signed-off-by: Karthik Poosa Reviewed-by: Anshuman Gupta Cc: Badal Nilawar --- drivers/gpu/drm/xe/xe_hwmon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/xe/xe_hwmon.c b/drivers/gpu/drm/xe/xe_hwmon.c index e234321c165c..9511476478cb 100644 --- a/drivers/gpu/drm/xe/xe_hwmon.c +++ b/drivers/gpu/drm/xe/xe_hwmon.c @@ -297,7 +297,7 @@ xe_hwmon_power_max_interval_show(struct device *dev, struct device_attribute *at * As y can be < 2, we compute tau4 = (4 | x) << y * and then add 2 when doing the final right shift to account for units */ - tau4 = ((1 << x_w) | x) << y; + tau4 = (u64)((1 << x_w) | x) << y; /* val in hwmon interface units (millisec) */ out = mul_u64_u32_shr(tau4, SF_TIME, hwmon->scl_shift_time + x_w); @@ -338,7 +338,7 @@ xe_hwmon_power_max_interval_store(struct device *dev, struct device_attribute *a r = FIELD_PREP(PKG_MAX_WIN, PKG_MAX_WIN_DEFAULT); x = REG_FIELD_GET(PKG_MAX_WIN_X, r); y = REG_FIELD_GET(PKG_MAX_WIN_Y, r); - tau4 = ((1 << x_w) | x) << y; + tau4 = (u64)((1 << x_w) | x) << y; max_win = mul_u64_u32_shr(tau4, SF_TIME, hwmon->scl_shift_time + x_w); if (val > max_win) -- 2.25.1