Re: [PATCH v7 8/8] gpiolib: remove the shared GPIO proxies before freeing the remaining IRQs

From: Kent Gibson

Date: Sat Nov 21 2026 - 00:08:55 EST


On Fri, Nov 20, 2026 at 10:14:00AM +0200, Adrian Ambrozewicz wrote:
> gpio_shared_proxy_to_irq() returns the parent chip's IRQ, so an edge
> request on a proxy line holds an IRQ of the parent.
>
> When the parent is removed, gpiochip_remove() frees the IRQs still
> requested on its lines before it removes the proxies in
> gpio_device_teardown_shared(). The release of a proxy line request is
> serialized only with the proxy's own removal notifier, so if
> gpiod_free_irqs() frees the IRQ between the release's irq_has_action()
> check and its free_irq(), free_irq() warns:
>
> Trying to free already-free IRQ 22
>
> Remove the proxies first, so the character device on each proxy frees
> its IRQs before the rest are forcibly freed.
>
> Reproduced on arm64 QEMU with a shared gpio-sim line and a test delay
> before the release's free_irq(): 3 of 3 runs warned; with this change,
> none.
>
> Fixes: 1e4f6db614a3 ("gpiolib: support shared GPIOs in core subsystem code")
> Cc: stable@xxxxxxxxxxxxxxx
> Reported-by: Sashiko <sashiko-bot@xxxxxxxxxx>
> Closes: https://sashiko.dev/#/patchset/20261103-gpiolib-chip-removal-v5-0-aambrozewicz@xxxxxxxxxx?part=7
> Signed-off-by: Adrian Ambrozewicz <aambrozewicz@xxxxxxxxxx>
> ---
> drivers/gpio/gpiolib.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index e0ba17a73c4b..57024a1b042b 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -1461,12 +1461,12 @@ void gpiochip_remove(struct gpio_chip *gc)
>
> /*
> * No new interrupts can be requested through the character device now.
> - * Have it free the ones it holds before forcibly freeing the rest, and
> - * both before the irqchip and its mappings go away.
> + * Have it free the ones it holds, also on the shared proxies, before
> + * forcibly freeing the rest and removing the irqchip.
> */
> blocking_notifier_call_chain(&gdev->device_notifier, 0, NULL);
> - gpiochip_free_remaining_irqs(gc);
> gpio_device_teardown_shared(gdev);
> + gpiochip_free_remaining_irqs(gc);
> gpiochip_irqchip_remove(gc);
> acpi_gpiochip_remove(gc);
> of_gpiochip_remove(gc);
> --
> 2.43.0
>

Everything it touches was added in patch 7, so it needs a dependency note as
per my other patch comments.

Cheers,
Kent.