drm/msm/disp: check the return value of kzalloc()
authorXiaoke Wang <xkernel.wang@foxmail.com>
Thu, 24 Mar 2022 09:15:08 +0000 (17:15 +0800)
committerRob Clark <robdclark@chromium.org>
Wed, 6 Apr 2022 16:13:46 +0000 (09:13 -0700)
kzalloc() is a memory allocation function which can return NULL when
some internal memory errors happen. So it is better to check it to
prevent potential wrong memory access.

Signed-off-by: Xiaoke Wang <xkernel.wang@foxmail.com>
Reviewed-by: Abhinav Kumar <quic_abhinavk@quicinc.com>
Link: https://lore.kernel.org/r/tencent_B3E19486FF39415098B572B7397C2936C309@qq.com
Signed-off-by: Rob Clark <robdclark@chromium.org>
drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c

index 5d2ff67..acfe1b3 100644 (file)
@@ -176,6 +176,8 @@ void msm_disp_snapshot_add_block(struct msm_disp_state *disp_state, u32 len,
        va_list va;
 
        new_blk = kzalloc(sizeof(struct msm_disp_state_block), GFP_KERNEL);
+       if (!new_blk)
+               return;
 
        va_start(va, fmt);