Skip to contentSkip to conversation

drm/mediatek: simplify mtk_crtc allocation

PATCH Applied Rosen Penev 3 participants 3 messages Mar 31 – May 13

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/mediatek: simplify mtk_crtc allocation

Use a flexible array member to combine allocations.

---
 drivers/gpu/drm/mediatek/mtk_crtc.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/gpu/drm/mediatek/mtk_crtc.c +4 -9
index fcb16f3f7b23..914841d2396e 100644
@@ -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,12 @@ 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)) {
Signature · 1 line
2.53.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Rosen Penev

External email : Please do not click links or open attachments until you have verified the sender or the content.

Use a flexible array member to combine allocations.

Quoted 51 lines
---
 drivers/gpu/drm/mediatek/mtk_crtc.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/gpu/drm/mediatek/mtk_crtc.c +4 -10
index fcb16f3f7b23..914841d2396e 100644
@@ -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,12 @@ 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)) {
--

2.53.0

maintainer Applied
#2 lore raw
In reply to Rosen Penev

Hi, Rosen:

Rosen Penev <[email protected]> 於 2026年3月31日週二 上午12:24寫道:

Quoted 2 lines

Use a flexible array member to combine allocations.

Applied to mediatek-drm-next [1], thanks.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/chunkuang.hu/linux.git/log/?h=mediatek-drm-next

Regards,
Chun-Kuang.

Quoted 51 lines
---
 drivers/gpu/drm/mediatek/mtk_crtc.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/gpu/drm/mediatek/mtk_crtc.c +4 -10
index fcb16f3f7b23..914841d2396e 100644
@@ -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,12 @@ 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)) {
--

2.53.0