public inbox for linux-gpio@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpio: mockup: allocate lines with main struct
@ 2026-03-19  0:05 Rosen Penev
  2026-03-20 13:28 ` Linus Walleij
  2026-03-20 18:10 ` Kees Cook
  0 siblings, 2 replies; 12+ messages in thread
From: Rosen Penev @ 2026-03-19  0:05 UTC (permalink / raw)
  To: linux-gpio
  Cc: Bamvor Jian Zhang, Linus Walleij, Bartosz Golaszewski, Kees Cook,
	Gustavo A. R. Silva, open list,
	open list:KERNEL HARDENING (not covered by other areas):Keyword:b__counted_by(_le|_be)?b

Remove no longer needed kcalloc to simplify allocation.

Added __counted_by along with a counting variable to get extra runtime
analysis.

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

diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c
index a7d69f3835c1..a907ce28cbbb 100644
--- a/drivers/gpio/gpio-mockup.c
+++ b/drivers/gpio/gpio-mockup.c
@@ -52,10 +52,11 @@ struct gpio_mockup_line_status {
 
 struct gpio_mockup_chip {
 	struct gpio_chip gc;
-	struct gpio_mockup_line_status *lines;
 	struct irq_domain *irq_sim_domain;
 	struct dentry *dbg_dir;
 	struct mutex lock;
+	int nr_lines;
+	struct gpio_mockup_line_status lines[] __counted_by(nr_lines);
 };
 
 struct gpio_mockup_dbgfs_private {
@@ -436,15 +437,18 @@ static int gpio_mockup_probe(struct platform_device *pdev)
 	if (rv)
 		name = dev_name(dev);
 
-	chip = devm_kzalloc(dev, sizeof(*chip), GFP_KERNEL);
+	chip = devm_kzalloc(dev, struct_size(chip, lines, ngpio), GFP_KERNEL);
 	if (!chip)
 		return -ENOMEM;
 
-	mutex_init(&chip->lock);
+	chip->nr_lines = ngpio;
 
 	gc = &chip->gc;
-	gc->base = base;
 	gc->ngpio = ngpio;
+	gc->base = base;
+
+	mutex_init(&chip->lock);
+
 	gc->label = name;
 	gc->owner = THIS_MODULE;
 	gc->parent = dev;
@@ -460,11 +464,6 @@ static int gpio_mockup_probe(struct platform_device *pdev)
 	gc->request = gpio_mockup_request;
 	gc->free = gpio_mockup_free;
 
-	chip->lines = devm_kcalloc(dev, gc->ngpio,
-				   sizeof(*chip->lines), GFP_KERNEL);
-	if (!chip->lines)
-		return -ENOMEM;
-
 	for (i = 0; i < gc->ngpio; i++)
 		chip->lines[i].dir = GPIO_LINE_DIRECTION_IN;
 
-- 
2.53.0


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

end of thread, other threads:[~2026-03-24 18:25 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-19  0:05 [PATCH] gpio: mockup: allocate lines with main struct Rosen Penev
2026-03-20 13:28 ` Linus Walleij
2026-03-20 18:10 ` Kees Cook
2026-03-20 23:00   ` Rosen Penev
2026-03-23 10:00     ` Bartosz Golaszewski
2026-03-23 16:43       ` Rosen Penev
2026-03-24  9:16         ` Bartosz Golaszewski
2026-03-24 15:51           ` Rosen Penev
2026-03-24 15:54             ` Bartosz Golaszewski
2026-03-24 15:56               ` Rosen Penev
2026-03-24 17:16                 ` Bartosz Golaszewski
2026-03-24 18:25                   ` Rosen Penev

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