[PATCH] gpio: aspeed: Fix potential coprocessor bank map leak
From: Guangshuo Li
Date: Wed Nov 18 2026 - 09:21:33 EST
The coprocessor bank map is allocated lazily but is never freed when
the GPIO controller is removed. Its only owner is the device-managed
GPIO private data.
Register a cleanup action before adding the GPIO chip, so removal frees
the map after removing the chip and before freeing its owner.
This issue was found by our static analysis tool under development.
Fixes: a7ca13826e47 ("gpio: aspeed: Add interfaces for co-processor to grab GPIOs")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Guangshuo Li <liguangshuo@xxxxxxxxxxxxxxx>
---
drivers/gpio/gpio-aspeed.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/drivers/gpio/gpio-aspeed.c b/drivers/gpio/gpio-aspeed.c
index dc53b2decb66..bb30bbf8c60b 100644
--- a/drivers/gpio/gpio-aspeed.c
+++ b/drivers/gpio/gpio-aspeed.c
@@ -1300,6 +1300,13 @@ static const struct of_device_id aspeed_gpio_of_table[] = {
};
MODULE_DEVICE_TABLE(of, aspeed_gpio_of_table);
+static void aspeed_gpio_free_copro_bankmap(void *data)
+{
+ struct aspeed_gpio *gpio = data;
+
+ kfree(gpio->cf_copro_bankmap);
+}
+
static int aspeed_gpio_probe(struct platform_device *pdev)
{
struct gpio_irq_chip *girq;
@@ -1364,6 +1371,10 @@ static int aspeed_gpio_probe(struct platform_device *pdev)
gpio->config->llops->reg_bank_get(gpio, (i << 5), reg_rdata);
}
+ rc = devm_add_action_or_reset(&pdev->dev, aspeed_gpio_free_copro_bankmap, gpio);
+ if (rc)
+ return rc;
+
if (gpio->config->llops->privilege_init)
gpio->config->llops->privilege_init(gpio);
base-commit: 6628e7d4c6b25c8d18f1345e3a20d21829aae7e4