All of lore.kernel.org
 help / color / mirror / Atom feed
From: Rosen Penev <rosenp@gmail.com>
To: linux-gpio@vger.kernel.org
Cc: Bamvor Jian Zhang <bamv2005@gmail.com>,
	Linus Walleij <linusw@kernel.org>,
	Bartosz Golaszewski <brgl@kernel.org>,
	Kees Cook <kees@kernel.org>,
	"Gustavo A. R. Silva" <gustavoars@kernel.org>,
	linux-kernel@vger.kernel.org (open list),
	linux-hardening@vger.kernel.org (open list:KERNEL HARDENING (not
	covered by other areas):Keyword:\b__counted_by(_le|_be)?\b)
Subject: [PATCH] gpio: mockup: allocate lines with main struct
Date: Wed, 18 Mar 2026 17:05:58 -0700	[thread overview]
Message-ID: <20260319000558.22108-1-rosenp@gmail.com> (raw)

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


             reply	other threads:[~2026-03-19  0:06 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-19  0:05 Rosen Penev [this message]
2026-03-20 13:28 ` [PATCH] gpio: mockup: allocate lines with main struct 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260319000558.22108-1-rosenp@gmail.com \
    --to=rosenp@gmail.com \
    --cc=bamv2005@gmail.com \
    --cc=brgl@kernel.org \
    --cc=gustavoars@kernel.org \
    --cc=kees@kernel.org \
    --cc=linusw@kernel.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-hardening@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.