Skip to contentSkip to conversation

mailbox: rockchip: kzalloc + kcalloc to kzalloc

PATCH Applied Rosen Penev 2 participants 2 messages Mar 11 – Mar 29

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mailbox: rockchip: kzalloc + kcalloc to kzalloc

Use a flexible array member to reduce allocations.

---
 drivers/mailbox/rockchip-mailbox.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/mailbox/rockchip-mailbox.c +2 -7
index 4d966cb2ed03..a1a7dee64356 100644
@@ -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)
Signature · 1 line
2.53.0
maintainer Applied
#1 lore raw
Quoted 39 lines · Rosen Penev

Use a flexible array member to reduce allocations.

---
 drivers/mailbox/rockchip-mailbox.c | 9 ++-------
 1 file changed, 2 insertions(+), 7 deletions(-)
drivers/mailbox/rockchip-mailbox.c +2 -8
index 4d966cb2ed03..a1a7dee64356 100644
@@ -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)
--
Quoted 2 lines

2.53.0

Applied to mailbox/for-next
Thanks
Jassi