diff mbox series

drm/i915/hwmon: Fix issues found by static analysis tool in i915 hwmon

Message ID 20231201143430.1320510-1-karthik.poosa@intel.com (mailing list archive)
State New, archived
Headers show
Series drm/i915/hwmon: Fix issues found by static analysis tool in i915 hwmon | expand

Commit Message

Karthik Poosa Dec. 1, 2023, 2:34 p.m. UTC
Updated i915 hwmon with fixes for issues reported by static analysis tool.
Fixed unintentional buffer overflow (OVERFLOW_BEFORE_WIDEN) with upcasting.

Fixes: 4c2572fe0ae7 ("drm/i915/hwmon: Expose power1_max_interval")
Signed-off-by: Karthik Poosa <karthik.poosa@intel.com>
---
 drivers/gpu/drm/i915/i915_hwmon.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Gupta, Anshuman Dec. 4, 2023, 8:28 a.m. UTC | #1
> -----Original Message-----
> From: Poosa, Karthik <karthik.poosa@intel.com>
> Sent: Friday, December 1, 2023 8:05 PM
> To: intel-gfx@lists.freedesktop.org
> Cc: Gupta, Anshuman <anshuman.gupta@intel.com>; Nilawar, Badal
> <badal.nilawar@intel.com>; Poosa, Karthik <karthik.poosa@intel.com>
> Subject: [PATCH] drm/i915/hwmon: Fix issues found by static analysis tool in
> i915 hwmon
Keep the subject short and explanatory.
" drm/i915/hwmon: Fix analysis tool issues "
> 
> Updated i915 hwmon with fixes for issues reported by static analysis tool.
> Fixed unintentional buffer overflow (OVERFLOW_BEFORE_WIDEN) with
Remove an tool specific error codes like "OVERFLOW_BEFORE_WIDEN"
from commit message. Keep it generic.
> upcasting.
> 
> Fixes: 4c2572fe0ae7 ("drm/i915/hwmon: Expose power1_max_interval")
> Signed-off-by: Karthik Poosa <karthik.poosa@intel.com>
Please add the review comment credits from reviewers.
With all above .
Reviewed-by: Anshuman Gupta <anshuman.gupta@intel.com>
Thanks,
Anshuman.
> ---
>  drivers/gpu/drm/i915/i915_hwmon.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_hwmon.c
> b/drivers/gpu/drm/i915/i915_hwmon.c
> index 975da8e7f2a9..8c3f443c8347 100644
> --- a/drivers/gpu/drm/i915/i915_hwmon.c
> +++ b/drivers/gpu/drm/i915/i915_hwmon.c
> @@ -175,7 +175,7 @@ hwm_power1_max_interval_show(struct device
> *dev, struct device_attribute *attr,
>  	 *     tau4 = (4 | x) << y
>  	 * but 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);
> 
> @@ -211,7 +211,7 @@ hwm_power1_max_interval_store(struct device
> *dev,
>  	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
Andi Shyti Dec. 6, 2023, 5:02 p.m. UTC | #2
Hi Karthik,

On Fri, Dec 01, 2023 at 08:04:30PM +0530, Karthik Poosa wrote:
> Updated i915 hwmon with fixes for issues reported by static analysis tool.
> Fixed unintentional buffer overflow (OVERFLOW_BEFORE_WIDEN) with upcasting.

what kind of error was this? Was it caught by a static analyzer
or did you actually hit the overflow?

Thanks,
Andi

> Fixes: 4c2572fe0ae7 ("drm/i915/hwmon: Expose power1_max_interval")
> Signed-off-by: Karthik Poosa <karthik.poosa@intel.com>
> ---
>  drivers/gpu/drm/i915/i915_hwmon.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/i915/i915_hwmon.c b/drivers/gpu/drm/i915/i915_hwmon.c
> index 975da8e7f2a9..8c3f443c8347 100644
> --- a/drivers/gpu/drm/i915/i915_hwmon.c
> +++ b/drivers/gpu/drm/i915/i915_hwmon.c
> @@ -175,7 +175,7 @@ hwm_power1_max_interval_show(struct device *dev, struct device_attribute *attr,
>  	 *     tau4 = (4 | x) << y
>  	 * but 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);
>  
> @@ -211,7 +211,7 @@ hwm_power1_max_interval_store(struct device *dev,
>  	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
diff mbox series

Patch

diff --git a/drivers/gpu/drm/i915/i915_hwmon.c b/drivers/gpu/drm/i915/i915_hwmon.c
index 975da8e7f2a9..8c3f443c8347 100644
--- a/drivers/gpu/drm/i915/i915_hwmon.c
+++ b/drivers/gpu/drm/i915/i915_hwmon.c
@@ -175,7 +175,7 @@  hwm_power1_max_interval_show(struct device *dev, struct device_attribute *attr,
 	 *     tau4 = (4 | x) << y
 	 * but 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);
 
@@ -211,7 +211,7 @@  hwm_power1_max_interval_store(struct device *dev,
 	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)