clk: renesas: cpg-mssr: Use struct_size() helper

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 <rosenp@gmail.com>
Reviewed-by: Geert Uytterhoeven <geert+renesas@glider.be>
Link: https://patch.msgid.link/20260324021103.13651-1-rosenp@gmail.com
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
This commit is contained in:
Rosen Penev 2026-03-23 19:11:03 -07:00 committed by Geert Uytterhoeven
parent d85cb4ff46
commit 0e590f4d99

View File

@ -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;