* [PATCH] clk: rockchip: Use flexible array for clock table
@ 2026-05-11 3:22 Rosen Penev
2026-05-11 16:06 ` Brian Masney
0 siblings, 1 reply; 4+ messages in thread
From: Rosen Penev @ 2026-05-11 3:22 UTC (permalink / raw)
To: linux-clk
Cc: Michael Turquette, Stephen Boyd, Brian Masney, Heiko Stuebner,
moderated list:ARM/Rockchip SoC support,
open list:ARM/Rockchip SoC support, open list
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.
Assisted-by: Codex:GPT-5.5
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/clk/rockchip/clk.c | 17 ++++-------------
drivers/clk/rockchip/clk.h | 2 ++
2 files changed, 6 insertions(+), 13 deletions(-)
diff --git a/drivers/clk/rockchip/clk.c b/drivers/clk/rockchip/clk.c
index ee8c79b938d3..dbb4b6f33abb 100644
--- a/drivers/clk/rockchip/clk.c
+++ b/drivers/clk/rockchip/clk.c
@@ -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,
diff --git a/drivers/clk/rockchip/clk.h b/drivers/clk/rockchip/clk.h
index 9e3503e2ffc2..d4033bf750f5 100644
--- a/drivers/clk/rockchip/clk.h
+++ b/drivers/clk/rockchip/clk.h
@@ -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
^ permalink raw reply related [flat|nested] 4+ messages in thread* Re: [PATCH] clk: rockchip: Use flexible array for clock table
2026-05-11 3:22 [PATCH] clk: rockchip: Use flexible array for clock table Rosen Penev
@ 2026-05-11 16:06 ` Brian Masney
2026-05-11 19:08 ` Rosen Penev
0 siblings, 1 reply; 4+ messages in thread
From: Brian Masney @ 2026-05-11 16:06 UTC (permalink / raw)
To: Rosen Penev
Cc: linux-clk, Michael Turquette, Stephen Boyd, Heiko Stuebner,
moderated list:ARM/Rockchip SoC support,
open list:ARM/Rockchip SoC support, open list
Hi Rosen,
On Sun, May 10, 2026 at 08:22:52PM -0700, Rosen Penev wrote:
> 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.
>
> Assisted-by: Codex:GPT-5.5
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
> drivers/clk/rockchip/clk.c | 17 ++++-------------
> drivers/clk/rockchip/clk.h | 2 ++
> 2 files changed, 6 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/clk/rockchip/clk.c b/drivers/clk/rockchip/clk.c
> index ee8c79b938d3..dbb4b6f33abb 100644
> --- a/drivers/clk/rockchip/clk.c
> +++ b/drivers/clk/rockchip/clk.c
> @@ -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;
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
> + 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,
> diff --git a/drivers/clk/rockchip/clk.h b/drivers/clk/rockchip/clk.h
> index 9e3503e2ffc2..d4033bf750f5 100644
> --- a/drivers/clk/rockchip/clk.h
> +++ b/drivers/clk/rockchip/clk.h
> @@ -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
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] clk: rockchip: Use flexible array for clock table
2026-05-11 16:06 ` Brian Masney
@ 2026-05-11 19:08 ` Rosen Penev
2026-05-11 20:41 ` Brian Masney
0 siblings, 1 reply; 4+ messages in thread
From: Rosen Penev @ 2026-05-11 19:08 UTC (permalink / raw)
To: Brian Masney
Cc: linux-clk, Michael Turquette, Stephen Boyd, Heiko Stuebner,
moderated list:ARM/Rockchip SoC support,
open list:ARM/Rockchip SoC support, open list
On Mon, May 11, 2026 at 9:06 AM Brian Masney <bmasney@redhat.com> wrote:
>
> Hi Rosen,
>
> On Sun, May 10, 2026 at 08:22:52PM -0700, Rosen Penev wrote:
> > 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.
> >
> > Assisted-by: Codex:GPT-5.5
> > Signed-off-by: Rosen Penev <rosenp@gmail.com>
> > ---
> > drivers/clk/rockchip/clk.c | 17 ++++-------------
> > drivers/clk/rockchip/clk.h | 2 ++
> > 2 files changed, 6 insertions(+), 13 deletions(-)
> >
> > diff --git a/drivers/clk/rockchip/clk.c b/drivers/clk/rockchip/clk.c
> > index ee8c79b938d3..dbb4b6f33abb 100644
> > --- a/drivers/clk/rockchip/clk.c
> > +++ b/drivers/clk/rockchip/clk.c
> > @@ -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;
>
> 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.
Not present. __counted_by does not work with embedded struct members.
No need to add one IMO.
>
> Brian
>
>
> > + 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,
> > diff --git a/drivers/clk/rockchip/clk.h b/drivers/clk/rockchip/clk.h
> > index 9e3503e2ffc2..d4033bf750f5 100644
> > --- a/drivers/clk/rockchip/clk.h
> > +++ b/drivers/clk/rockchip/clk.h
> > @@ -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
> >
>
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH] clk: rockchip: Use flexible array for clock table
2026-05-11 19:08 ` Rosen Penev
@ 2026-05-11 20:41 ` Brian Masney
0 siblings, 0 replies; 4+ messages in thread
From: Brian Masney @ 2026-05-11 20:41 UTC (permalink / raw)
To: Rosen Penev
Cc: linux-clk, Michael Turquette, Stephen Boyd, Heiko Stuebner,
moderated list:ARM/Rockchip SoC support,
open list:ARM/Rockchip SoC support, open list,
Gustavo A. R. Silva
+ Gustavo
On Mon, May 11, 2026 at 12:08:56PM -0700, Rosen Penev wrote:
> On Mon, May 11, 2026 at 9:06 AM Brian Masney <bmasney@redhat.com> wrote:
> >
> > Hi Rosen,
> >
> > On Sun, May 10, 2026 at 08:22:52PM -0700, Rosen Penev wrote:
> > > 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.
> > >
> > > Assisted-by: Codex:GPT-5.5
> > > Signed-off-by: Rosen Penev <rosenp@gmail.com>
> > > ---
> > > drivers/clk/rockchip/clk.c | 17 ++++-------------
> > > drivers/clk/rockchip/clk.h | 2 ++
> > > 2 files changed, 6 insertions(+), 13 deletions(-)
> > >
> > > diff --git a/drivers/clk/rockchip/clk.c b/drivers/clk/rockchip/clk.c
> > > index ee8c79b938d3..dbb4b6f33abb 100644
> > > --- a/drivers/clk/rockchip/clk.c
> > > +++ b/drivers/clk/rockchip/clk.c
> > > @@ -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;
> >
> > 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.
> Not present. __counted_by does 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
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-05-11 20:41 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-11 3:22 [PATCH] clk: rockchip: Use flexible array for clock table Rosen Penev
2026-05-11 16:06 ` Brian Masney
2026-05-11 19:08 ` Rosen Penev
2026-05-11 20:41 ` Brian Masney
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox