Re: [PATCH v6 3/8] gpiolib: cdev: do not free line IRQs again after the chip is removed
From: Kent Gibson
Date: Wed Nov 18 2026 - 10:40:56 EST
On Mon, Nov 16, 2026 at 03:47:06PM +0200, Adrian Ambrozewicz wrote:
> Since commit ec8b6f55b981 ("gpio: free irqs that are still requested
> when the chip is being removed"), gpiochip_remove() frees the IRQs
> still installed on the chip's lines. A line request or v1 line event
> kept open across the removal frees its IRQ again on release. If the
> mapping is gone, that can touch freed memory, as reported with
> virtio-gpio; if the number was reused, free_irq() warns:
>
> Trying to free already-free IRQ 28
> WARNING: kernel/irq/manage.c:1881 at free_irq+0x193/0x2d0, CPU#2: gpio-hold/111
> Call Trace:
> linereq_free
> linereq_release
> __fput
>
> Stop edge detection from the device notifier that gpiochip_remove()
> calls, under config_mutex so that it does not race a reconfiguration.
> Free the IRQ there only if it still has an action, as gpiochip_remove()
> frees only those on lines flagged as used for IRQs. The release path
> then finds nothing left to free.
>
> Reproduced with gpio-sim: remove the chip under an open request with
> edge detection, set it up again and request the same line, then close
> the first request. Every cycle warns; with this change, 100 cycles pass.
>
Reviewed-by: Kent Gibson <warthog618@xxxxxxxxx>
Cheers,
Kent.