* [PATCH RESEND] clk: tegra: bmp: remove kcalloc
@ 2026-09-29 19:24 Rosen Penev
2026-09-30 7:58 ` Jerome Brunet
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Rosen Penev @ 2026-09-29 19:24 UTC (permalink / raw)
To: linux-clk
Cc: Prashant Gaikwad, Stephen Boyd, Brian Masney, Jerome Brunet,
Thierry Reding, Jonathan Hunter, Kees Cook, Gustavo A. R. Silva,
open list:TEGRA ARCHITECTURE SUPPORT, open list,
open list:KERNEL HARDENING (not covered by other
areas):Keyword:b__counted_by(_le|_be|_ptr)?b
Use a flexible array member to avoid allocating separately.
Use __counted_by for extra runtime analysis.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/clk/tegra/clk-bpmp.c | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/drivers/clk/tegra/clk-bpmp.c b/drivers/clk/tegra/clk-bpmp.c
index 067a8555c4e7..15b976162b59 100644
--- a/drivers/clk/tegra/clk-bpmp.c
+++ b/drivers/clk/tegra/clk-bpmp.c
@@ -32,7 +32,7 @@ struct tegra_bpmp_clk {
unsigned int id;
unsigned int num_parents;
- unsigned int *parents;
+ unsigned int parents[] __counted_by(num_parents);
};
static inline struct tegra_bpmp_clk *to_tegra_bpmp_clk(struct clk_hw *hw)
@@ -518,20 +518,14 @@ tegra_bpmp_clk_register(struct tegra_bpmp *bpmp,
unsigned int i;
int err;
- clk = devm_kzalloc(bpmp->dev, sizeof(*clk), GFP_KERNEL);
+ clk = devm_kzalloc(bpmp->dev, struct_size(clk, parents, info->num_parents), GFP_KERNEL);
if (!clk)
return ERR_PTR(-ENOMEM);
+ clk->num_parents = info->num_parents;
clk->id = info->id;
clk->bpmp = bpmp;
- clk->parents = devm_kcalloc(bpmp->dev, info->num_parents,
- sizeof(*clk->parents), GFP_KERNEL);
- if (!clk->parents)
- return ERR_PTR(-ENOMEM);
-
- clk->num_parents = info->num_parents;
-
/* hardware clock initialization */
memset(&init, 0, sizeof(init));
init.name = info->name;
--
2.55.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RESEND] clk: tegra: bmp: remove kcalloc
2026-09-29 19:24 [PATCH RESEND] clk: tegra: bmp: remove kcalloc Rosen Penev
@ 2026-09-30 7:58 ` Jerome Brunet
2026-09-30 9:29 ` Thierry Reding
2026-09-30 9:33 ` Thierry Reding
2026-09-30 11:06 ` Jon Hunter
2 siblings, 1 reply; 5+ messages in thread
From: Jerome Brunet @ 2026-09-30 7:58 UTC (permalink / raw)
To: Rosen Penev, linux-clk
Cc: Prashant Gaikwad, Stephen Boyd, Brian Masney, Jerome Brunet,
Thierry Reding, Jonathan Hunter, Kees Cook, Gustavo A. R. Silva,
open list:TEGRA ARCHITECTURE SUPPORT, open list,
open list:KERNEL HARDENING (not covered by other
areas):Keyword:b__counted_by(_le|_be|_ptr)?b
On mar. 29 sept. 2026 at 12:24, Rosen Penev <rosenp@gmail.com> wrote:
> Use a flexible array member to avoid allocating separately.
>
> Use __counted_by for extra runtime analysis.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
> drivers/clk/tegra/clk-bpmp.c | 12 +++---------
> 1 file changed, 3 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/clk/tegra/clk-bpmp.c b/drivers/clk/tegra/clk-bpmp.c
> index 067a8555c4e7..15b976162b59 100644
> --- a/drivers/clk/tegra/clk-bpmp.c
> +++ b/drivers/clk/tegra/clk-bpmp.c
> @@ -32,7 +32,7 @@ struct tegra_bpmp_clk {
> unsigned int id;
>
> unsigned int num_parents;
> - unsigned int *parents;
> + unsigned int parents[] __counted_by(num_parents);
> };
>
> static inline struct tegra_bpmp_clk *to_tegra_bpmp_clk(struct clk_hw *hw)
> @@ -518,20 +518,14 @@ tegra_bpmp_clk_register(struct tegra_bpmp *bpmp,
> unsigned int i;
> int err;
>
> - clk = devm_kzalloc(bpmp->dev, sizeof(*clk), GFP_KERNEL);
> + clk = devm_kzalloc(bpmp->dev, struct_size(clk, parents, info->num_parents), GFP_KERNEL);
> if (!clk)
> return ERR_PTR(-ENOMEM);
>
> + clk->num_parents = info->num_parents;
> clk->id = info->id;
> clk->bpmp = bpmp;
>
> - clk->parents = devm_kcalloc(bpmp->dev, info->num_parents,
> - sizeof(*clk->parents), GFP_KERNEL);
> - if (!clk->parents)
> - return ERR_PTR(-ENOMEM);
> -
> - clk->num_parents = info->num_parents;
> -
What is the benefit of doing this ? It looks like you are just trading
one alloc for another here ?
> /* hardware clock initialization */
> memset(&init, 0, sizeof(init));
> init.name = info->name;
> --
> 2.55.0
>
--
Jerome
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RESEND] clk: tegra: bmp: remove kcalloc
2026-09-30 7:58 ` Jerome Brunet
@ 2026-09-30 9:29 ` Thierry Reding
0 siblings, 0 replies; 5+ messages in thread
From: Thierry Reding @ 2026-09-30 9:29 UTC (permalink / raw)
To: Jerome Brunet
Cc: Rosen Penev, linux-clk, Prashant Gaikwad, Stephen Boyd,
Brian Masney, Jerome Brunet, Jonathan Hunter, Kees Cook,
Gustavo A. R. Silva, open list:TEGRA ARCHITECTURE SUPPORT,
open list,
open list:KERNEL HARDENING (not covered by other
areas):Keyword:b__counted_by(_le|_be|_ptr)?b
[-- Attachment #1: Type: text/plain, Size: 1965 bytes --]
On Wed, Sep 30, 2026 at 09:58:18AM +0200, Jerome Brunet wrote:
> On mar. 29 sept. 2026 at 12:24, Rosen Penev <rosenp@gmail.com> wrote:
>
> > Use a flexible array member to avoid allocating separately.
> >
> > Use __counted_by for extra runtime analysis.
> >
> > Signed-off-by: Rosen Penev <rosenp@gmail.com>
> > ---
> > drivers/clk/tegra/clk-bpmp.c | 12 +++---------
> > 1 file changed, 3 insertions(+), 9 deletions(-)
> >
> > diff --git a/drivers/clk/tegra/clk-bpmp.c b/drivers/clk/tegra/clk-bpmp.c
> > index 067a8555c4e7..15b976162b59 100644
> > --- a/drivers/clk/tegra/clk-bpmp.c
> > +++ b/drivers/clk/tegra/clk-bpmp.c
> > @@ -32,7 +32,7 @@ struct tegra_bpmp_clk {
> > unsigned int id;
> >
> > unsigned int num_parents;
> > - unsigned int *parents;
> > + unsigned int parents[] __counted_by(num_parents);
> > };
> >
> > static inline struct tegra_bpmp_clk *to_tegra_bpmp_clk(struct clk_hw *hw)
> > @@ -518,20 +518,14 @@ tegra_bpmp_clk_register(struct tegra_bpmp *bpmp,
> > unsigned int i;
> > int err;
> >
> > - clk = devm_kzalloc(bpmp->dev, sizeof(*clk), GFP_KERNEL);
> > + clk = devm_kzalloc(bpmp->dev, struct_size(clk, parents, info->num_parents), GFP_KERNEL);
> > if (!clk)
> > return ERR_PTR(-ENOMEM);
> >
> > + clk->num_parents = info->num_parents;
> > clk->id = info->id;
> > clk->bpmp = bpmp;
> >
> > - clk->parents = devm_kcalloc(bpmp->dev, info->num_parents,
> > - sizeof(*clk->parents), GFP_KERNEL);
> > - if (!clk->parents)
> > - return ERR_PTR(-ENOMEM);
> > -
> > - clk->num_parents = info->num_parents;
> > -
>
> What is the benefit of doing this ? It looks like you are just trading
> one alloc for another here ?
I think the point is allocating the parents array as part of the main
allocation, so we end up with one allocation instead of two. This avoids
fragmentation and overhead and is possibly a little bit faster.
Seems fine to me.
Thierry
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RESEND] clk: tegra: bmp: remove kcalloc
2026-09-29 19:24 [PATCH RESEND] clk: tegra: bmp: remove kcalloc Rosen Penev
2026-09-30 7:58 ` Jerome Brunet
@ 2026-09-30 9:33 ` Thierry Reding
2026-09-30 11:06 ` Jon Hunter
2 siblings, 0 replies; 5+ messages in thread
From: Thierry Reding @ 2026-09-30 9:33 UTC (permalink / raw)
To: Rosen Penev
Cc: linux-clk, Prashant Gaikwad, Stephen Boyd, Brian Masney,
Jerome Brunet, Jonathan Hunter, Kees Cook, Gustavo A. R. Silva,
open list:TEGRA ARCHITECTURE SUPPORT, open list,
open list:KERNEL HARDENING (not covered by other
areas):Keyword:b__counted_by(_le|_be|_ptr)?b
[-- Attachment #1: Type: text/plain, Size: 1361 bytes --]
On Tue, Sep 29, 2026 at 12:24:37PM -0700, Rosen Penev wrote:
> Use a flexible array member to avoid allocating separately.
>
> Use __counted_by for extra runtime analysis.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
> drivers/clk/tegra/clk-bpmp.c | 12 +++---------
> 1 file changed, 3 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/clk/tegra/clk-bpmp.c b/drivers/clk/tegra/clk-bpmp.c
> index 067a8555c4e7..15b976162b59 100644
> --- a/drivers/clk/tegra/clk-bpmp.c
> +++ b/drivers/clk/tegra/clk-bpmp.c
> @@ -32,7 +32,7 @@ struct tegra_bpmp_clk {
> unsigned int id;
>
> unsigned int num_parents;
> - unsigned int *parents;
> + unsigned int parents[] __counted_by(num_parents);
> };
>
> static inline struct tegra_bpmp_clk *to_tegra_bpmp_clk(struct clk_hw *hw)
> @@ -518,20 +518,14 @@ tegra_bpmp_clk_register(struct tegra_bpmp *bpmp,
> unsigned int i;
> int err;
>
> - clk = devm_kzalloc(bpmp->dev, sizeof(*clk), GFP_KERNEL);
> + clk = devm_kzalloc(bpmp->dev, struct_size(clk, parents, info->num_parents), GFP_KERNEL);
k{m,z}alloc_flex() exists for this, but there's no devm variant of
those, so I guess someone should add one. In the meantime, this is as
good as it's going to get for now:
Reviewed-by: Thierry Reding <treding@nvidia.com>
Acked-by: Thierry Reding <treding@nvidia.com>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH RESEND] clk: tegra: bmp: remove kcalloc
2026-09-29 19:24 [PATCH RESEND] clk: tegra: bmp: remove kcalloc Rosen Penev
2026-09-30 7:58 ` Jerome Brunet
2026-09-30 9:33 ` Thierry Reding
@ 2026-09-30 11:06 ` Jon Hunter
2 siblings, 0 replies; 5+ messages in thread
From: Jon Hunter @ 2026-09-30 11:06 UTC (permalink / raw)
To: Rosen Penev, linux-clk
Cc: Prashant Gaikwad, Stephen Boyd, Brian Masney, Jerome Brunet,
Thierry Reding, Kees Cook, Gustavo A. R. Silva,
open list:TEGRA ARCHITECTURE SUPPORT, open list,
open list:KERNEL HARDENING (not covered by other
areas):Keyword:b__counted_by(_le|_be|_ptr)?b
On 29/09/2026 20:24, Rosen Penev wrote:
> Use a flexible array member to avoid allocating separately.
>
> Use __counted_by for extra runtime analysis.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
Please fix the subject prefix, it should be 'clk: tegra: bpmp:'
Jon
--
nvpublic
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-09-30 11:07 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-29 19:24 [PATCH RESEND] clk: tegra: bmp: remove kcalloc Rosen Penev
2026-09-30 7:58 ` Jerome Brunet
2026-09-30 9:29 ` Thierry Reding
2026-09-30 9:33 ` Thierry Reding
2026-09-30 11:06 ` Jon Hunter
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®