Skip to contentSkip to conversation

clk: renesas: cpg-mssr: use struct_size

PATCH In review Rosen Penev 2 participants 2 messages Mar 24 – Mar 25

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

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.

---
 drivers/clk/renesas/renesas-cpg-mssr.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/renesas/renesas-cpg-mssr.c +2 -2
index 64a432fd0e8a..26ea85cfaa02 100644
@@ -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
Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Rosen Penev

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.

FTR, no changes in generated code.

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