Re: [PATCH] gpio: aspeed: Fix potential coprocessor bank map leak
From: Bartosz Golaszewski
Date: Thu Nov 19 2026 - 08:30:39 EST
On Wed, Nov 18, 2026 at 10:21:19PM +0800, Guangshuo Li wrote:
> 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;
> +
You have the address of the device that binds to the driver in struct
aspeed_gpio, why don't you just use devm_kzalloc_obj()?
Bart