2022-03-25 19:01:11

by QintaoShen

[permalink] [raw]
Subject: [PATCH v1] drm/msm: Check for NULL return of kzalloc()

The allocation of kzalloc() may return NULL, which would bring a NULL
pointer dereference bug.

To avoid this confusion, it is better to check the return value of kzalloc().

Signed-off-by: QintaoShen <[email protected]>
---
drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c | 2 ++
1 file changed, 2 insertions(+)

diff --git a/drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c b/drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c
index 5d2ff67..d017deb 100644
--- a/drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c
+++ b/drivers/gpu/drm/msm/disp/msm_disp_snapshot_util.c
@@ -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);

--
2.7.4