linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mailbox: zynq: Switch to flexible array to simplify code
@ 2022-11-20  8:25 Christophe JAILLET
  2022-12-23  2:34 ` Tanmay Shah
  2022-12-23  2:44 ` [PATCH] mailbox: zynq: Switch to flexible array to simplify code Tanmay Shah
  0 siblings, 2 replies; 3+ messages in thread
From: Christophe JAILLET @ 2022-11-20  8:25 UTC (permalink / raw)
  To: Jassi Brar, Michal Simek
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-arm-kernel

Using flexible array is more straight forward. It
  - saves 1 pointer in the 'zynqmp_ipi_pdata' structure
  - saves an indirection when using this array
  - saves some LoC and avoids some always spurious pointer arithmetic

Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
---
Compile tested only
---
 drivers/mailbox/zynqmp-ipi-mailbox.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/mailbox/zynqmp-ipi-mailbox.c b/drivers/mailbox/zynqmp-ipi-mailbox.c
index 31a0fa914274..68e5726f5157 100644
--- a/drivers/mailbox/zynqmp-ipi-mailbox.c
+++ b/drivers/mailbox/zynqmp-ipi-mailbox.c
@@ -110,7 +110,7 @@ struct zynqmp_ipi_pdata {
 	unsigned int method;
 	u32 local_id;
 	int num_mboxes;
-	struct zynqmp_ipi_mbox *ipi_mboxes;
+	struct zynqmp_ipi_mbox ipi_mboxes[];
 };
 
 static struct device_driver zynqmp_ipi_mbox_driver = {
@@ -633,7 +633,7 @@ static int zynqmp_ipi_probe(struct platform_device *pdev)
 	int num_mboxes, ret = -EINVAL;
 
 	num_mboxes = of_get_child_count(np);
-	pdata = devm_kzalloc(dev, sizeof(*pdata) + (num_mboxes * sizeof(*mbox)),
+	pdata = devm_kzalloc(dev, struct_size(pdata, ipi_mboxes, num_mboxes),
 			     GFP_KERNEL);
 	if (!pdata)
 		return -ENOMEM;
@@ -647,8 +647,6 @@ static int zynqmp_ipi_probe(struct platform_device *pdev)
 	}
 
 	pdata->num_mboxes = num_mboxes;
-	pdata->ipi_mboxes = (struct zynqmp_ipi_mbox *)
-			    ((char *)pdata + sizeof(*pdata));
 
 	mbox = pdata->ipi_mboxes;
 	for_each_available_child_of_node(np, nc) {
-- 
2.34.1


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

* (no subject)
  2022-11-20  8:25 [PATCH] mailbox: zynq: Switch to flexible array to simplify code Christophe JAILLET
@ 2022-12-23  2:34 ` Tanmay Shah
  2022-12-23  2:44 ` [PATCH] mailbox: zynq: Switch to flexible array to simplify code Tanmay Shah
  1 sibling, 0 replies; 3+ messages in thread
From: Tanmay Shah @ 2022-12-23  2:34 UTC (permalink / raw)
  To: christophe.jaillet
  Cc: jassisinghbrar, kernel-janitors, linux-arm-kernel, linux-kernel,
	michal.simek, tanmay.shah

Thanks for your patch. The patch looks good to me.

From 48e51754dd7cd49abdf3adc7a01e6863bf5e3764 Mon Sep 17 00:00:00 2001
From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Date: Sun, 20 Nov 2022 09:25:54 +0100
Subject: [PATCH] mailbox: zynq: Switch to flexible array to simplify code

>Using flexible array is more straight forward. It
>  - saves 1 pointer in the 'zynqmp_ipi_pdata' structure
>  - saves an indirection when using this array
>  - saves some LoC and avoids some always spurious pointer arithmetic
>
>Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>---
> drivers/mailbox/zynqmp-ipi-mailbox.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
>diff --git a/drivers/mailbox/zynqmp-ipi-mailbox.c b/drivers/mailbox/zynqmp-ipi-mailbox.c
>index 12e004ff1a14..a4c8d23c76e2 100644
>--- a/drivers/mailbox/zynqmp-ipi-mailbox.c
>+++ b/drivers/mailbox/zynqmp-ipi-mailbox.c
>@@ -110,7 +110,7 @@ struct zynqmp_ipi_pdata {
> 	unsigned int method;
> 	u32 local_id;
> 	int num_mboxes;
>-	struct zynqmp_ipi_mbox *ipi_mboxes;
>+	struct zynqmp_ipi_mbox ipi_mboxes[];
> };
> 
> static struct device_driver zynqmp_ipi_mbox_driver = {
>@@ -635,7 +635,7 @@ static int zynqmp_ipi_probe(struct platform_device *pdev)
> 	int num_mboxes, ret = -EINVAL;
> 
> 	num_mboxes = of_get_child_count(np);
>-	pdata = devm_kzalloc(dev, sizeof(*pdata) + (num_mboxes * sizeof(*mbox)),
>+	pdata = devm_kzalloc(dev, struct_size(pdata, ipi_mboxes, num_mboxes),
> 			     GFP_KERNEL);
> 	if (!pdata)
> 		return -ENOMEM;
>@@ -649,8 +649,6 @@ static int zynqmp_ipi_probe(struct platform_device *pdev)
> 	}
> 
> 	pdata->num_mboxes = num_mboxes;
>-	pdata->ipi_mboxes = (struct zynqmp_ipi_mbox *)
>-			    ((char *)pdata + sizeof(*pdata));
> 
> 	mbox = pdata->ipi_mboxes;
> 	for_each_available_child_of_node(np, nc) {
>
>-- 
>2.25.1


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

* RE: [PATCH] mailbox: zynq: Switch to flexible array to simplify code
  2022-11-20  8:25 [PATCH] mailbox: zynq: Switch to flexible array to simplify code Christophe JAILLET
  2022-12-23  2:34 ` Tanmay Shah
@ 2022-12-23  2:44 ` Tanmay Shah
  1 sibling, 0 replies; 3+ messages in thread
From: Tanmay Shah @ 2022-12-23  2:44 UTC (permalink / raw)
  To: christophe.jaillet
  Cc: jassisinghbrar, kernel-janitors, linux-arm-kernel, linux-kernel,
	michal.simek, tanmay.shah

Reviewed-by: Tanmay Shah <tanmay.shah@amd.com>

Thanks for your patch. The patch looks good to me.

(Update: Fixed subject of email)

From 48e51754dd7cd49abdf3adc7a01e6863bf5e3764 Mon Sep 17 00:00:00 2001
>From: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>Date: Sun, 20 Nov 2022 09:25:54 +0100
>Subject: [PATCH] mailbox: zynq: Switch to flexible array to simplify code
>
>Using flexible array is more straight forward. It
>  - saves 1 pointer in the 'zynqmp_ipi_pdata' structure
>  - saves an indirection when using this array
>  - saves some LoC and avoids some always spurious pointer arithmetic
>
>Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
>---
> drivers/mailbox/zynqmp-ipi-mailbox.c | 6 ++----
> 1 file changed, 2 insertions(+), 4 deletions(-)
>
>diff --git a/drivers/mailbox/zynqmp-ipi-mailbox.c b/drivers/mailbox/zynqmp-ipi-mailbox.c
>index 12e004ff1a14..a4c8d23c76e2 100644
>--- a/drivers/mailbox/zynqmp-ipi-mailbox.c
>+++ b/drivers/mailbox/zynqmp-ipi-mailbox.c
>@@ -110,7 +110,7 @@ struct zynqmp_ipi_pdata {
> 	unsigned int method;
> 	u32 local_id;
> 	int num_mboxes;
>-	struct zynqmp_ipi_mbox *ipi_mboxes;
>+	struct zynqmp_ipi_mbox ipi_mboxes[];
> };
> 
> static struct device_driver zynqmp_ipi_mbox_driver = {
>@@ -635,7 +635,7 @@ static int zynqmp_ipi_probe(struct platform_device *pdev)
> 	int num_mboxes, ret = -EINVAL;
> 
> 	num_mboxes = of_get_child_count(np);
>-	pdata = devm_kzalloc(dev, sizeof(*pdata) + (num_mboxes * sizeof(*mbox)),
>+	pdata = devm_kzalloc(dev, struct_size(pdata, ipi_mboxes, num_mboxes),
> 			     GFP_KERNEL);
> 	if (!pdata)
> 		return -ENOMEM;
>@@ -649,8 +649,6 @@ static int zynqmp_ipi_probe(struct platform_device *pdev)
> 	}
> 
> 	pdata->num_mboxes = num_mboxes;
>-	pdata->ipi_mboxes = (struct zynqmp_ipi_mbox *)
>-			    ((char *)pdata + sizeof(*pdata));
> 
> 	mbox = pdata->ipi_mboxes;
> 	for_each_available_child_of_node(np, nc) {
>
>-- 
>2.25.1


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

end of thread, other threads:[~2022-12-23  2:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-20  8:25 [PATCH] mailbox: zynq: Switch to flexible array to simplify code Christophe JAILLET
2022-12-23  2:34 ` Tanmay Shah
2022-12-23  2:44 ` [PATCH] mailbox: zynq: Switch to flexible array to simplify code Tanmay Shah

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).