[PATCH v2] drm/xe/hwmon: Update xe hwmon with couple of fixes
Gupta, Anshuman
anshuman.gupta at intel.com
Mon Apr 1 10:09:31 UTC 2024
> -----Original Message-----
> From: Poosa, Karthik <karthik.poosa at intel.com>
> Sent: Sunday, March 31, 2024 8:24 PM
> To: intel-xe at lists.freedesktop.org
> Cc: Gupta, Anshuman <anshuman.gupta at intel.com>; Nilawar, Badal
> <badal.nilawar at intel.com>; Vivi, Rodrigo <rodrigo.vivi at intel.com>; Poosa,
> Karthik <karthik.poosa at intel.com>
> Subject: [PATCH v2] drm/xe/hwmon: Update xe hwmon with couple of fixes
>
> Fix potential overflows with upcasting.
> Initialize variables which were being used uninitialized.
>
> v2:
> - Rebase.
> - In xe_hwmon_process_reg, set argument 'value' to 0 on failure.
> With this change caller function need not initialize value to 0.
>
> Fixes: 4446fcf220ce ("drm/xe/hwmon: Expose power1_max_interval")
> Signed-off-by: Karthik Poosa <karthik.poosa at intel.com>
> Reviewed-by: Anshuman Gupta <anshuman.gupta at intel.com>
Looks good to me.
> ---
> drivers/gpu/drm/xe/xe_hwmon.c | 9 ++++++---
> 1 file changed, 6 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_hwmon.c
> b/drivers/gpu/drm/xe/xe_hwmon.c index 7e8caac838e0..bc1bc73749c1
> 100644
> --- a/drivers/gpu/drm/xe/xe_hwmon.c
> +++ b/drivers/gpu/drm/xe/xe_hwmon.c
> @@ -129,8 +129,10 @@ static void xe_hwmon_process_reg(struct xe_hwmon
> *hwmon, enum xe_hwmon_reg hwmon
>
> reg.raw = xe_hwmon_get_reg(hwmon, hwmon_reg, channel);
>
> - if (!reg.raw)
> + if (!reg.raw) {
> + *value = 0;
> return;
> + }
>
> switch (operation) {
> case REG_READ32:
> @@ -143,6 +145,7 @@ static void xe_hwmon_process_reg(struct xe_hwmon
> *hwmon, enum xe_hwmon_reg hwmon
> *value = xe_mmio_read64_2x32(hwmon->gt, reg);
> break;
> default:
> + *value = 0;
> drm_warn(>_to_xe(hwmon->gt)->drm, "Invalid xe hwmon
> reg operation: %d\n",
> operation);
> break;
> @@ -298,7 +301,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); @@ -339,7 +342,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
More information about the Intel-xe
mailing list