mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] pinctrl: starfive: jh7110: use struct_size
@ 2026-04-25  1:40 Rosen Penev
  2026-04-25  8:28 ` Hal Feng
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Rosen Penev @ 2026-04-25  1:40 UTC (permalink / raw)
  To: linux-gpio; +Cc: Emil Renner Berthing, Hal Feng, Linus Walleij, open list

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>
---
 drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c | 12 +++++-------
 drivers/pinctrl/starfive/pinctrl-starfive-jh7110.h |  2 +-
 2 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c b/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c
index e44480e71ea8..3572e8edd9f3 100644
--- 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
 	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);
diff --git a/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.h b/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.h
index 2da2d6858008..188fc9d96269 100644
--- a/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.h
+++ b/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.h
@@ -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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] pinctrl: starfive: jh7110: use struct_size
  2026-04-25  1:40 [PATCH] pinctrl: starfive: jh7110: use struct_size Rosen Penev
@ 2026-04-25  8:28 ` Hal Feng
  2026-04-28 10:37 ` Linus Walleij
  2026-05-12 11:40 ` Geert Uytterhoeven
  2 siblings, 0 replies; 4+ messages in thread
From: Hal Feng @ 2026-04-25  8:28 UTC (permalink / raw)
  To: Rosen Penev, linux-gpio; +Cc: Emil Renner Berthing, Linus Walleij, open list

> On 25.04.26 09:40, Rosen Penev 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@gmail.com>

Looks good.

Acked-by: Hal Feng <hal.feng@starfivetech.com>

Best regards,
Hal

> ---
>  drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c | 12 +++++-------
> drivers/pinctrl/starfive/pinctrl-starfive-jh7110.h |  2 +-
>  2 files changed, 6 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c
> b/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.c
> index e44480e71ea8..3572e8edd9f3 100644
> --- 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
>  	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);
> diff --git a/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.h
> b/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.h
> index 2da2d6858008..188fc9d96269 100644
> --- a/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.h
> +++ b/drivers/pinctrl/starfive/pinctrl-starfive-jh7110.h
> @@ -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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] pinctrl: starfive: jh7110: use struct_size
  2026-04-25  1:40 [PATCH] pinctrl: starfive: jh7110: use struct_size Rosen Penev
  2026-04-25  8:28 ` Hal Feng
@ 2026-04-28 10:37 ` Linus Walleij
  2026-05-12 11:40 ` Geert Uytterhoeven
  2 siblings, 0 replies; 4+ messages in thread
From: Linus Walleij @ 2026-04-28 10:37 UTC (permalink / raw)
  To: Rosen Penev; +Cc: linux-gpio, Emil Renner Berthing, Hal Feng, open list

On Sat, Apr 25, 2026 at 3:40 AM Rosen Penev <rosenp@gmail.com> 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@gmail.com>

Patch applied!

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] pinctrl: starfive: jh7110: use struct_size
  2026-04-25  1:40 [PATCH] pinctrl: starfive: jh7110: use struct_size Rosen Penev
  2026-04-25  8:28 ` Hal Feng
  2026-04-28 10:37 ` Linus Walleij
@ 2026-05-12 11:40 ` Geert Uytterhoeven
  2 siblings, 0 replies; 4+ messages in thread
From: Geert Uytterhoeven @ 2026-05-12 11:40 UTC (permalink / raw)
  To: Rosen Penev
  Cc: linux-gpio, Emil Renner Berthing, Hal Feng, Linus Walleij, open list

Hi Rosen,

On Sat, 25 Apr 2026 at 03:40, Rosen Penev <rosenp@gmail.com> 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@gmail.com>

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@linux-m68k.org

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-05-12 11:41 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-04-25  1:40 [PATCH] pinctrl: starfive: jh7110: use struct_size Rosen Penev
2026-04-25  8:28 ` Hal Feng
2026-04-28 10:37 ` Linus Walleij
2026-05-12 11:40 ` Geert Uytterhoeven

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®