[PATCH 1/8] clk: mediatek: add array size fields to clk trees
David Lechner
dlechner at baylibre.com
Thu Dec 18 18:16:59 CET 2025
Add num_plls, num_fclks, num_fdivs, num_muxes, and num_gates fields to
the mtk_clk_tree struct and populate them in the clk trees for all
existing drivers.
Currently, there is no bounds checking when accessing the arrays in
the clk tree structs. Adding these fields will allow for bounds checking
in the future.
Signed-off-by: David Lechner <dlechner at baylibre.com>
---
drivers/clk/mediatek/clk-mt7622.c | 9 +++++++++
drivers/clk/mediatek/clk-mt7623.c | 6 ++++++
drivers/clk/mediatek/clk-mt7629.c | 8 ++++++++
drivers/clk/mediatek/clk-mt7981.c | 7 +++++++
drivers/clk/mediatek/clk-mt7986.c | 7 +++++++
drivers/clk/mediatek/clk-mt7987.c | 5 +++++
drivers/clk/mediatek/clk-mt7988.c | 6 ++++++
drivers/clk/mediatek/clk-mt8183.c | 4 ++++
drivers/clk/mediatek/clk-mt8365.c | 4 ++++
drivers/clk/mediatek/clk-mt8512.c | 4 ++++
drivers/clk/mediatek/clk-mt8516.c | 4 ++++
drivers/clk/mediatek/clk-mt8518.c | 4 ++++
drivers/clk/mediatek/clk-mtk.h | 5 +++++
13 files changed, 73 insertions(+)
diff --git a/drivers/clk/mediatek/clk-mt7622.c b/drivers/clk/mediatek/clk-mt7622.c
index 23b9787612a..ccad3820c1b 100644
--- a/drivers/clk/mediatek/clk-mt7622.c
+++ b/drivers/clk/mediatek/clk-mt7622.c
@@ -604,6 +604,8 @@ static const struct mtk_clk_tree mt7622_apmixed_clk_tree = {
.plls = apmixed_plls,
.gates_offs = CLK_APMIXED_MAIN_CORE_EN,
.gates = apmixed_cgs,
+ .num_plls = ARRAY_SIZE(apmixed_plls),
+ .num_gates = ARRAY_SIZE(apmixed_cgs),
};
static const struct mtk_clk_tree mt7622_infra_clk_tree = {
@@ -612,6 +614,8 @@ static const struct mtk_clk_tree mt7622_infra_clk_tree = {
.gates_offs = CLK_INFRA_DBGCLK_PD,
.muxes = infra_muxes,
.gates = infra_cgs,
+ .num_muxes = ARRAY_SIZE(infra_muxes),
+ .num_gates = ARRAY_SIZE(infra_cgs),
};
static const struct mtk_clk_tree mt7622_peri_clk_tree = {
@@ -620,6 +624,8 @@ static const struct mtk_clk_tree mt7622_peri_clk_tree = {
.gates_offs = CLK_PERI_THERM_PD,
.muxes = peri_muxes,
.gates = peri_cgs,
+ .num_muxes = ARRAY_SIZE(peri_muxes),
+ .num_gates = ARRAY_SIZE(peri_cgs),
};
static const struct mtk_clk_tree mt7622_clk_tree = {
@@ -629,6 +635,9 @@ static const struct mtk_clk_tree mt7622_clk_tree = {
.fclks = top_fixed_clks,
.fdivs = top_fixed_divs,
.muxes = top_muxes,
+ .num_fclks = ARRAY_SIZE(top_fixed_clks),
+ .num_fdivs = ARRAY_SIZE(top_fixed_divs),
+ .num_muxes = ARRAY_SIZE(top_muxes),
};
static int mt7622_mcucfg_probe(struct udevice *dev)
diff --git a/drivers/clk/mediatek/clk-mt7623.c b/drivers/clk/mediatek/clk-mt7623.c
index d0b80f48b0a..cfc711ad216 100644
--- a/drivers/clk/mediatek/clk-mt7623.c
+++ b/drivers/clk/mediatek/clk-mt7623.c
@@ -997,6 +997,7 @@ static const struct mtk_clk_tree mt7623_apmixedsys_clk_tree = {
.xtal2_rate = 26 * MHZ,
.id_offs_map = pll_id_offs_map,
.plls = apmixed_plls,
+ .num_plls = ARRAY_SIZE(apmixed_plls),
};
static const struct mtk_clk_tree mt7623_topckgen_clk_tree = {
@@ -1007,6 +1008,9 @@ static const struct mtk_clk_tree mt7623_topckgen_clk_tree = {
.fclks = top_fixed_clks,
.fdivs = top_fixed_divs,
.muxes = top_muxes,
+ .num_fclks = ARRAY_SIZE(top_fixed_clks),
+ .num_fdivs = ARRAY_SIZE(top_fixed_divs),
+ .num_muxes = ARRAY_SIZE(top_muxes),
};
static int mt7623_mcucfg_probe(struct udevice *dev)
@@ -1063,6 +1067,8 @@ static const struct mtk_clk_tree mt7623_clk_peri_tree = {
.gates_offs = peri_id_offs_map[CLK_PERI_NFI],
.muxes = peri_muxes,
.gates = peri_cgs,
+ .num_muxes = ARRAY_SIZE(peri_muxes),
+ .num_gates = ARRAY_SIZE(peri_cgs),
.xtal_rate = 26 * MHZ,
};
diff --git a/drivers/clk/mediatek/clk-mt7629.c b/drivers/clk/mediatek/clk-mt7629.c
index 94fc5e51456..e0eff01561c 100644
--- a/drivers/clk/mediatek/clk-mt7629.c
+++ b/drivers/clk/mediatek/clk-mt7629.c
@@ -572,6 +572,10 @@ static const struct mtk_clk_tree mt7629_clk_tree = {
.fclks = top_fixed_clks,
.fdivs = top_fixed_divs,
.muxes = top_muxes,
+ .num_plls = ARRAY_SIZE(apmixed_plls),
+ .num_fclks = ARRAY_SIZE(top_fixed_clks),
+ .num_fdivs = ARRAY_SIZE(top_fixed_divs),
+ .num_muxes = ARRAY_SIZE(top_muxes),
};
static const struct mtk_clk_tree mt7629_peri_clk_tree = {
@@ -584,6 +588,10 @@ static const struct mtk_clk_tree mt7629_peri_clk_tree = {
.fclks = top_fixed_clks,
.fdivs = top_fixed_divs,
.muxes = top_muxes,
+ .num_plls = ARRAY_SIZE(apmixed_plls),
+ .num_fclks = ARRAY_SIZE(top_fixed_clks),
+ .num_fdivs = ARRAY_SIZE(top_fixed_divs),
+ .num_muxes = ARRAY_SIZE(top_muxes),
};
static int mt7629_mcucfg_probe(struct udevice *dev)
diff --git a/drivers/clk/mediatek/clk-mt7981.c b/drivers/clk/mediatek/clk-mt7981.c
index 6130c93d5e6..9cb2aff2bee 100644
--- a/drivers/clk/mediatek/clk-mt7981.c
+++ b/drivers/clk/mediatek/clk-mt7981.c
@@ -513,6 +513,7 @@ static const struct mtk_clk_tree mt7981_fixed_pll_clk_tree = {
.fdivs_offs = CLK_APMIXED_NR_CLK,
.xtal_rate = 40 * MHZ,
.fclks = fixed_pll_clks,
+ .num_fclks = ARRAY_SIZE(fixed_pll_clks),
};
static const struct mtk_clk_tree mt7981_topckgen_clk_tree = {
@@ -521,6 +522,9 @@ static const struct mtk_clk_tree mt7981_topckgen_clk_tree = {
.fclks = top_fixed_clks,
.fdivs = top_fixed_divs,
.muxes = top_muxes,
+ .num_fclks = ARRAY_SIZE(top_fixed_clks),
+ .num_fdivs = ARRAY_SIZE(top_fixed_divs),
+ .num_muxes = ARRAY_SIZE(top_muxes),
.flags = CLK_BYPASS_XTAL | CLK_TOPCKGEN,
};
@@ -531,6 +535,9 @@ static const struct mtk_clk_tree mt7981_infracfg_clk_tree = {
.fdivs = infra_fixed_divs,
.muxes = infra_muxes,
.gates = infracfg_gates,
+ .num_fdivs = ARRAY_SIZE(infra_fixed_divs),
+ .num_muxes = ARRAY_SIZE(infra_muxes),
+ .num_gates = ARRAY_SIZE(infracfg_gates),
.flags = CLK_INFRASYS,
};
diff --git a/drivers/clk/mediatek/clk-mt7986.c b/drivers/clk/mediatek/clk-mt7986.c
index cf298af644c..afff3167284 100644
--- a/drivers/clk/mediatek/clk-mt7986.c
+++ b/drivers/clk/mediatek/clk-mt7986.c
@@ -519,6 +519,7 @@ static const struct mtk_clk_tree mt7986_fixed_pll_clk_tree = {
.fdivs_offs = CLK_APMIXED_NR_CLK,
.xtal_rate = 40 * MHZ,
.fclks = fixed_pll_clks,
+ .num_fclks = ARRAY_SIZE(fixed_pll_clks),
.flags = CLK_APMIXED,
};
@@ -528,6 +529,9 @@ static const struct mtk_clk_tree mt7986_topckgen_clk_tree = {
.fclks = top_fixed_clks,
.fdivs = top_fixed_divs,
.muxes = top_muxes,
+ .num_fclks = ARRAY_SIZE(top_fixed_clks),
+ .num_fdivs = ARRAY_SIZE(top_fixed_divs),
+ .num_muxes = ARRAY_SIZE(top_muxes),
.flags = CLK_BYPASS_XTAL | CLK_TOPCKGEN,
};
@@ -538,6 +542,9 @@ static const struct mtk_clk_tree mt7986_infracfg_clk_tree = {
.fdivs = infra_fixed_divs,
.muxes = infra_muxes,
.gates = infracfg_gates,
+ .num_fdivs = ARRAY_SIZE(infra_fixed_divs),
+ .num_muxes = ARRAY_SIZE(infra_muxes),
+ .num_gates = ARRAY_SIZE(infracfg_gates),
.flags = CLK_INFRASYS,
};
diff --git a/drivers/clk/mediatek/clk-mt7987.c b/drivers/clk/mediatek/clk-mt7987.c
index b662d680b15..8e37803e97b 100644
--- a/drivers/clk/mediatek/clk-mt7987.c
+++ b/drivers/clk/mediatek/clk-mt7987.c
@@ -46,6 +46,7 @@ static const struct mtk_fixed_clk apmixedsys_mtk_plls[] = {
static const struct mtk_clk_tree mt7987_fixed_pll_clk_tree = {
.fdivs_offs = ARRAY_SIZE(apmixedsys_mtk_plls),
.fclks = apmixedsys_mtk_plls,
+ .num_fclks = ARRAY_SIZE(apmixedsys_mtk_plls),
.flags = CLK_APMIXED,
.xtal_rate = 40 * MHZ,
};
@@ -442,6 +443,8 @@ static const struct mtk_clk_tree mt7987_topckgen_clk_tree = {
.muxes_offs = CLK_TOP_NETSYS_SEL,
.fdivs = topckgen_mtk_fixed_factors,
.muxes = topckgen_mtk_muxes,
+ .num_fdivs = ARRAY_SIZE(topckgen_mtk_fixed_factors),
+ .num_muxes = ARRAY_SIZE(topckgen_mtk_muxes),
.flags = CLK_BYPASS_XTAL | CLK_TOPCKGEN,
.xtal_rate = MT7987_XTAL_RATE,
};
@@ -765,6 +768,8 @@ static const struct mtk_clk_tree mt7987_infracfg_clk_tree = {
.gates_offs = CLK_INFRA_66M_GPT_BCK,
.muxes = infracfg_mtk_mux,
.gates = infracfg_mtk_gates,
+ .num_muxes = ARRAY_SIZE(infracfg_mtk_mux),
+ .num_gates = ARRAY_SIZE(infracfg_mtk_gates),
.flags = CLK_BYPASS_XTAL,
.xtal_rate = MT7987_XTAL_RATE,
};
diff --git a/drivers/clk/mediatek/clk-mt7988.c b/drivers/clk/mediatek/clk-mt7988.c
index c6da42f970b..d594fc6df39 100644
--- a/drivers/clk/mediatek/clk-mt7988.c
+++ b/drivers/clk/mediatek/clk-mt7988.c
@@ -773,6 +773,7 @@ static const struct mtk_gate infracfg_mtk_gates[] = {
static const struct mtk_clk_tree mt7988_fixed_pll_clk_tree = {
.fdivs_offs = ARRAY_SIZE(apmixedsys_mtk_plls),
.fclks = apmixedsys_mtk_plls,
+ .num_fclks = ARRAY_SIZE(apmixedsys_mtk_plls),
.flags = CLK_APMIXED,
.xtal_rate = 40 * MHZ,
};
@@ -783,6 +784,9 @@ static const struct mtk_clk_tree mt7988_topckgen_clk_tree = {
.fclks = topckgen_mtk_fixed_clks,
.fdivs = topckgen_mtk_fixed_factors,
.muxes = topckgen_mtk_muxes,
+ .num_fclks = ARRAY_SIZE(topckgen_mtk_fixed_clks),
+ .num_fdivs = ARRAY_SIZE(topckgen_mtk_fixed_factors),
+ .num_muxes = ARRAY_SIZE(topckgen_mtk_muxes),
.flags = CLK_BYPASS_XTAL | CLK_TOPCKGEN,
.xtal_rate = 40 * MHZ,
};
@@ -792,6 +796,8 @@ static const struct mtk_clk_tree mt7988_infracfg_clk_tree = {
.gates_offs = CLK_INFRA_PCIE_PERI_26M_CK_P0,
.muxes = infracfg_mtk_mux,
.gates = infracfg_mtk_gates,
+ .num_muxes = ARRAY_SIZE(infracfg_mtk_mux),
+ .num_gates = ARRAY_SIZE(infracfg_mtk_gates),
.flags = CLK_BYPASS_XTAL,
.xtal_rate = 40 * MHZ,
};
diff --git a/drivers/clk/mediatek/clk-mt8183.c b/drivers/clk/mediatek/clk-mt8183.c
index 9612a62e56a..7a1953ef6fd 100644
--- a/drivers/clk/mediatek/clk-mt8183.c
+++ b/drivers/clk/mediatek/clk-mt8183.c
@@ -599,6 +599,10 @@ static const struct mtk_clk_tree mt8183_clk_tree = {
.fclks = top_fixed_clks,
.fdivs = top_fixed_divs,
.muxes = top_muxes,
+ .num_plls = ARRAY_SIZE(apmixed_plls),
+ .num_fclks = ARRAY_SIZE(top_fixed_clks),
+ .num_fdivs = ARRAY_SIZE(top_fixed_divs),
+ .num_muxes = ARRAY_SIZE(top_muxes),
};
static const struct mtk_gate_regs infra0_cg_regs = {
diff --git a/drivers/clk/mediatek/clk-mt8365.c b/drivers/clk/mediatek/clk-mt8365.c
index 53eca73b98d..7897044e1ad 100644
--- a/drivers/clk/mediatek/clk-mt8365.c
+++ b/drivers/clk/mediatek/clk-mt8365.c
@@ -490,6 +490,10 @@ static const struct mtk_clk_tree mt8365_clk_tree = {
.fclks = top_fixed_clks,
.fdivs = top_divs,
.muxes = top_muxes,
+ .num_plls = ARRAY_SIZE(apmixed_plls),
+ .num_fclks = ARRAY_SIZE(top_fixed_clks),
+ .num_fdivs = ARRAY_SIZE(top_divs),
+ .num_muxes = ARRAY_SIZE(top_muxes),
};
/* topckgen cg */
diff --git a/drivers/clk/mediatek/clk-mt8512.c b/drivers/clk/mediatek/clk-mt8512.c
index ab270673442..6d98403bc45 100644
--- a/drivers/clk/mediatek/clk-mt8512.c
+++ b/drivers/clk/mediatek/clk-mt8512.c
@@ -790,6 +790,10 @@ static const struct mtk_clk_tree mt8512_clk_tree = {
.fclks = top_fixed_clks,
.fdivs = top_fixed_divs,
.muxes = top_muxes,
+ .num_plls = ARRAY_SIZE(apmixed_plls),
+ .num_fclks = ARRAY_SIZE(top_fixed_clks),
+ .num_fdivs = ARRAY_SIZE(top_fixed_divs),
+ .num_muxes = ARRAY_SIZE(top_muxes),
};
static int mt8512_apmixedsys_probe(struct udevice *dev)
diff --git a/drivers/clk/mediatek/clk-mt8516.c b/drivers/clk/mediatek/clk-mt8516.c
index 623f88499f1..c21b9894ad6 100644
--- a/drivers/clk/mediatek/clk-mt8516.c
+++ b/drivers/clk/mediatek/clk-mt8516.c
@@ -739,6 +739,10 @@ static const struct mtk_clk_tree mt8516_clk_tree = {
.fclks = top_fixed_clks,
.fdivs = top_fixed_divs,
.muxes = top_muxes,
+ .num_plls = ARRAY_SIZE(apmixed_plls),
+ .num_fclks = ARRAY_SIZE(top_fixed_clks),
+ .num_fdivs = ARRAY_SIZE(top_fixed_divs),
+ .num_muxes = ARRAY_SIZE(top_muxes),
};
static int mt8516_apmixedsys_probe(struct udevice *dev)
diff --git a/drivers/clk/mediatek/clk-mt8518.c b/drivers/clk/mediatek/clk-mt8518.c
index ba8cc584d46..48ef209ebbd 100644
--- a/drivers/clk/mediatek/clk-mt8518.c
+++ b/drivers/clk/mediatek/clk-mt8518.c
@@ -1495,6 +1495,10 @@ static const struct mtk_clk_tree mt8518_clk_tree = {
.fclks = top_fixed_clks,
.fdivs = top_fixed_divs,
.muxes = top_muxes,
+ .num_plls = ARRAY_SIZE(apmixed_plls),
+ .num_fclks = ARRAY_SIZE(top_fixed_clks),
+ .num_fdivs = ARRAY_SIZE(top_fixed_divs),
+ .num_muxes = ARRAY_SIZE(top_muxes),
};
static int mt8518_apmixedsys_probe(struct udevice *dev)
diff --git a/drivers/clk/mediatek/clk-mtk.h b/drivers/clk/mediatek/clk-mtk.h
index 89479001ba8..05c22fce10d 100644
--- a/drivers/clk/mediatek/clk-mtk.h
+++ b/drivers/clk/mediatek/clk-mtk.h
@@ -265,6 +265,11 @@ struct mtk_clk_tree {
const struct mtk_fixed_factor *fdivs;
const struct mtk_composite *muxes;
const struct mtk_gate *gates;
+ const int num_plls;
+ const int num_fclks;
+ const int num_fdivs;
+ const int num_muxes;
+ const int num_gates;
u32 flags;
};
--
2.43.0
More information about the U-Boot
mailing list