Re: [PATCH v8 7/8] gpiolib: let the character device free its IRQs first on chip removal

From: Kent Gibson

Date: Tue Nov 24 2026 - 09:06:18 EST


On Tue, Nov 24, 2026 at 11:20:38AM +0200, Adrian Ambrozewicz wrote:
> gpiochip_remove() force-frees the remaining IRQs, removes the irqchip,
> and only then calls the notifier on which the character device frees
> its IRQs. It may then free an IRQ it no longer owns, after its mapping
> was disposed of and the number reused, or from a release racing
> gpiod_free_irqs() and gpiochip_irqchip_remove(). free_irq() then warns
> "Trying to free already-free IRQ" or uses a disposed descriptor.
>
> Herve Codina first proposed calling the notifier earlier [1]. Call it
> after the chip pointer is cleared and SRCU synchronized, when no ioctl
> can request IRQs, then free the rest. The release paths now free their
> IRQs before unregistering, under the lock the callback takes
> (config_mutex, or a new mutex for v1 line events). Initialise
> config_mutex on allocation: linereq_free() takes it, also on
> linereq_create()'s error returns.
>
> IRQs left requested by in-kernel users are now freed after the chip
> pointer is cleared, when gpiod_*() calls fail.
>
> Reproduced with a test chip on the hierarchical irqchip: both races
> warned in 30 of 30 cycles; with this change, none.
>
> This patch depends on patches 3 and 5 of this series.
>

Reviewed-by: Kent Gibson <warthog618@xxxxxxxxx>

Cheers,
Kent.