]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/xe: Add NULL checks to scratch LRC allocation
authorMatthew Brost <matthew.brost@intel.com>
Wed, 8 Oct 2025 21:44:59 +0000 (14:44 -0700)
committerMatthew Brost <matthew.brost@intel.com>
Thu, 9 Oct 2025 10:22:15 +0000 (03:22 -0700)
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
drivers/gpu/drm/xe/xe_lrc.c

index af09f70f6e785956b5760a9eaf18cd678cbda714..2c6eae2de1f21e8d05c7d7c73b94e32ca338fe54 100644 (file)
@@ -1214,8 +1214,7 @@ static int setup_bo(struct bo_setup_state *state)
        ssize_t remain;
 
        if (state->lrc->bo->vmap.is_iomem) {
-               if (!state->buffer)
-                       return -ENOMEM;
+               xe_gt_assert(state->hwe->gt, state->buffer);
                state->ptr = state->buffer;
        } else {
                state->ptr = state->lrc->bo->vmap.vaddr + state->offset;
@@ -1303,8 +1302,11 @@ static int setup_wa_bb(struct xe_lrc *lrc, struct xe_hw_engine *hwe)
        u32 *buf = NULL;
        int ret;
 
-       if (lrc->bo->vmap.is_iomem)
+       if (lrc->bo->vmap.is_iomem) {
                buf = kmalloc(LRC_WA_BB_SIZE, GFP_KERNEL);
+               if (!buf)
+                       return -ENOMEM;
+       }
 
        ret = xe_lrc_setup_wa_bb_with_scratch(lrc, hwe, buf);
 
@@ -1347,8 +1349,11 @@ setup_indirect_ctx(struct xe_lrc *lrc, struct xe_hw_engine *hwe)
        if (xe_gt_WARN_ON(lrc->gt, !state.funcs))
                return 0;
 
-       if (lrc->bo->vmap.is_iomem)
+       if (lrc->bo->vmap.is_iomem) {
                state.buffer = kmalloc(state.max_size, GFP_KERNEL);
+               if (!state.buffer)
+                       return -ENOMEM;
+       }
 
        ret = setup_bo(&state);
        if (ret) {