All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpio: htc-egpio: allocate irq with the main struct
@ 2026-03-09 22:52 Rosen Penev
  2026-03-11  8:46 ` Bartosz Golaszewski
  0 siblings, 1 reply; 2+ messages in thread
From: Rosen Penev @ 2026-03-09 22:52 UTC (permalink / raw)
  To: linux-gpio
  Cc: Linus Walleij, linux-hardening, gustavoars, Bartosz Golaszewski,
	Kees Cook, open list

Use a flexible array member to combinwe allocations.

Add __counted_by for extra runtime analysis.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 drivers/gpio/gpio-htc-egpio.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/drivers/gpio/gpio-htc-egpio.c b/drivers/gpio/gpio-htc-egpio.c
index 72935d6dbebf..d15423c718d0 100644
--- a/drivers/gpio/gpio-htc-egpio.c
+++ b/drivers/gpio/gpio-htc-egpio.c
@@ -46,8 +46,8 @@ struct egpio_info {
 	uint              chained_irq;
 
 	/* egpio info */
-	struct egpio_chip *chip;
 	int               nchips;
+	struct egpio_chip chip[] __counted_by(nchips);
 };
 
 static inline void egpio_writew(u16 value, struct egpio_info *ei, int reg)
@@ -270,10 +270,12 @@ static int __init egpio_probe(struct platform_device *pdev)
 	int               i;
 
 	/* Initialize ei data structure. */
-	ei = devm_kzalloc(&pdev->dev, sizeof(*ei), GFP_KERNEL);
+	ei = devm_kzalloc(&pdev->dev, struct_size(ei, chip, pdata->num_chips), GFP_KERNEL);
 	if (!ei)
 		return -ENOMEM;
 
+	ei->nchips = pdata->num_chips;
+
 	spin_lock_init(&ei->lock);
 
 	/* Find chained irq */
@@ -302,13 +304,6 @@ static int __init egpio_probe(struct platform_device *pdev)
 
 	platform_set_drvdata(pdev, ei);
 
-	ei->nchips = pdata->num_chips;
-	ei->chip = devm_kcalloc(&pdev->dev,
-				ei->nchips, sizeof(struct egpio_chip),
-				GFP_KERNEL);
-	if (!ei->chip)
-		return -ENOMEM;
-
 	for (i = 0; i < ei->nchips; i++) {
 		ei->chip[i].reg_start = pdata->chip[i].reg_start;
 		ei->chip[i].cached_values = pdata->chip[i].initial_values;
-- 
2.53.0


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

* Re: [PATCH] gpio: htc-egpio: allocate irq with the main struct
  2026-03-09 22:52 [PATCH] gpio: htc-egpio: allocate irq with the main struct Rosen Penev
@ 2026-03-11  8:46 ` Bartosz Golaszewski
  0 siblings, 0 replies; 2+ messages in thread
From: Bartosz Golaszewski @ 2026-03-11  8:46 UTC (permalink / raw)
  To: linux-gpio, Rosen Penev
  Cc: Bartosz Golaszewski, Linus Walleij, linux-hardening, gustavoars,
	Bartosz Golaszewski, Kees Cook, linux-kernel


On Mon, 09 Mar 2026 15:52:04 -0700, Rosen Penev wrote:
> Use a flexible array member to combinwe allocations.
> 
> Add __counted_by for extra runtime analysis.
> 
> 

Applied, thanks!

[1/1] gpio: htc-egpio: allocate irq with the main struct
      https://git.kernel.org/brgl/c/223d9a310c7bd785f08320de8d2b66a5af6a25e6

Best regards,
-- 
Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>

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

end of thread, other threads:[~2026-03-11  8:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-09 22:52 [PATCH] gpio: htc-egpio: allocate irq with the main struct Rosen Penev
2026-03-11  8:46 ` Bartosz Golaszewski

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.