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>,
Thierry Reding <thierry.reding@kernel.org>,
Jonathan Hunter <jonathanh@nvidia.com>,
Kees Cook <kees@kernel.org>,
linux-tegra@vger.kernel.org (open list:TEGRA ARCHITECTURE
SUPPORT), linux-kernel@vger.kernel.org (open list)
Subject: [PATCH] gpio: tegra186: allocate irqs with the main struct
Date: Mon, 9 Mar 2026 16:28:04 -0700 [thread overview]
Message-ID: <20260309232804.331882-1-rosenp@gmail.com> (raw)
Remove an extra kcalloc call by using a flexible array member.
Add __counted_by for extra runtime analysis.
Assign counting variable immediately after allocation as required by
__counted_by.
Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
drivers/gpio/gpio-tegra186.c | 22 +++++++++-------------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/drivers/gpio/gpio-tegra186.c b/drivers/gpio/gpio-tegra186.c
index fb26402b6c47..aa7c3e44234f 100644
--- a/drivers/gpio/gpio-tegra186.c
+++ b/drivers/gpio/gpio-tegra186.c
@@ -125,7 +125,6 @@ struct tegra_gpio_soc {
struct tegra_gpio {
struct gpio_chip gpio;
unsigned int num_irq;
- unsigned int *irq;
const struct tegra_gpio_soc *soc;
unsigned int num_irqs_per_bank;
@@ -133,6 +132,8 @@ struct tegra_gpio {
void __iomem *secure;
void __iomem *base;
+
+ unsigned int irq[] __counted_by(num_irq);
};
static const struct tegra_gpio_port *
@@ -859,10 +860,16 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
char **names;
int node, err;
- gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
+ err = platform_irq_count(pdev);
+ if (err < 0)
+ return err;
+
+ gpio = devm_kzalloc(&pdev->dev, struct_size(gpio, irq, err), GFP_KERNEL);
if (!gpio)
return -ENOMEM;
+ gpio->num_irq = err;
+
gpio->soc = device_get_match_data(&pdev->dev);
gpio->gpio.label = gpio->soc->name;
gpio->gpio.parent = &pdev->dev;
@@ -889,21 +896,10 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
if (IS_ERR(gpio->base))
return PTR_ERR(gpio->base);
- err = platform_irq_count(pdev);
- if (err < 0)
- return err;
-
- gpio->num_irq = err;
-
err = tegra186_gpio_irqs_per_bank(gpio);
if (err < 0)
return err;
- gpio->irq = devm_kcalloc(&pdev->dev, gpio->num_irq, sizeof(*gpio->irq),
- GFP_KERNEL);
- if (!gpio->irq)
- return -ENOMEM;
-
for (i = 0; i < gpio->num_irq; i++) {
err = platform_get_irq(pdev, i);
if (err < 0)
--
2.53.0
next reply other threads:[~2026-03-09 23:28 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-09 23:28 Rosen Penev [this message]
2026-03-11 8:46 ` [PATCH] gpio: tegra186: allocate irqs 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=20260309232804.331882-1-rosenp@gmail.com \
--to=rosenp@gmail.com \
--cc=brgl@kernel.org \
--cc=gustavoars@kernel.org \
--cc=jonathanh@nvidia.com \
--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 \
--cc=linux-tegra@vger.kernel.org \
--cc=thierry.reding@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.