clk: renesas: cpg-mssr: use struct_size
Subsystems (2)
PATCH 1/1 clk: renesas: cpg-mssr: use struct_size
struct_size is what is normally used when a flexible array member is present to avoid accidental mistakes. pm_size is still needed for the memcpy call below.
Added __counted_by for extra runtime analysis.
Signed-off-by Rosen Penev <[email protected]>
--- drivers/clk/renesas/renesas-cpg-mssr.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/renesas/renesas-cpg-mssr.c +2 -2
@@ -569,7 +569,7 @@ static void __init cpg_mssr_register_mod_clk(const struct mssr_mod_clk *mod,struct cpg_mssr_clk_domain {struct generic_pm_domain genpd;unsigned int num_core_pm_clks; -unsigned int core_pm_clks[]; + unsigned int core_pm_clks[] __counted_by(num_core_pm_clks); };static struct cpg_mssr_clk_domain *cpg_mssr_clk_domain;
@@ -667,7 +667,7 @@ static int __init cpg_mssr_add_clk_domain(struct device *dev,size_t pm_size = num_core_pm_clks *sizeof (core_pm_clks[0 ]);int ret; - pd =devm_kzalloc (dev,sizeof (*pd) + pm_size,GFP_KERNEL ); + pd =devm_kzalloc (dev,struct_size (pd, core_pm_clks, num_core_pm_clks),GFP_KERNEL );if (!pd)return -ENOMEM ;
Signature · 1 line
2.53.0
Quoted 7 lines · Rosen Penev
struct_sizeis what is normally used when a flexible array member is present to avoid accidental mistakes.pm_sizeis still needed for the memcpy call below.Added
__counted_byfor extra runtime analysis.Signed-off-by Rosen Penev <[email protected]>
FTR, no changes in generated code.
Reviewed-by Geert Uytterhoeven <[email protected]>
i.e. will queue in renesas-clk for v7.1.
Gr{oetje,eeting}s,
Geert
Signature · 5 lines
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected] In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that. -- Linus Torvalds