Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/xe/xe_late_bind_fw: Initialize uval variable in xe_late_bind_fw_num_fans()

Initialize the uval variable to 0 in xe_late_bind_fw_num_fans() to fix
a potential use of uninitialized variable warning and ensure predictable
behavior.

The variable is passed by reference to xe_pcode_read() which should
populate it on success, but initializing it to 0 provides a safe
default value and follows kernel coding best practices.

v2:
- uval = 0 which serves as both a safe default and the fallback
value when the pcode read operation fails.

v3:
- Handle MMIO failure (Rodrigo)
- The function should probably return the error and make the uval as
pointer-argument, like the pcode_read.
- Change the caller of this function to propagate the error
upwards if mmio failed.

Fixes: 45832bf9c10f3 ("drm/xe/xe_late_bind_fw: Initialize late binding firmware")
Signed-off-by: Mallesh Koujalagi <mallesh.koujalagi@intel.com>
Link: https://lore.kernel.org/r/20251002005648.3185636-1-mallesh.koujalagi@intel.com
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>

authored by

Mallesh Koujalagi and committed by
Rodrigo Vivi
07abc16c ad298d9e

+8 -8
+8 -8
drivers/gpu/drm/xe/xe_late_bind_fw.c
··· 184 184 } 185 185 } 186 186 187 - static int xe_late_bind_fw_num_fans(struct xe_late_bind *late_bind) 187 + static int xe_late_bind_fw_num_fans(struct xe_late_bind *late_bind, u32 *num_fans) 188 188 { 189 189 struct xe_device *xe = late_bind_to_xe(late_bind); 190 190 struct xe_tile *root_tile = xe_device_get_root_tile(xe); 191 - u32 uval; 192 191 193 - if (!xe_pcode_read(root_tile, 194 - PCODE_MBOX(FAN_SPEED_CONTROL, FSC_READ_NUM_FANS, 0), &uval, NULL)) 195 - return uval; 196 - else 197 - return 0; 192 + return xe_pcode_read(root_tile, 193 + PCODE_MBOX(FAN_SPEED_CONTROL, FSC_READ_NUM_FANS, 0), num_fans, NULL); 198 194 } 199 195 200 196 void xe_late_bind_wait_for_worker_completion(struct xe_late_bind *late_bind) ··· 310 314 lb_fw->flags &= ~INTEL_LB_FLAG_IS_PERSISTENT; 311 315 312 316 if (lb_fw->type == INTEL_LB_TYPE_FAN_CONTROL) { 313 - num_fans = xe_late_bind_fw_num_fans(late_bind); 317 + ret = xe_late_bind_fw_num_fans(late_bind, &num_fans); 318 + if (ret) { 319 + drm_dbg(&xe->drm, "Failed to read number of fans: %d\n", ret); 320 + return 0; /* Not a fatal error, continue without fan control */ 321 + } 314 322 drm_dbg(&xe->drm, "Number of Fans: %d\n", num_fans); 315 323 if (!num_fans) 316 324 return 0;