public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH] mailbox: rockchip: kzalloc + kcalloc to kzalloc
@ 2026-03-11  0:37 Rosen Penev
  2026-03-29 16:28 ` Jassi Brar
  0 siblings, 1 reply; 2+ messages in thread
From: Rosen Penev @ 2026-03-11  0:37 UTC (permalink / raw)
  To: linux-kernel
  Cc: Jassi Brar, Heiko Stuebner,
	moderated list:ARM/Rockchip SoC support,
	open list:ARM/Rockchip SoC support

Use a flexible array member to reduce allocations.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/mailbox/rockchip-mailbox.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)

diff --git a/drivers/mailbox/rockchip-mailbox.c b/drivers/mailbox/rockchip-mailbox.c
index 4d966cb2ed03..a1a7dee64356 100644
--- a/drivers/mailbox/rockchip-mailbox.c
+++ b/drivers/mailbox/rockchip-mailbox.c
@@ -46,7 +46,7 @@ struct rockchip_mbox {
 	/* The maximum size of buf for each channel */
 	u32 buf_size;
 
-	struct rockchip_mbox_chan *chans;
+	struct rockchip_mbox_chan chans[];
 };
 
 static int rockchip_mbox_send_data(struct mbox_chan *chan, void *data)
@@ -173,15 +173,10 @@ static int rockchip_mbox_probe(struct platform_device *pdev)
 
 	drv_data = (const struct rockchip_mbox_data *) device_get_match_data(&pdev->dev);
 
-	mb = devm_kzalloc(&pdev->dev, sizeof(*mb), GFP_KERNEL);
+	mb = devm_kzalloc(&pdev->dev, struct_size(mb, chans, drv_data->num_chans), GFP_KERNEL);
 	if (!mb)
 		return -ENOMEM;
 
-	mb->chans = devm_kcalloc(&pdev->dev, drv_data->num_chans,
-				 sizeof(*mb->chans), GFP_KERNEL);
-	if (!mb->chans)
-		return -ENOMEM;
-
 	mb->mbox.chans = devm_kcalloc(&pdev->dev, drv_data->num_chans,
 				      sizeof(*mb->mbox.chans), GFP_KERNEL);
 	if (!mb->mbox.chans)
-- 
2.53.0



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

* Re: [PATCH] mailbox: rockchip: kzalloc + kcalloc to kzalloc
  2026-03-11  0:37 [PATCH] mailbox: rockchip: kzalloc + kcalloc to kzalloc Rosen Penev
@ 2026-03-29 16:28 ` Jassi Brar
  0 siblings, 0 replies; 2+ messages in thread
From: Jassi Brar @ 2026-03-29 16:28 UTC (permalink / raw)
  To: Rosen Penev
  Cc: linux-kernel, Heiko Stuebner,
	moderated list:ARM/Rockchip SoC support,
	open list:ARM/Rockchip SoC support

On Tue, Mar 10, 2026 at 7:38 PM Rosen Penev <rosenp@gmail.com> wrote:
>
> Use a flexible array member to reduce allocations.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  drivers/mailbox/rockchip-mailbox.c | 9 ++-------
>  1 file changed, 2 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/mailbox/rockchip-mailbox.c b/drivers/mailbox/rockchip-mailbox.c
> index 4d966cb2ed03..a1a7dee64356 100644
> --- a/drivers/mailbox/rockchip-mailbox.c
> +++ b/drivers/mailbox/rockchip-mailbox.c
> @@ -46,7 +46,7 @@ struct rockchip_mbox {
>         /* The maximum size of buf for each channel */
>         u32 buf_size;
>
> -       struct rockchip_mbox_chan *chans;
> +       struct rockchip_mbox_chan chans[];
>  };
>
>  static int rockchip_mbox_send_data(struct mbox_chan *chan, void *data)
> @@ -173,15 +173,10 @@ static int rockchip_mbox_probe(struct platform_device *pdev)
>
>         drv_data = (const struct rockchip_mbox_data *) device_get_match_data(&pdev->dev);
>
> -       mb = devm_kzalloc(&pdev->dev, sizeof(*mb), GFP_KERNEL);
> +       mb = devm_kzalloc(&pdev->dev, struct_size(mb, chans, drv_data->num_chans), GFP_KERNEL);
>         if (!mb)
>                 return -ENOMEM;
>
> -       mb->chans = devm_kcalloc(&pdev->dev, drv_data->num_chans,
> -                                sizeof(*mb->chans), GFP_KERNEL);
> -       if (!mb->chans)
> -               return -ENOMEM;
> -
>         mb->mbox.chans = devm_kcalloc(&pdev->dev, drv_data->num_chans,
>                                       sizeof(*mb->mbox.chans), GFP_KERNEL);
>         if (!mb->mbox.chans)
> --
> 2.53.0
>
Applied to mailbox/for-next
Thanks
Jassi


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

end of thread, other threads:[~2026-03-29 16:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-11  0:37 [PATCH] mailbox: rockchip: kzalloc + kcalloc to kzalloc Rosen Penev
2026-03-29 16:28 ` Jassi Brar

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