pinctrl: starfive: jh7110: use struct_size
Subsystems (3)
PATCH 1/1 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.
--- drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c | 12 +++++------- drivers/pinctrl/starfive/pinctrl-starfive-jh7110.h | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-)
drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c +5 -7
@@ -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);
drivers/pinctrl/starfive/pinctrl-starfive-jh7110.h +1 -1
@@ -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 {
Signature · 1 line
2.54.0
Quoted 5 lines · Rosen Penev
Instead of an extra kcalloc, Use a flexible array member to combine allocations. Saves a pointer in the struct.
Signed-off-by Rosen Penev <[email protected]>
Looks good.
Best regards,
Hal
Quoted 50 lines
--- drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c | 12 +++++------- drivers/pinctrl/starfive/pinctrl-starfive-jh7110.h | 2 +- 2 files changed, 6 insertions(+), 8 deletions(-)drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c +5
-7@@ -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))drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c +0
-0return PTR_ERR (sfp->base);drivers/pinctrl/starfive/pinctrl-starfive-jh7110.h +1
-2@@ -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 { --2.54.0
Linus Walleij
maintainerQuoted 4 lines · Rosen Penev
Instead of an extra kcalloc, Use a flexible array member to combine allocations. Saves a pointer in the struct.
Signed-off-by Rosen Penev <[email protected]>
Patch applied!
Yours,
Linus Walleij
Hi Rosen,
Quoted 4 lines · Rosen Penev
Instead of an extra kcalloc, Use a flexible array member to combine allocations. Saves a pointer in the struct.
Signed-off-by Rosen Penev <[email protected]>
Thanks for your patch, which is now commit 87182ef0bf93c283 ("pinctrl:
starfive: jh7110: use struct_size") in pinctrl/for-next.
drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c int jh7110_pinctrl_probe(struct platform_device *pdev) · line 865
Quoted 12 lines
drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c +5
-0@@ -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);drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c int jh7110_pinctrl_probe(struct platform_device *pdev) · line 871
Quoted 13 lines
drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c +0
-7if (!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
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