]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
clk: mediatek: add array size fields to cg gates
authorDavid Lechner <dlechner@baylibre.com>
Wed, 7 Jan 2026 15:50:12 +0000 (09:50 -0600)
committerTom Rini <trini@konsulko.com>
Mon, 12 Jan 2026 19:14:02 +0000 (13:14 -0600)
Add num_gates field to struct mtk_cg_priv and populate it for all
existing drivers.

Currently, there is no bounds checking when accessing the gates array.
Adding this field will allow for bounds checking in the future.

Signed-off-by: David Lechner <dlechner@baylibre.com>
15 files changed:
drivers/clk/mediatek/clk-mt7622.c
drivers/clk/mediatek/clk-mt7623.c
drivers/clk/mediatek/clk-mt7629.c
drivers/clk/mediatek/clk-mt7981.c
drivers/clk/mediatek/clk-mt7986.c
drivers/clk/mediatek/clk-mt7987.c
drivers/clk/mediatek/clk-mt7988.c
drivers/clk/mediatek/clk-mt8183.c
drivers/clk/mediatek/clk-mt8188.c
drivers/clk/mediatek/clk-mt8365.c
drivers/clk/mediatek/clk-mt8512.c
drivers/clk/mediatek/clk-mt8516.c
drivers/clk/mediatek/clk-mt8518.c
drivers/clk/mediatek/clk-mtk.c
drivers/clk/mediatek/clk-mtk.h

index ccad3820c1bd957f9e6124840c882e97ebd8a3da..16c6f024e72c595cec10a22c76487142274ad5a9 100644 (file)
@@ -692,7 +692,8 @@ static int mt7622_pericfg_probe(struct udevice *dev)
 
 static int mt7622_pciesys_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt7622_clk_tree, pcie_cgs);
+       return mtk_common_clk_gate_init(dev, &mt7622_clk_tree, pcie_cgs,
+                                       ARRAY_SIZE(pcie_cgs));
 }
 
 static int mt7622_pciesys_bind(struct udevice *dev)
@@ -710,7 +711,8 @@ static int mt7622_pciesys_bind(struct udevice *dev)
 
 static int mt7622_ethsys_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt7622_clk_tree, eth_cgs);
+       return mtk_common_clk_gate_init(dev, &mt7622_clk_tree, eth_cgs,
+                                       ARRAY_SIZE(eth_cgs));
 }
 
 static int mt7622_ethsys_bind(struct udevice *dev)
@@ -728,12 +730,14 @@ static int mt7622_ethsys_bind(struct udevice *dev)
 
 static int mt7622_sgmiisys_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt7622_clk_tree, sgmii_cgs);
+       return mtk_common_clk_gate_init(dev, &mt7622_clk_tree, sgmii_cgs,
+                                       ARRAY_SIZE(sgmii_cgs));
 }
 
 static int mt7622_ssusbsys_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt7622_clk_tree, ssusb_cgs);
+       return mtk_common_clk_gate_init(dev, &mt7622_clk_tree, ssusb_cgs,
+                                       ARRAY_SIZE(ssusb_cgs));
 }
 
 static const struct udevice_id mt7622_apmixed_compat[] = {
index cfc711ad216ce61dddc20b6e72e09397111afaf8..5a60a86233e8e847ce6284c2122c69293b597aa6 100644 (file)
@@ -1057,8 +1057,8 @@ static const struct mtk_clk_tree mt7623_clk_gate_tree = {
 
 static int mt7623_infracfg_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt7623_clk_gate_tree,
-                                       infra_cgs);
+       return mtk_common_clk_gate_init(dev, &mt7623_clk_gate_tree, infra_cgs,
+                                       ARRAY_SIZE(infra_cgs));
 }
 
 static const struct mtk_clk_tree mt7623_clk_peri_tree = {
@@ -1079,14 +1079,14 @@ static int mt7623_pericfg_probe(struct udevice *dev)
 
 static int mt7623_hifsys_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt7623_clk_gate_tree,
-                                       hif_cgs);
+       return mtk_common_clk_gate_init(dev, &mt7623_clk_gate_tree, hif_cgs,
+                                       ARRAY_SIZE(hif_cgs));
 }
 
 static int mt7623_ethsys_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt7623_clk_gate_tree,
-                                       eth_cgs);
+       return mtk_common_clk_gate_init(dev, &mt7623_clk_gate_tree, eth_cgs,
+                                       ARRAY_SIZE(eth_cgs));
 }
 
 static int mt7623_ethsys_hifsys_bind(struct udevice *dev)
index e0eff01561cef0f44e70bb74ed7d8b79e61bcb9d..e4132f6195f9835230a49ec650d6433ea914dac4 100644 (file)
@@ -634,17 +634,20 @@ static int mt7629_topckgen_probe(struct udevice *dev)
 
 static int mt7629_infracfg_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt7629_clk_tree, infra_cgs);
+       return mtk_common_clk_gate_init(dev, &mt7629_clk_tree, infra_cgs,
+                                       ARRAY_SIZE(infra_cgs));
 }
 
 static int mt7629_pericfg_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt7629_peri_clk_tree, peri_cgs);
+       return mtk_common_clk_gate_init(dev, &mt7629_peri_clk_tree, peri_cgs,
+                                       ARRAY_SIZE(peri_cgs));
 }
 
 static int mt7629_ethsys_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt7629_clk_tree, eth_cgs);
+       return mtk_common_clk_gate_init(dev, &mt7629_clk_tree, eth_cgs,
+                                       ARRAY_SIZE(eth_cgs));
 }
 
 static int mt7629_ethsys_bind(struct udevice *dev)
@@ -662,12 +665,14 @@ static int mt7629_ethsys_bind(struct udevice *dev)
 
 static int mt7629_sgmiisys_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt7629_clk_tree, sgmii_cgs);
+       return mtk_common_clk_gate_init(dev, &mt7629_clk_tree, sgmii_cgs,
+                                       ARRAY_SIZE(sgmii_cgs));
 }
 
 static int mt7629_ssusbsys_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt7629_clk_tree, ssusb_cgs);
+       return mtk_common_clk_gate_init(dev, &mt7629_clk_tree, ssusb_cgs,
+                                       ARRAY_SIZE(ssusb_cgs));
 }
 
 static const struct udevice_id mt7629_apmixed_compat[] = {
index f854f079c672f2c000b63c79695188c56c1b2ed3..c8090688df0c3b73c9c9ad12faddea84fcd689b9 100644 (file)
@@ -631,7 +631,7 @@ static const struct mtk_gate sgmii0_cgs[] = {
 static int mt7981_sgmii0sys_probe(struct udevice *dev)
 {
        return mtk_common_clk_gate_init(dev, &mt7981_topckgen_clk_tree,
-                                       sgmii0_cgs);
+                                       sgmii0_cgs, ARRAY_SIZE(sgmii0_cgs));
 }
 
 static const struct udevice_id mt7981_sgmii0sys_compat[] = {
@@ -658,7 +658,7 @@ static const struct mtk_gate sgmii1_cgs[] = {
 static int mt7981_sgmii1sys_probe(struct udevice *dev)
 {
        return mtk_common_clk_gate_init(dev, &mt7981_topckgen_clk_tree,
-                                       sgmii1_cgs);
+                                       sgmii1_cgs, ARRAY_SIZE(sgmii1_cgs));
 }
 
 static const struct udevice_id mt7981_sgmii1sys_compat[] = {
@@ -699,7 +699,7 @@ static const struct mtk_gate eth_cgs[] = {
 static int mt7981_ethsys_probe(struct udevice *dev)
 {
        return mtk_common_clk_gate_init(dev, &mt7981_topckgen_clk_tree,
-                                       eth_cgs);
+                                       eth_cgs, ARRAY_SIZE(eth_cgs));
 }
 
 static int mt7981_ethsys_bind(struct udevice *dev)
index 257f89b7daa58756b40da09158fa8e47b5b9ffba..735e824c874a2825462aaab05d54707b5fb5daa8 100644 (file)
@@ -636,8 +636,8 @@ static const struct mtk_gate eth_cgs[] = {
 
 static int mt7986_ethsys_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt7986_topckgen_clk_tree,
-                                       eth_cgs);
+       return mtk_common_clk_gate_init(dev, &mt7986_topckgen_clk_tree, eth_cgs,
+                                       ARRAY_SIZE(eth_cgs));
 }
 
 static int mt7986_ethsys_bind(struct udevice *dev)
index b559152c045b90de5cebb1afdef2525cdb873bf1..99ff57c5dc52c028878102a03b39b77d9698d5d2 100644 (file)
@@ -818,8 +818,8 @@ static const struct mtk_gate eth_cgs[] = {
 
 static int mt7987_ethsys_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt7987_topckgen_clk_tree,
-                                       eth_cgs);
+       return mtk_common_clk_gate_init(dev, &mt7987_topckgen_clk_tree, eth_cgs,
+                                       ARRAY_SIZE(eth_cgs));
 }
 
 static int mt7987_ethsys_bind(struct udevice *dev)
index 56f3e5ebdff5aff2489cca6a179615961a10b8f2..da1d2e89d61b3f9f2a250806dbf2f9af0503cd2f 100644 (file)
@@ -892,7 +892,8 @@ static const struct mtk_gate ethdma_mtk_gate[] = {
 static int mt7988_ethdma_probe(struct udevice *dev)
 {
        return mtk_common_clk_gate_init(dev, &mt7988_topckgen_clk_tree,
-                                       ethdma_mtk_gate);
+                                       ethdma_mtk_gate,
+                                       ARRAY_SIZE(ethdma_mtk_gate));
 }
 
 static int mt7988_ethdma_bind(struct udevice *dev)
@@ -950,7 +951,8 @@ static const struct mtk_gate sgmiisys_0_mtk_gate[] = {
 static int mt7988_sgmiisys_0_probe(struct udevice *dev)
 {
        return mtk_common_clk_gate_init(dev, &mt7988_topckgen_clk_tree,
-                                       sgmiisys_0_mtk_gate);
+                                       sgmiisys_0_mtk_gate,
+                                       ARRAY_SIZE(sgmiisys_0_mtk_gate));
 }
 
 static const struct udevice_id mt7988_sgmiisys_0_compat[] = {
@@ -994,7 +996,8 @@ static const struct mtk_gate sgmiisys_1_mtk_gate[] = {
 static int mt7988_sgmiisys_1_probe(struct udevice *dev)
 {
        return mtk_common_clk_gate_init(dev, &mt7988_topckgen_clk_tree,
-                                       sgmiisys_1_mtk_gate);
+                                       sgmiisys_1_mtk_gate,
+                                       ARRAY_SIZE(sgmiisys_1_mtk_gate));
 }
 
 static const struct udevice_id mt7988_sgmiisys_1_compat[] = {
@@ -1040,7 +1043,8 @@ static const struct mtk_gate ethwarp_mtk_gate[] = {
 static int mt7988_ethwarp_probe(struct udevice *dev)
 {
        return mtk_common_clk_gate_init(dev, &mt7988_topckgen_clk_tree,
-                                       ethwarp_mtk_gate);
+                                       ethwarp_mtk_gate,
+                                       ARRAY_SIZE(ethwarp_mtk_gate));
 }
 
 static int mt7988_ethwarp_bind(struct udevice *dev)
index 7a1953ef6fd62dde35ee5640fa376c5b9de7e9db..5b41cf4b88c34a706205390de22c6e5951d0e337 100644 (file)
@@ -777,7 +777,8 @@ static int mt8183_topckgen_probe(struct udevice *dev)
 
 static int mt8183_infracfg_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt8183_clk_tree, infra_clks);
+       return mtk_common_clk_gate_init(dev, &mt8183_clk_tree, infra_clks,
+                                       ARRAY_SIZE(infra_clks));
 }
 
 static const struct udevice_id mt8183_apmixed_compat[] = {
index 186638fcb662d0dae5840a5367a93935e94dbfcd..f7c04047f4dc07ed43723ae57fc9b24acb855768 100644 (file)
@@ -1694,33 +1694,44 @@ static int mt8188_topckgen_probe(struct udevice *dev)
 
 static int mt8188_topckgen_cg_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt8188_topckgen_cg_clk_tree, topckgen_cg_clks);
+       return mtk_common_clk_gate_init(dev, &mt8188_topckgen_cg_clk_tree,
+                                       topckgen_cg_clks,
+                                       ARRAY_SIZE(topckgen_cg_clks));
 }
 
 static int mt8188_infracfg_ao_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt8188_infracfg_ao_clk_tree, infracfg_ao_clks);
+       return mtk_common_clk_gate_init(dev, &mt8188_infracfg_ao_clk_tree,
+                                       infracfg_ao_clks,
+                                       ARRAY_SIZE(infracfg_ao_clks));
 }
 
 static int mt8188_pericfg_ao_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt8188_pericfg_ao_clk_tree, pericfg_ao_clks);
+       return mtk_common_clk_gate_init(dev, &mt8188_pericfg_ao_clk_tree,
+                                       pericfg_ao_clks,
+                                       ARRAY_SIZE(pericfg_ao_clks));
 }
 
 static int mt8188_imp_iic_wrap_c_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt8188_imp_iic_wrap_c_clk_tree, imp_iic_wrap_c_clks);
+       return mtk_common_clk_gate_init(dev, &mt8188_imp_iic_wrap_c_clk_tree,
+                                       imp_iic_wrap_c_clks,
+                                       ARRAY_SIZE(imp_iic_wrap_c_clks));
 }
 
 static int mt8188_imp_iic_wrap_w_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt8188_imp_iic_wrap_w_clk_tree, imp_iic_wrap_w_clks);
+       return mtk_common_clk_gate_init(dev, &mt8188_imp_iic_wrap_w_clk_tree,
+                                       imp_iic_wrap_w_clks,
+                                       ARRAY_SIZE(imp_iic_wrap_w_clks));
 }
 
 static int mt8188_imp_iic_wrap_en_probe(struct udevice *dev)
 {
        return mtk_common_clk_gate_init(dev, &mt8188_imp_iic_wrap_en_clk_tree,
-                                       imp_iic_wrap_en_clks);
+                                       imp_iic_wrap_en_clks,
+                                       ARRAY_SIZE(imp_iic_wrap_en_clks));
 }
 
 static const struct udevice_id mt8188_apmixed_compat[] = {
index 7897044e1adcbd9fceeac22db342d58a1dac990d..c88545fc7cfd594a47231896a89a949d5db73139 100644 (file)
@@ -705,12 +705,14 @@ static int mt8365_topckgen_probe(struct udevice *dev)
 
 static int mt8365_topckgen_cg_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt8365_clk_tree, top_clk_gates);
+       return mtk_common_clk_gate_init(dev, &mt8365_clk_tree, top_clk_gates,
+                                       ARRAY_SIZE(top_clk_gates));
 }
 
 static int mt8365_infracfg_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt8365_clk_tree, ifr_clks);
+       return mtk_common_clk_gate_init(dev, &mt8365_clk_tree, ifr_clks,
+                                       ARRAY_SIZE(ifr_clks));
 }
 
 static const struct udevice_id mt8365_apmixed_compat[] = {
index 6d98403bc451e9881e94675294c1f2f094435d25..d4f6604c160ea89f0a69d4e22e86232d0af93458 100644 (file)
@@ -808,12 +808,14 @@ static int mt8512_topckgen_probe(struct udevice *dev)
 
 static int mt8512_topckgen_cg_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt8512_clk_tree, top_clks);
+       return mtk_common_clk_gate_init(dev, &mt8512_clk_tree, top_clks,
+                                       ARRAY_SIZE(top_clks));
 }
 
 static int mt8512_infracfg_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt8512_clk_tree, infra_clks);
+       return mtk_common_clk_gate_init(dev, &mt8512_clk_tree, infra_clks,
+                                       ARRAY_SIZE(infra_clks));
 }
 
 static const struct udevice_id mt8512_apmixed_compat[] = {
index c21b9894ad687cb7430d86a2c731334a6726b538..d5f922886a3aa60180640edf6273aa16943b97b8 100644 (file)
@@ -757,7 +757,8 @@ static int mt8516_topckgen_probe(struct udevice *dev)
 
 static int mt8516_topckgen_cg_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt8516_clk_tree, top_clks);
+       return mtk_common_clk_gate_init(dev, &mt8516_clk_tree, top_clks,
+                                       ARRAY_SIZE(top_clks));
 }
 
 static const struct udevice_id mt8516_apmixed_compat[] = {
index 48ef209ebbdd711c414bf8b52e2d3048697350f2..92730f3f06ce3aee8c5c85db39ef5c372f193d3e 100644 (file)
@@ -1513,7 +1513,8 @@ static int mt8518_topckgen_probe(struct udevice *dev)
 
 static int mt8518_topckgen_cg_probe(struct udevice *dev)
 {
-       return mtk_common_clk_gate_init(dev, &mt8518_clk_tree, top_clks);
+       return mtk_common_clk_gate_init(dev, &mt8518_clk_tree, top_clks,
+                                       ARRAY_SIZE(top_clks));
 }
 
 static const struct udevice_id mt8518_apmixed_compat[] = {
index f91777e968a63477c4e75872af632a6b7c855c51..ffaecbfd306ba0b8a610ea11a65c04dadd37ea54 100644 (file)
@@ -824,7 +824,7 @@ int mtk_common_clk_infrasys_init(struct udevice *dev,
 
 int mtk_common_clk_gate_init(struct udevice *dev,
                             const struct mtk_clk_tree *tree,
-                            const struct mtk_gate *gates)
+                            const struct mtk_gate *gates, int num_gates)
 {
        struct mtk_cg_priv *priv = dev_get_priv(dev);
        struct udevice *parent;
@@ -845,6 +845,7 @@ int mtk_common_clk_gate_init(struct udevice *dev,
        priv->parent = parent;
        priv->tree = tree;
        priv->gates = gates;
+       priv->num_gates = num_gates;
 
        return 0;
 }
index a4a3307e576f402e6cd8d869c859b0d46ba5a452..7bd432cb93dbb67c78c071f4c54b7c44cd7e5b88 100644 (file)
@@ -279,6 +279,7 @@ struct mtk_cg_priv {
        void __iomem *base;
        const struct mtk_clk_tree *tree;
        const struct mtk_gate *gates;
+       int num_gates;
 };
 
 extern const struct clk_ops mtk_clk_apmixedsys_ops;
@@ -293,6 +294,6 @@ int mtk_common_clk_infrasys_init(struct udevice *dev,
                                 const struct mtk_clk_tree *tree);
 int mtk_common_clk_gate_init(struct udevice *dev,
                             const struct mtk_clk_tree *tree,
-                            const struct mtk_gate *gates);
+                            const struct mtk_gate *gates, int num_gates);
 
 #endif /* __DRV_CLK_MTK_H */