Commit 883232b4 authored by Karthik Poosa's avatar Karthik Poosa Committed by Lucas De Marchi

drm/xe/hwmon: Cast result to output precision on left shift of operand

Address potential overflow in result of left shift of a
lower precision (u32) operand before assignment to higher
precision (u64) variable.

v2:
 - Update commit message. (Himal)

Fixes: 4446fcf2 ("drm/xe/hwmon: Expose power1_max_interval")
Signed-off-by: default avatarKarthik Poosa <karthik.poosa@intel.com>
Reviewed-by: default avatarAnshuman Gupta <anshuman.gupta@intel.com>
Cc: Badal Nilawar <badal.nilawar@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20240405130127.1392426-5-karthik.poosa@intel.comSigned-off-by: default avatarLucas De Marchi <lucas.demarchi@intel.com>
parent a50b794c
...@@ -298,7 +298,7 @@ xe_hwmon_power_max_interval_show(struct device *dev, struct device_attribute *at ...@@ -298,7 +298,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 * 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 * 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) */ /* val in hwmon interface units (millisec) */
out = mul_u64_u32_shr(tau4, SF_TIME, hwmon->scl_shift_time + x_w); out = mul_u64_u32_shr(tau4, SF_TIME, hwmon->scl_shift_time + x_w);
...@@ -339,7 +339,7 @@ xe_hwmon_power_max_interval_store(struct device *dev, struct device_attribute *a ...@@ -339,7 +339,7 @@ xe_hwmon_power_max_interval_store(struct device *dev, struct device_attribute *a
r = FIELD_PREP(PKG_MAX_WIN, PKG_MAX_WIN_DEFAULT); r = FIELD_PREP(PKG_MAX_WIN, PKG_MAX_WIN_DEFAULT);
x = REG_FIELD_GET(PKG_MAX_WIN_X, r); x = REG_FIELD_GET(PKG_MAX_WIN_X, r);
y = REG_FIELD_GET(PKG_MAX_WIN_Y, 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); max_win = mul_u64_u32_shr(tau4, SF_TIME, hwmon->scl_shift_time + x_w);
if (val > max_win) if (val > max_win)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment