Skip to content

Commit 01a2c51

Browse files
diandersChun-Kuang Hu
authored andcommitted
drm/mediatek: Init ddp_comp with devm_kcalloc()
In the case where `conn_routes` is true we allocate an extra slot in the `ddp_comp` array but mtk_drm_crtc_create() never seemed to initialize it in the test case I ran. For me, this caused a later crash when we looped through the array in mtk_drm_crtc_mode_valid(). This showed up for me when I booted with `slub_debug=FZPUA` which poisons the memory initially. Without `slub_debug` I couldn't reproduce, presumably because the later code handles the value being NULL and in most cases (not guaranteed in all cases) the memory the allocator returned started out as 0. It really doesn't hurt to initialize the array with devm_kcalloc() since the array is small and the overhead of initting a handful of elements to 0 is small. In general initting memory to zero is a safer practice and usually it's suggested to only use the non-initting alloc functions if you really need to. Let's switch the function to use an allocation function that zeros the memory. For me, this avoids the crash. Fixes: 01389b3 ("drm/mediatek: Add connector dynamic selection capability") Signed-off-by: Douglas Anderson <dianders@chromium.org> Reviewed-by: CK Hu <ck.hu@mediatek.com> Link: https://patchwork.kernel.org/project/dri-devel/patch/20240328092248.1.I2e73c38c0f264ee2fa4a09cdd83994e37ba9f541@changeid/ Signed-off-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>
1 parent 1e43500 commit 01a2c51

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

drivers/gpu/drm/mediatek/mtk_drm_crtc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,10 +1009,10 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
10091009

10101010
mtk_crtc->mmsys_dev = priv->mmsys_dev;
10111011
mtk_crtc->ddp_comp_nr = path_len;
1012-
mtk_crtc->ddp_comp = devm_kmalloc_array(dev,
1013-
mtk_crtc->ddp_comp_nr + (conn_routes ? 1 : 0),
1014-
sizeof(*mtk_crtc->ddp_comp),
1015-
GFP_KERNEL);
1012+
mtk_crtc->ddp_comp = devm_kcalloc(dev,
1013+
mtk_crtc->ddp_comp_nr + (conn_routes ? 1 : 0),
1014+
sizeof(*mtk_crtc->ddp_comp),
1015+
GFP_KERNEL);
10161016
if (!mtk_crtc->ddp_comp)
10171017
return -ENOMEM;
10181018

0 commit comments

Comments
 (0)