Skip to content

Commit 883232b

Browse files
kpoosalucasdemarchi
authored andcommitted
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: 4446fcf ("drm/xe/hwmon: Expose power1_max_interval") Signed-off-by: Karthik Poosa <[email protected]> Reviewed-by: Anshuman Gupta <[email protected]> Cc: Badal Nilawar <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected] Signed-off-by: Lucas De Marchi <[email protected]>
1 parent a50b794 commit 883232b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/gpu/drm/xe/xe_hwmon.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ xe_hwmon_power_max_interval_show(struct device *dev, struct device_attribute *at
298298
* As y can be < 2, we compute tau4 = (4 | x) << y
299299
* and then add 2 when doing the final right shift to account for units
300300
*/
301-
tau4 = ((1 << x_w) | x) << y;
301+
tau4 = (u64)((1 << x_w) | x) << y;
302302

303303
/* val in hwmon interface units (millisec) */
304304
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
339339
r = FIELD_PREP(PKG_MAX_WIN, PKG_MAX_WIN_DEFAULT);
340340
x = REG_FIELD_GET(PKG_MAX_WIN_X, r);
341341
y = REG_FIELD_GET(PKG_MAX_WIN_Y, r);
342-
tau4 = ((1 << x_w) | x) << y;
342+
tau4 = (u64)((1 << x_w) | x) << y;
343343
max_win = mul_u64_u32_shr(tau4, SF_TIME, hwmon->scl_shift_time + x_w);
344344

345345
if (val > max_win)

0 commit comments

Comments
 (0)