* [PATCH] drm/mediatek: Add checks for devm_kcalloc
@ 2022-11-25 1:41 Yuan Can
2022-11-30 10:43 ` Daniel Vetter
0 siblings, 1 reply; 2+ messages in thread
From: Yuan Can @ 2022-11-25 1:41 UTC (permalink / raw)
To: chunkuang.hu, p.zabel, airlied, daniel, matthias.bgg, stu.hsieh,
ck.hu, dri-devel, linux-mediatek, linux-arm-kernel
Cc: yuancan
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;
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
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] drm/mediatek: Add checks for devm_kcalloc
2022-11-25 1:41 [PATCH] drm/mediatek: Add checks for devm_kcalloc Yuan Can
@ 2022-11-30 10:43 ` Daniel Vetter
0 siblings, 0 replies; 2+ messages in thread
From: Daniel Vetter @ 2022-11-30 10:43 UTC (permalink / raw)
To: Yuan Can
Cc: chunkuang.hu, p.zabel, airlied, daniel, matthias.bgg, stu.hsieh,
ck.hu, dri-devel, linux-mediatek, linux-arm-kernel
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
>
--
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-11-30 10:44 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-25 1:41 [PATCH] drm/mediatek: Add checks for devm_kcalloc Yuan Can
2022-11-30 10:43 ` Daniel Vetter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).