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

From: Xiaolei Wang

Date: Mon Nov 30 2026 - 05:45:03 EST


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>
---
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);
+
+ 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