[PATCH v5 4/4] drm/xe/hwmon: Cast to output precision before multiplying operands

Ghimiray, Himal Prasad himal.prasad.ghimiray at intel.com
Thu Apr 4 11:48:05 UTC 2024


Commit Message and description doesn't match with the operations you are 
addressing.
You are using left shift not multiply.

On 04-04-2024 09:24, Karthik Poosa wrote:
> Address potential overflow in result of multiplication of two lower
> precision (u32) operands before widening it to higher precision (u64).
>
> Signed-off-by: Karthik Poosa <karthik.poosa at intel.com>
> ---
>   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 114aadb54c8e..3c5764af8a23 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)


More information about the Intel-xe mailing list