Re: [PATCH v13 08/13] gpio: regmap: remove gpiochip before tearing down irqchip

From: Michael Walle

Date: Mon Nov 02 2026 - 03:38:48 EST


On Mon Nov 2, 2026 at 7:46 AM CET, Long Zhao via B4 Relay wrote:
> From: Long Zhao <longzhao@xxxxxxxxxxxxx>
>
> gpio_regmap_unregister() currently calls regmap_del_irq_chip() before
> gpiochip_remove(). That disposes the mapped virtual IRQs and frees the
> irq_domain while ACPI GPIO-signaled events may still be requested and
> while gpiod_free_irqs() still needs gc->irq.domain.

Maybe Andy have an opinion here. But that deviated from the usual
cleanup in the reverse order and at least deserves a comment in the
code.

> Remove the gpio_chip first so ACPI teardown and USED_AS_IRQ cleanup run
> against a live domain, then delete the regmap irqchip. Use the same
> order on the registration error path, which previously leaked the
> irqchip when gpiochip_irqchip_add_domain() failed after
> regmap_add_irq_chip_fwnode().

This should be split into a seperate patch with a Fixes: tag.

-michael

>
> Cc: Michael Walle <mwalle@xxxxxxxxxx>
> Signed-off-by: Long Zhao <longzhao@xxxxxxxxxxxxx>
> ---
> drivers/gpio/gpio-regmap.c | 8 +++++++-
> 1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c
> index 0a44deae3d01..6b520bd80834 100644
> --- a/drivers/gpio/gpio-regmap.c
> +++ b/drivers/gpio/gpio-regmap.c
> @@ -429,6 +429,11 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config
>
> err_remove_gpiochip:
> gpiochip_remove(chip);
> +
> +#ifdef CONFIG_REGMAP_IRQ
> + if (gpio->irq_chip_data)
> + regmap_del_irq_chip(gpio->regmap_irq_line, gpio->irq_chip_data);
> +#endif
> err_free_bitmap_output:
> bitmap_free(gpio->fixed_direction_output);
> err_free_bitmap_dirmask:
> @@ -445,12 +450,13 @@ EXPORT_SYMBOL_GPL(gpio_regmap_register);
> */
> void gpio_regmap_unregister(struct gpio_regmap *gpio)
> {
> + gpiochip_remove(&gpio->gpio_chip);
> +
> #ifdef CONFIG_REGMAP_IRQ
> if (gpio->irq_chip_data)
> regmap_del_irq_chip(gpio->regmap_irq_line, gpio->irq_chip_data);
> #endif
>
> - gpiochip_remove(&gpio->gpio_chip);
> bitmap_free(gpio->fixed_direction_output);
> bitmap_free(gpio->fixed_direction_mask);
> kfree(gpio);

Attachment: signature.asc
Description: PGP signature