Skip to content

Commit b4784ad

Browse files
nehebBartosz Golaszewski
authored andcommitted
gpio: tegra186: allocate irqs with the main struct
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> Link: https://patch.msgid.link/20260309232804.331882-1-rosenp@gmail.com Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@oss.qualcomm.com>
1 parent 223d9a3 commit b4784ad

1 file changed

Lines changed: 9 additions & 13 deletions

File tree

drivers/gpio/gpio-tegra186.c

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,15 @@ struct tegra_gpio_soc {
125125
struct tegra_gpio {
126126
struct gpio_chip gpio;
127127
unsigned int num_irq;
128-
unsigned int *irq;
129128

130129
const struct tegra_gpio_soc *soc;
131130
unsigned int num_irqs_per_bank;
132131
unsigned int num_banks;
133132

134133
void __iomem *secure;
135134
void __iomem *base;
135+
136+
unsigned int irq[] __counted_by(num_irq);
136137
};
137138

138139
static const struct tegra_gpio_port *
@@ -859,10 +860,16 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
859860
char **names;
860861
int node, err;
861862

862-
gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
863+
err = platform_irq_count(pdev);
864+
if (err < 0)
865+
return err;
866+
867+
gpio = devm_kzalloc(&pdev->dev, struct_size(gpio, irq, err), GFP_KERNEL);
863868
if (!gpio)
864869
return -ENOMEM;
865870

871+
gpio->num_irq = err;
872+
866873
gpio->soc = device_get_match_data(&pdev->dev);
867874
gpio->gpio.label = gpio->soc->name;
868875
gpio->gpio.parent = &pdev->dev;
@@ -889,21 +896,10 @@ static int tegra186_gpio_probe(struct platform_device *pdev)
889896
if (IS_ERR(gpio->base))
890897
return PTR_ERR(gpio->base);
891898

892-
err = platform_irq_count(pdev);
893-
if (err < 0)
894-
return err;
895-
896-
gpio->num_irq = err;
897-
898899
err = tegra186_gpio_irqs_per_bank(gpio);
899900
if (err < 0)
900901
return err;
901902

902-
gpio->irq = devm_kcalloc(&pdev->dev, gpio->num_irq, sizeof(*gpio->irq),
903-
GFP_KERNEL);
904-
if (!gpio->irq)
905-
return -ENOMEM;
906-
907903
for (i = 0; i < gpio->num_irq; i++) {
908904
err = platform_get_irq(pdev, i);
909905
if (err < 0)

0 commit comments

Comments
 (0)