Re: [PATCH] genirq/test: Release fake irq descriptors after KUnit tests

From: Brian Norris

Date: Mon Nov 30 2026 - 14:11:33 EST


On Mon, Nov 30, 2026 at 10:44:26AM +0000, Xiaolei Wang wrote:
> Each of the four irq_test_cases cases allocates a virtual interrupt via
> irq_domain_alloc_descs() in irq_test_setup_fake_irq(), but only calls
> free_irq() at the end. free_irq() releases the irqaction, not the
> descriptor, so every run of the suite leaves 4 fake irq descriptors behind.
> Each leaked descriptor keeps its debugfs node alive at
> /sys/kernel/debug/irq/irqs/<N> ("chip: fake"), and the nodes accumulate
> across repeated runs.
>
> kmemleak does not report this because irq descriptors have a kobject/rcu
> lifetime, but the descriptors are never returned to the irq_desc radix
> tree and the debugfs entries are never removed.
>
> Register a cleanup callback with kunit_add_action_or_reset() immediately
> after the descriptor is allocated. On test exit, including an early abort
> on a failed assertion, it frees any still-registered action and then
> calls irq_free_descs() to release the descriptor. The _or_reset() variant
> also cleans up when registering the action itself fails.
>
> Fixes: 66067c3c8a1e ("genirq: Add kunit tests for depth counts")
> Signed-off-by: Xiaolei Wang <wangxiaolei01@xxxxxxxxxxx>

Thanks for the fix. Looks fine to me:

Reviewed-by: Brian Norris <briannorris@xxxxxxxxxxxx>

> ---
> kernel/irq/irq_test.c | 17 ++++++++++++++++-
> 1 file changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/kernel/irq/irq_test.c b/kernel/irq/irq_test.c
> index e2d31914b3c4..283fe32bf39a 100644
> --- a/kernel/irq/irq_test.c
> +++ b/kernel/irq/irq_test.c
> @@ -41,14 +41,29 @@ static struct irq_chip fake_irq_chip = {
> .flags = IRQCHIP_SKIP_SET_WAKE,
> };
>
> +static void irq_test_free_fake_irq(void *data)
> +{
> + unsigned int virq = (unsigned long)data;
> + struct irq_desc *desc = irq_to_desc(virq);
> +
> + if (desc->action)
> + free_irq(virq, NULL);

I wondered whether we should remove free_irq() from the tail of each
test, but I suppose it's not really logically the right responsibility
-- irq_test_setup_fake_irq() isn't really about assigning IRQ actions,
so its cleanup here is just done for safety, not because it's really the
best place to do it.

Regards,
Brian

> +
> + irq_free_descs(virq, 1);
> +}
> +
> static int irq_test_setup_fake_irq(struct kunit *test, struct irq_affinity_desc *affd)
> {
> struct irq_desc *desc;
> - int virq;
> + int virq, ret;
>
> virq = irq_domain_alloc_descs(-1, 1, 0, NUMA_NO_NODE, affd);
> KUNIT_ASSERT_GE(test, virq, 0);
>
> + ret = kunit_add_action_or_reset(test, irq_test_free_fake_irq,
> + (void *)(unsigned long)virq);
> + KUNIT_ASSERT_EQ(test, ret, 0);
> +
> irq_set_chip_and_handler(virq, &fake_irq_chip, handle_simple_irq);
>
> desc = irq_to_desc(virq);
> --
> 2.34.1
>