clk: rockchip: Use flexible array for clock table
Subsystems (2)
PATCH 1/1 clk: rockchip: Use flexible array for clock table
Store the clock lookup table in the Rockchip clock provider allocation instead of allocating it separately.
This ties the table lifetime directly to the provider and removes a separate allocation failure path while preserving the clk_onecell_data lookup interface.
--- drivers/clk/rockchip/clk.c | 17 ++++------------- drivers/clk/rockchip/clk.h | 2 ++ 2 files changed, 6 insertions(+), 13 deletions(-)
drivers/clk/rockchip/clk.c +4 -13
@@ -359,26 +359,21 @@ static struct rockchip_clk_provider *rockchip_clk_init_base( unsigned long nr_clks, bool has_late_clocks) {struct rockchip_clk_provider *ctx; -struct clk **clk_table;struct clk *default_clk_val;int i; default_clk_val =ERR_PTR (has_late_clocks ? -EPROBE_DEFER : -ENOENT ); - ctx = kzalloc_obj(struct rockchip_clk_provider); + ctx =kzalloc_flex (*ctx, clk_table, nr_clks);if (!ctx)return ERR_PTR (-ENOMEM ); - clk_table = kzalloc_objs(struct clk *, nr_clks); -if (!clk_table) - goto err_free; -for (i =0 ; i < nr_clks; ++i) - clk_table[i] = default_clk_val; + ctx->clk_table[i] = default_clk_val; - ctx->reg_base = base; - ctx->clk_data.clks = clk_table; ctx->clk_data.clk_num = nr_clks; + ctx->clk_data.clks = ctx->clk_table; + ctx->reg_base = base; ctx->cru_node = np;spin_lock_init (&ctx->lock);
@@ -388,10 +383,6 @@ static struct rockchip_clk_provider *rockchip_clk_init_base( "rockchip,grf");return ctx; - -err_free: -kfree (ctx); -return ERR_PTR (-ENOMEM ); } struct rockchip_clk_provider *rockchip_clk_init(struct device_node *np,
drivers/clk/rockchip/clk.h +2 -0
@@ -604,6 +604,7 @@ struct rockchip_aux_grf {* @grf: regmap of the general-register-files syscon * @aux_grf_table: hashtable of auxiliary GRF regmaps, indexed by grf_type * @lock: maintains exclusion between callbacks for a given clock-provider. +* @clk_table: clock lookup table. */ struct rockchip_clk_provider {void __iomem *reg_base;
@@ -612,6 +613,7 @@ struct rockchip_clk_provider {struct regmap *grf;DECLARE_HASHTABLE (aux_grf_table,GRF_HASH_ORDER );spinlock_t lock; +struct clk *clk_table[]; };struct rockchip_pll_rate_table {
Signature · 1 line
2.54.0
Hi Rosen,
Quoted 35 lines · Rosen Penev
Store the clock lookup table in the Rockchip clock provider allocation instead of allocating it separately.
This ties the table lifetime directly to the provider and removes a separate allocation failure path while preserving the
clk_onecell_datalookup interface.Assisted-by Codex:GPT-5.5Signed-off-by Rosen Penev <[email protected]>--- drivers/clk/rockchip/clk.c | 17 ++++------------- drivers/clk/rockchip/clk.h | 2 ++ 2 files changed, 6 insertions(+), 13 deletions(-)drivers/clk/rockchip/clk.c +1
-4@@ -359,26 +359,21 @@ static struct rockchip_clk_provider *rockchip_clk_init_base( unsigned long nr_clks, bool has_late_clocks) {struct rockchip_clk_provider *ctx; -struct clk **clk_table;struct clk *default_clk_val;int i; default_clk_val =ERR_PTR (has_late_clocks ? -EPROBE_DEFER : -ENOENT ); - ctx = kzalloc_obj(struct rockchip_clk_provider); + ctx =kzalloc_flex (*ctx, clk_table, nr_clks);if (!ctx)return ERR_PTR (-ENOMEM ); - clk_table = kzalloc_objs(struct clk *, nr_clks); -if (!clk_table)
drivers/clk/rockchip/clk.c static struct rockchip_clk_provider *rockchip_clk_init_base( · line 375
Quoted 10 lines
drivers/clk/rockchip/clk.c +2
-5- goto err_free; -for (i =0 ; i < nr_clks; ++i) - clk_table[i] = default_clk_val; + ctx->clk_table[i] = default_clk_val; - ctx->reg_base = base; - ctx->clk_data.clks = clk_table; ctx->clk_data.clk_num = nr_clks; + ctx->clk_data.clks = ctx->clk_table;
Where's the __counted_by? Also struct clk_onecell_data is embedded inside struct rockchip_clk_provider, and I'm not sure offhand how that'll work.
Brian
Quoted 38 lines
drivers/clk/rockchip/clk.c +1
-4+ ctx->reg_base = base; ctx->cru_node = np;spin_lock_init (&ctx->lock);@@ -388,10 +383,6 @@ static struct rockchip_clk_provider *rockchip_clk_init_base( "rockchip,grf");return ctx; - -err_free: -kfree (ctx); -return ERR_PTR (-ENOMEM ); } struct rockchip_clk_provider *rockchip_clk_init(struct device_node *np,drivers/clk/rockchip/clk.h +2
-0@@ -604,6 +604,7 @@ struct rockchip_aux_grf {* @grf: regmap of the general-register-files syscon * @aux_grf_table: hashtable of auxiliary GRF regmaps, indexed by grf_type * @lock: maintains exclusion between callbacks for a given clock-provider. +* @clk_table: clock lookup table. */ struct rockchip_clk_provider {void __iomem *reg_base;@@ -612,6 +613,7 @@ struct rockchip_clk_provider {struct regmap *grf;DECLARE_HASHTABLE (aux_grf_table,GRF_HASH_ORDER );spinlock_t lock; +struct clk *clk_table[]; };struct rockchip_pll_rate_table {Signature · 1 line
2.54.0
Quoted 45 lines · Brian Masney
Hi Rosen,
Quoted 41 lines · Rosen Penev
Store the clock lookup table in the Rockchip clock provider allocation instead of allocating it separately.
This ties the table lifetime directly to the provider and removes a separate allocation failure path while preserving the
clk_onecell_datalookup interface.Assisted-by Codex:GPT-5.5Signed-off-by Rosen Penev <[email protected]>--- drivers/clk/rockchip/clk.c | 17 ++++------------- drivers/clk/rockchip/clk.h | 2 ++ 2 files changed, 6 insertions(+), 13 deletions(-)drivers/clk/rockchip/clk.c +2
-7@@ -359,26 +359,21 @@ static struct rockchip_clk_provider *rockchip_clk_init_base( unsigned long nr_clks, bool has_late_clocks) {struct rockchip_clk_provider *ctx; -struct clk **clk_table;struct clk *default_clk_val;int i; default_clk_val =ERR_PTR (has_late_clocks ? -EPROBE_DEFER : -ENOENT ); - ctx = kzalloc_obj(struct rockchip_clk_provider); + ctx =kzalloc_flex (*ctx, clk_table, nr_clks);if (!ctx)return ERR_PTR (-ENOMEM ); - clk_table = kzalloc_objs(struct clk *, nr_clks); -if (!clk_table) - goto err_free; -for (i =0 ; i < nr_clks; ++i) - clk_table[i] = default_clk_val; + ctx->clk_table[i] = default_clk_val;
Quoted 8 lines
drivers/clk/rockchip/clk.c static struct rockchip_clk_provider *rockchip_clk_init_base( · line 375
Quoted 4 lines
drivers/clk/rockchip/clk.c +1
-2- ctx->reg_base = base; - ctx->clk_data.clks = clk_table; ctx->clk_data.clk_num = nr_clks; + ctx->clk_data.clks = ctx->clk_table;Where's the
__counted_by? Also structclk_onecell_datais embedded inside structrockchip_clk_provider, and I'm not sure offhand how that'll work.
Not present. __counted_by does not work with embedded struct members. No need to add one IMO.
Quoted 43 lines
Brian
Quoted 38 lines
drivers/clk/rockchip/clk.c +1
-4+ ctx->reg_base = base; ctx->cru_node = np;spin_lock_init (&ctx->lock);@@ -388,10 +383,6 @@ static struct rockchip_clk_provider *rockchip_clk_init_base( "rockchip,grf");return ctx; - -err_free: -kfree (ctx); -return ERR_PTR (-ENOMEM ); } struct rockchip_clk_provider *rockchip_clk_init(struct device_node *np,drivers/clk/rockchip/clk.h +2
-1@@ -604,6 +604,7 @@ struct rockchip_aux_grf {* @grf: regmap of the general-register-files syscon * @aux_grf_table: hashtable of auxiliary GRF regmaps, indexed by grf_type * @lock: maintains exclusion between callbacks for a given clock-provider. +* @clk_table: clock lookup table. */ struct rockchip_clk_provider {void __iomem *reg_base;@@ -612,6 +613,7 @@ struct rockchip_clk_provider {struct regmap *grf;DECLARE_HASHTABLE (aux_grf_table,GRF_HASH_ORDER );spinlock_t lock; +struct clk *clk_table[]; };struct rockchip_pll_rate_table { --2.54.0
+ Gustavo
Quoted 54 lines · Rosen Penev
Quoted 45 lines · Brian Masney
Hi Rosen,
Quoted 41 lines · Rosen Penev
Store the clock lookup table in the Rockchip clock provider allocation instead of allocating it separately.
This ties the table lifetime directly to the provider and removes a separate allocation failure path while preserving the
clk_onecell_datalookup interface.Assisted-by Codex:GPT-5.5Signed-off-by Rosen Penev <[email protected]>--- drivers/clk/rockchip/clk.c | 17 ++++------------- drivers/clk/rockchip/clk.h | 2 ++ 2 files changed, 6 insertions(+), 13 deletions(-)drivers/clk/rockchip/clk.c +2
-7@@ -359,26 +359,21 @@ static struct rockchip_clk_provider *rockchip_clk_init_base( unsigned long nr_clks, bool has_late_clocks) {struct rockchip_clk_provider *ctx; -struct clk **clk_table;struct clk *default_clk_val;int i; default_clk_val =ERR_PTR (has_late_clocks ? -EPROBE_DEFER : -ENOENT ); - ctx = kzalloc_obj(struct rockchip_clk_provider); + ctx =kzalloc_flex (*ctx, clk_table, nr_clks);if (!ctx)return ERR_PTR (-ENOMEM ); - clk_table = kzalloc_objs(struct clk *, nr_clks); -if (!clk_table) - goto err_free; -for (i =0 ; i < nr_clks; ++i) - clk_table[i] = default_clk_val; + ctx->clk_table[i] = default_clk_val;Quoted 8 lines
drivers/clk/rockchip/clk.c static struct rockchip_clk_provider *rockchip_clk_init_base( · line 375
Quoted 4 lines
drivers/clk/rockchip/clk.c +1
-2- ctx->reg_base = base; - ctx->clk_data.clks = clk_table; ctx->clk_data.clk_num = nr_clks; + ctx->clk_data.clks = ctx->clk_table;Where's the
__counted_by? Also structclk_onecell_datais embedded inside structrockchip_clk_provider, and I'm not sure offhand how that'll work.
Quoted 2 lines
Not present.
__counted_bydoes not work with embedded struct members. No need to add one IMO.
I'll be honest that I'm not sure what's correct here. I added Gustavo since I saw comments from him before about these types of changes.
Brian
Quoted 58 lines · Brian Masney
+ Gustavo
Quoted 54 lines · Rosen Penev
Quoted 53 lines · Brian Masney
Hi Rosen,
Quoted 35 lines · Rosen Penev
Store the clock lookup table in the Rockchip clock provider allocation instead of allocating it separately.
This ties the table lifetime directly to the provider and removes a separate allocation failure path while preserving the
clk_onecell_datalookup interface.Assisted-by Codex:GPT-5.5Signed-off-by Rosen Penev <[email protected]>--- drivers/clk/rockchip/clk.c | 17 ++++------------- drivers/clk/rockchip/clk.h | 2 ++ 2 files changed, 6 insertions(+), 13 deletions(-)drivers/clk/rockchip/clk.c +1
-4@@ -359,26 +359,21 @@ static struct rockchip_clk_provider *rockchip_clk_init_base( unsigned long nr_clks, bool has_late_clocks) {struct rockchip_clk_provider *ctx; -struct clk **clk_table;struct clk *default_clk_val;int i; default_clk_val =ERR_PTR (has_late_clocks ? -EPROBE_DEFER : -ENOENT ); - ctx = kzalloc_obj(struct rockchip_clk_provider); + ctx =kzalloc_flex (*ctx, clk_table, nr_clks);if (!ctx)return ERR_PTR (-ENOMEM ); - clk_table = kzalloc_objs(struct clk *, nr_clks); -if (!clk_table)drivers/clk/rockchip/clk.c static struct rockchip_clk_provider *rockchip_clk_init_base( · line 375
Quoted 10 lines
drivers/clk/rockchip/clk.c +2
-5- goto err_free; -for (i =0 ; i < nr_clks; ++i) - clk_table[i] = default_clk_val; + ctx->clk_table[i] = default_clk_val; - ctx->reg_base = base; - ctx->clk_data.clks = clk_table; ctx->clk_data.clk_num = nr_clks; + ctx->clk_data.clks = ctx->clk_table;Where's the
__counted_by? Also structclk_onecell_datais embedded inside structrockchip_clk_provider, and I'm not sure offhand how that'll work.
Quoted 5 lines
Quoted 2 lines
Not present.
__counted_bydoes not work with embedded struct members. No need to add one IMO.I'll be honest that I'm not sure what's correct here. I added Gustavo since I saw comments from him before about these types of changes.
Anything else? The comments AFAIK were about descriptions of why the counting variable assignment was moved. There's no counting variable here.
Quoted 3 lines
Brian