Skip to content

Commit 6982a46

Browse files
Mallesh-Koujalagilucasdemarchi
authored andcommitted
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: 45832bf ("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> (cherry picked from commit 07abc16c14693df703763c45e9fc0abfefc927d5) Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com>
1 parent 10aa5c8 commit 6982a46

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

drivers/gpu/drm/xe/xe_late_bind_fw.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,17 +184,13 @@ static const char *xe_late_bind_parse_status(uint32_t status)
184184
}
185185
}
186186

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)
188188
{
189189
struct xe_device *xe = late_bind_to_xe(late_bind);
190190
struct xe_tile *root_tile = xe_device_get_root_tile(xe);
191-
u32 uval;
192191

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);
198194
}
199195

200196
void xe_late_bind_wait_for_worker_completion(struct xe_late_bind *late_bind)
@@ -314,7 +310,11 @@ static int __xe_late_bind_fw_init(struct xe_late_bind *late_bind, u32 fw_id)
314310
lb_fw->flags &= ~INTEL_LB_FLAG_IS_PERSISTENT;
315311

316312
if (lb_fw->type == INTEL_LB_TYPE_FAN_CONTROL) {
317-
num_fans = xe_late_bind_fw_num_fans(late_bind);
313+
ret = xe_late_bind_fw_num_fans(late_bind, &num_fans);
314+
if (ret) {
315+
drm_dbg(&xe->drm, "Failed to read number of fans: %d\n", ret);
316+
return 0; /* Not a fatal error, continue without fan control */
317+
}
318318
drm_dbg(&xe->drm, "Number of Fans: %d\n", num_fans);
319319
if (!num_fans)
320320
return 0;

0 commit comments

Comments
 (0)