* [PATCH] gpio: tegra186: allocate irqs with the main struct
@ 2026-03-09 23:28 Rosen Penev
2026-03-11 8:46 ` Bartosz Golaszewski
0 siblings, 1 reply; 2+ messages in thread
From: Rosen Penev @ 2026-03-09 23:28 UTC (permalink / raw)
To: linux-gpio
Cc: Linus Walleij, linux-hardening, gustavoars, Bartosz Golaszewski,
Thierry Reding, Jonathan Hunter, Kees Cook,
open list:TEGRA ARCHITECTURE SUPPORT, open list
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
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH] gpio: tegra186: allocate irqs with the main struct
2026-03-09 23:28 [PATCH] gpio: tegra186: allocate irqs 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, Thierry Reding, Jonathan Hunter, Kees Cook,
linux-tegra, linux-kernel
On Mon, 09 Mar 2026 16:28:04 -0700, Rosen Penev wrote:
> 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.
>
> [...]
Applied, thanks!
[1/1] gpio: tegra186: allocate irqs with the main struct
https://git.kernel.org/brgl/c/b4784adfe3aab3e74b5f7556834d87e416b666d0
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 23:28 [PATCH] gpio: tegra186: allocate irqs with the main struct Rosen Penev
2026-03-11 8:46 ` Bartosz Golaszewski
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox