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

drm/xe: Add NULL checks to scratch LRC allocation

kmalloc can fail, the returned value must have a NULL check. This should
be immediately after kmalloc for clarity.

v5:
- Assert state->buffer in setup_bo if buffer is iomem (Tomasz)

Signed-off-by: Matthew Brost <matthew.brost@intel.com>
Reviewed-by: Tomasz Lis <tomasz.lis@intel.com>
Link: https://lore.kernel.org/r/20251008214532.3442967-2-matthew.brost@intel.com

+9 -4
+9 -4
drivers/gpu/drm/xe/xe_lrc.c
··· 1214 1214 ssize_t remain; 1215 1215 1216 1216 if (state->lrc->bo->vmap.is_iomem) { 1217 - if (!state->buffer) 1218 - return -ENOMEM; 1217 + xe_gt_assert(state->hwe->gt, state->buffer); 1219 1218 state->ptr = state->buffer; 1220 1219 } else { 1221 1220 state->ptr = state->lrc->bo->vmap.vaddr + state->offset; ··· 1302 1303 u32 *buf = NULL; 1303 1304 int ret; 1304 1305 1305 - if (lrc->bo->vmap.is_iomem) 1306 + if (lrc->bo->vmap.is_iomem) { 1306 1307 buf = kmalloc(LRC_WA_BB_SIZE, GFP_KERNEL); 1308 + if (!buf) 1309 + return -ENOMEM; 1310 + } 1307 1311 1308 1312 ret = xe_lrc_setup_wa_bb_with_scratch(lrc, hwe, buf); 1309 1313 ··· 1349 1347 if (xe_gt_WARN_ON(lrc->gt, !state.funcs)) 1350 1348 return 0; 1351 1349 1352 - if (lrc->bo->vmap.is_iomem) 1350 + if (lrc->bo->vmap.is_iomem) { 1353 1351 state.buffer = kmalloc(state.max_size, GFP_KERNEL); 1352 + if (!state.buffer) 1353 + return -ENOMEM; 1354 + } 1354 1355 1355 1356 ret = setup_bo(&state); 1356 1357 if (ret) {