[PATCH v2] drm/xe/hwmon: Update xe hwmon with couple of fixes

Lucas De Marchi lucas.demarchi at intel.com
Mon Apr 1 14:09:47 UTC 2024


On Sun, Mar 31, 2024 at 08:23:40PM +0530, Karthik Poosa wrote:
>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>
>---
> 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;

The worst part here is actually that xe_hwmon_get_reg() is using the raw
value and that XE_REG(0) could result in reg.raw != 0 (even if the
register is invalid).  An invalid register has addr == 0, but
xe_hwmon_get_reg() should either a) return struct xe_reg or b) return
int/bool and the reg as output value.

Lucas De Marchi


More information about the Intel-xe mailing list