[PATCH 3/6] clk: en7523: decouple base clock count from clock ID count

From: John Crispin

Date: Tue Nov 24 2026 - 05:12:50 EST


en7581_register_clocks() walks num_clocks entries of base_clks[], and
num_clocks also sizes hws[]. That holds only while every clock ID below
num_clocks has a descriptor. A SoC that leaves an ID unused, or whose
largest ID is not the last descriptor, either reads past the array or
writes hws[] past its allocation.

Carry the descriptor count separately. num_clocks keeps sizing hws[].

No functional change.

Signed-off-by: John Crispin <john@xxxxxxxxxxx>
---
drivers/clk/clk-en7523.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/clk/clk-en7523.c b/drivers/clk/clk-en7523.c
index d044841cdc05..2799b550401e 100644
--- a/drivers/clk/clk-en7523.c
+++ b/drivers/clk/clk-en7523.c
@@ -149,6 +149,7 @@ struct en_clk_priv {
struct en_clk_soc_data {
u32 num_clocks;
const struct en_clk_desc *base_clks;
+ unsigned int num_base_clks;
const struct clk_ops pcie_ops;
int (*hw_init)(struct platform_device *pdev,
struct clk_hw_onecell_data *clk_data);
@@ -1006,7 +1007,7 @@ static void en7581_register_clocks(struct device *dev, struct clk_hw_onecell_dat

soc_data = device_get_match_data(dev);

- for (i = 0; i < soc_data->num_clocks; i++) {
+ for (i = 0; i < soc_data->num_base_clks; i++) {
const struct en_clk_desc *desc = &soc_data->base_clks[i];
u32 val, reg = desc->div_reg ? desc->div_reg : desc->base_reg;
int err;
@@ -1527,6 +1528,7 @@ static const struct en_clk_soc_data en7523_data = {

static const struct en_clk_soc_data en7581_data = {
.base_clks = en7581_base_clks,
+ .num_base_clks = ARRAY_SIZE(en7581_base_clks),
.num_clocks = ARRAY_SIZE(en7581_base_clks),
.pcie_ops = {
.is_enabled = en7581_pci_is_enabled,
@@ -1538,6 +1540,7 @@ static const struct en_clk_soc_data en7581_data = {

static const struct en_clk_soc_data an7583_data = {
.base_clks = an7583_base_clks,
+ .num_base_clks = ARRAY_SIZE(an7583_base_clks),
.num_clocks = ARRAY_SIZE(an7583_base_clks),
.pcie_ops = {
.is_enabled = en7581_pci_is_enabled,
--
2.34.1