From: Rosen Penev <rosenp@gmail.com>
To: linux-gpio@vger.kernel.org
Cc: Linus Walleij <linusw@kernel.org>,
linux-hardening@vger.kernel.org, gustavoars@kernel.org,
Bartosz Golaszewski <brgl@kernel.org>,
Kees Cook <kees@kernel.org>,
linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] gpio: htc-egpio: allocate irq with the main struct
Date: Mon, 9 Mar 2026 15:52:04 -0700 [thread overview]
Message-ID: <20260309225204.44789-1-rosenp@gmail.com> (raw)
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
next reply other threads:[~2026-03-09 22:52 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-09 22:52 Rosen Penev [this message]
2026-03-11 8:46 ` [PATCH] gpio: htc-egpio: allocate irq with the main struct Bartosz Golaszewski
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=20260309225204.44789-1-rosenp@gmail.com \
--to=rosenp@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox