Re: [PATCH] pinctrl: starfive: jh7110: use struct_size
From: Geert Uytterhoeven
Date: Tue May 12 2026 - 07:41:16 EST
Hi Rosen,
On Sat, 25 Apr 2026 at 03:40, Rosen Penev <rosenp@xxxxxxxxx> wrote:
> 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@xxxxxxxxx>
Thanks for your patch, which is now commit 87182ef0bf93c283 ("pinctrl:
starfive: jh7110: use struct_size") in pinctrl/for-next.
> --- a/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c
> +++ b/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c
> @@ -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
You can avoid the #ifdef and increase compile-coverage using
unsigned int n = IS_ENABLED(CONFIG_PM_SLEEP) ? info->nsaved_regs : 0;
...
sfp = devm_kzalloc(dev, struct_size(sfp, saved_regs, n, GFP_KERNEL);
> 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);
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@xxxxxxxxxxxxxx
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