]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/mediatek: Simplify mtk_crtc allocation
authorRosen Penev <rosenp@gmail.com>
Tue, 31 Mar 2026 00:23:57 +0000 (17:23 -0700)
committerChun-Kuang Hu <chunkuang.hu@kernel.org>
Wed, 13 May 2026 14:53:42 +0000 (14:53 +0000)
Use a flexible array member to combine allocations.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Reviewed-by: CK Hu <ck.hu@mediatek.com>
Link: https://patchwork.kernel.org/project/dri-devel/patch/20260331002357.7995-1-rosenp@gmail.com/
Signed-off-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>
drivers/gpu/drm/mediatek/mtk_crtc.c

index fcb16f3f7b23b37f939e0e52159be7152763cb0e..cd05e18c87da90f1e0feafcc905dac0d7960e4a8 100644 (file)
@@ -62,7 +62,6 @@ struct mtk_crtc {
        struct device                   *dma_dev;
        struct mtk_mutex                *mutex;
        unsigned int                    ddp_comp_nr;
-       struct mtk_ddp_comp             **ddp_comp;
        unsigned int                    num_conn_routes;
        const struct mtk_drm_route      *conn_routes;
 
@@ -71,6 +70,8 @@ struct mtk_crtc {
        bool                            config_updating;
        /* lock for config_updating to cmd buffer */
        spinlock_t                      config_lock;
+
+       struct mtk_ddp_comp             *ddp_comp[];
 };
 
 struct mtk_crtc_state {
@@ -1048,18 +1049,14 @@ int mtk_crtc_create(struct drm_device *drm_dev, const unsigned int *path,
                }
        }
 
-       mtk_crtc = devm_kzalloc(dev, sizeof(*mtk_crtc), GFP_KERNEL);
+       mtk_crtc = devm_kzalloc(dev,
+                               struct_size(mtk_crtc, ddp_comp, path_len + (conn_routes ? 1 : 0)),
+                               GFP_KERNEL);
        if (!mtk_crtc)
                return -ENOMEM;
 
-       mtk_crtc->mmsys_dev = priv->mmsys_dev;
        mtk_crtc->ddp_comp_nr = path_len;
-       mtk_crtc->ddp_comp = devm_kcalloc(dev,
-                                         mtk_crtc->ddp_comp_nr + (conn_routes ? 1 : 0),
-                                         sizeof(*mtk_crtc->ddp_comp),
-                                         GFP_KERNEL);
-       if (!mtk_crtc->ddp_comp)
-               return -ENOMEM;
+       mtk_crtc->mmsys_dev = priv->mmsys_dev;
 
        mtk_crtc->mutex = mtk_mutex_get(priv->mutex_dev);
        if (IS_ERR(mtk_crtc->mutex)) {