Skip to content

Commit a8ad871

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]> (cherry picked from commit 883232b) Signed-off-by: Lucas De Marchi <[email protected]>
1 parent 50a9b7f commit a8ad871

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
@@ -290,7 +290,7 @@ xe_hwmon_power1_max_interval_show(struct device *dev, struct device_attribute *a
290290
* As y can be < 2, we compute tau4 = (4 | x) << y
291291
* and then add 2 when doing the final right shift to account for units
292292
*/
293-
tau4 = ((1 << x_w) | x) << y;
293+
tau4 = (u64)((1 << x_w) | x) << y;
294294

295295
/* val in hwmon interface units (millisec) */
296296
out = mul_u64_u32_shr(tau4, SF_TIME, hwmon->scl_shift_time + x_w);
@@ -330,7 +330,7 @@ xe_hwmon_power1_max_interval_store(struct device *dev, struct device_attribute *
330330
r = FIELD_PREP(PKG_MAX_WIN, PKG_MAX_WIN_DEFAULT);
331331
x = REG_FIELD_GET(PKG_MAX_WIN_X, r);
332332
y = REG_FIELD_GET(PKG_MAX_WIN_Y, r);
333-
tau4 = ((1 << x_w) | x) << y;
333+
tau4 = (u64)((1 << x_w) | x) << y;
334334
max_win = mul_u64_u32_shr(tau4, SF_TIME, hwmon->scl_shift_time + x_w);
335335

336336
if (val > max_win)

0 commit comments

Comments
 (0)