Skip to contentSkip to conversation

drm/msm/dpu: check for null return of devm_kzalloc() in dpu_writeback_init()

PATCH Applied Hui Tang 3 participants 3 messages Nov 19, 2022 – Jan 9, 2023

Subsystems (3)
lore
Share & tools
lore

Hui Tang

author
#0 lore raw

PATCH 1/1 drm/msm/dpu: check for null return of devm_kzalloc() in dpu_writeback_init()

Because of the possilble failure of devm_kzalloc(), dpu_wb_conn might be NULL and will cause null pointer derefrence later.

Therefore, it might be better to check it and directly return -ENOMEM.

Fixes 77b001acdcfe ("drm/msm/dpu: add the writeback connector layer")
---
 drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c +2 -0
index 088ec990a2f2..2a5a68366582 100644
@@ -70,6 +70,8 @@ int dpu_writeback_init(struct drm_device *dev, struct drm_encoder *enc,
 	int rc = 0;
 
 	dpu_wb_conn = devm_kzalloc(dev->dev, sizeof(*dpu_wb_conn), GFP_KERNEL);
+	if (!dpu_wb_conn)
+		return -ENOMEM;
 
 	drm_connector_helper_add(&dpu_wb_conn->base.base, &dpu_wb_conn_helper_funcs);
 
Signature · 1 line
2.17.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 2 lines · Hui Tang

Because of the possilble failure of devm_kzalloc(), dpu_wb_conn might be NULL and will cause null pointer derefrence later.

derefrence --> dereference

Quoted 5 lines

Therefore, it might be better to check it and directly return -ENOMEM.

Fixes 77b001acdcfe ("drm/msm/dpu: add the writeback connector layer")

With that nit fixed,

Quoted 17 lines
---
  drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c | 2 ++
  1 file changed, 2 insertions(+)
drivers/gpu/drm/msm/disp/dpu1/dpu_writeback.c +2 -0
index 088ec990a2f2..2a5a68366582 100644
@@ -70,6 +70,8 @@ int dpu_writeback_init(struct drm_device *dev, struct drm_encoder *enc,
  	int rc = 0;
 
  	dpu_wb_conn = devm_kzalloc(dev->dev, sizeof(*dpu_wb_conn), GFP_KERNEL);
+	if (!dpu_wb_conn)
+		return -ENOMEM;
 
  	drm_connector_helper_add(&dpu_wb_conn->base.base, &dpu_wb_conn_helper_funcs);
 
#2 lore raw
In reply to Hui Tang
Quoted 6 lines · Hui Tang

Because of the possilble failure of devm_kzalloc(), dpu_wb_conn might be NULL and will cause null pointer derefrence later.

Therefore, it might be better to check it and directly return -ENOMEM.

Applied, thanks!

[1/1] drm/msm/dpu: check for null return of devm_kzalloc() in dpu_writeback_init()

      https://gitlab.freedesktop.org/lumag/msm/-/commit/21e9a838f505

Best regards,

Signature · 1 line
Dmitry Baryshkov <[email protected]>