Skip to content

Commit 3065e6a

Browse files
haryvenRob Clark
authored andcommitted
drm/msm: fix missing NULL check after kcalloc in crashstate_get_bos()
The crashstate_get_bos() function allocates memory for `state->bos` using kcalloc(), but the vmbind path does not check for allocation failure before dereferencing it in the following drm_gpuvm_for_each_va() loop. This could lead to a NULL pointer dereference if memory allocation fails. Fix this by wrapping the drm_gpuvm_for_each_va() loop with a NULL check on state->bos, similar to the safety check in the non-vmbind path. Fixes: af9aa6f ("drm/msm: Crashdump support for sparse") Signed-off-by: Huiwen He <hehuiwen@kylinos.cn> Patchwork: https://patchwork.freedesktop.org/patch/687556/ Signed-off-by: Rob Clark <robin.clark@oss.qualcomm.com>
1 parent 3099e02 commit 3065e6a

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

drivers/gpu/drm/msm/msm_gpu.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -287,16 +287,17 @@ static void crashstate_get_bos(struct msm_gpu_state *state, struct msm_gem_submi
287287

288288
state->bos = kcalloc(cnt, sizeof(struct msm_gpu_state_bo), GFP_KERNEL);
289289

290-
drm_gpuvm_for_each_va (vma, submit->vm) {
291-
bool dump = rd_full || (vma->flags & MSM_VMA_DUMP);
290+
if (state->bos)
291+
drm_gpuvm_for_each_va(vma, submit->vm) {
292+
bool dump = rd_full || (vma->flags & MSM_VMA_DUMP);
292293

293-
/* Skip MAP_NULL/PRR VMAs: */
294-
if (!vma->gem.obj)
295-
continue;
294+
/* Skip MAP_NULL/PRR VMAs: */
295+
if (!vma->gem.obj)
296+
continue;
296297

297-
msm_gpu_crashstate_get_bo(state, vma->gem.obj, vma->va.addr,
298-
dump, vma->gem.offset, vma->va.range);
299-
}
298+
msm_gpu_crashstate_get_bo(state, vma->gem.obj, vma->va.addr,
299+
dump, vma->gem.offset, vma->va.range);
300+
}
300301

301302
drm_exec_fini(&exec);
302303
} else {

0 commit comments

Comments
 (0)