diff mbox series

drm/mediatek: Add checks for devm_kcalloc

Message ID 20221125014123.121268-1-yuancan@huawei.com (mailing list archive)
State New, archived
Headers show
Series drm/mediatek: Add checks for devm_kcalloc | expand

Commit Message

Yuan Can Nov. 25, 2022, 1:41 a.m. UTC
As the devm_kcalloc may return NULL, the return value needs to be checked
to avoid NULL poineter dereference.

Fixes: 66b2cf9623fa ("drm/mediatek: use layer_nr function to get layer number to init plane")
Signed-off-by: Yuan Can <yuancan@huawei.com>
---
 drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Daniel Vetter Nov. 30, 2022, 10:43 a.m. UTC | #1
On Fri, Nov 25, 2022 at 01:41:23AM +0000, Yuan Can wrote:
> As the devm_kcalloc may return NULL, the return value needs to be checked
> to avoid NULL poineter dereference.
> 
> Fixes: 66b2cf9623fa ("drm/mediatek: use layer_nr function to get layer number to init plane")
> Signed-off-by: Yuan Can <yuancan@huawei.com>
> ---
>  drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 2 ++
>  1 file changed, 2 insertions(+)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> index 112615817dcb..5071f1263216 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> @@ -945,6 +945,8 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
>  
>  	mtk_crtc->planes = devm_kcalloc(dev, num_comp_planes,
>  					sizeof(struct drm_plane), GFP_KERNEL);
> +	if (!mtk_crtc->planes)
> +		return -ENOMEM;

These (= drm object allocations like drm_planes, drm_crtc) should all be
moved over to drmm_, since devm_ has the wrong lifetimes.

Just in case you want to spend a pile of time in here, the error handling
needs to be fixed either way.
-Daniel

>  
>  	for (i = 0; i < mtk_crtc->ddp_comp_nr; i++) {
>  		ret = mtk_drm_crtc_init_comp_planes(drm_dev, mtk_crtc, i,
> -- 
> 2.17.1
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
index 112615817dcb..5071f1263216 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
@@ -945,6 +945,8 @@  int mtk_drm_crtc_create(struct drm_device *drm_dev,
 
 	mtk_crtc->planes = devm_kcalloc(dev, num_comp_planes,
 					sizeof(struct drm_plane), GFP_KERNEL);
+	if (!mtk_crtc->planes)
+		return -ENOMEM;
 
 	for (i = 0; i < mtk_crtc->ddp_comp_nr; i++) {
 		ret = mtk_drm_crtc_init_comp_planes(drm_dev, mtk_crtc, i,