pinctrl: starfive: jh7110: use struct_size

Instead of an extra kcalloc, Use a flexible array member to combine
allocations. Saves a pointer in the struct.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
Acked-by: Hal Feng <hal.feng@starfivetech.com>
Signed-off-by: Linus Walleij <linusw@kernel.org>
This commit is contained in:
Rosen Penev 2026-04-24 18:40:29 -07:00 committed by Linus Walleij
parent b316171846
commit 87182ef0bf
2 changed files with 6 additions and 8 deletions

View File

@ -857,17 +857,15 @@ int jh7110_pinctrl_probe(struct platform_device *pdev)
return -EINVAL;
}
#if IS_ENABLED(CONFIG_PM_SLEEP)
sfp = devm_kzalloc(dev, struct_size(sfp, saved_regs, info->nsaved_regs),
GFP_KERNEL);
#else
sfp = devm_kzalloc(dev, sizeof(*sfp), GFP_KERNEL);
#endif
if (!sfp)
return -ENOMEM;
#if IS_ENABLED(CONFIG_PM_SLEEP)
sfp->saved_regs = devm_kcalloc(dev, info->nsaved_regs,
sizeof(*sfp->saved_regs), GFP_KERNEL);
if (!sfp->saved_regs)
return -ENOMEM;
#endif
sfp->base = devm_platform_ioremap_resource(pdev, 0);
if (IS_ERR(sfp->base))
return PTR_ERR(sfp->base);

View File

@ -21,7 +21,7 @@ struct jh7110_pinctrl {
/* register read/write mutex */
struct mutex mutex;
const struct jh7110_pinctrl_soc_info *info;
u32 *saved_regs;
u32 saved_regs[];
};
struct jh7110_gpio_irq_reg {