From: Xiaolei Wang <wangxiaolei01@kaihong.com>
To: tglx@kernel.org, radu@rendec.net, briannorris@chromium.org,
linux@roeck-us.net, davidgow@google.com,
wangxiaolei01@kaihong.com
Cc: linux-kernel@vger.kernel.org, geert@linux-m68k.org,
kunit-dev@googlegroups.com
Subject: [PATCH] genirq/test: Release fake irq descriptors after KUnit tests
Date: Mon, 30 Nov 2026 10:44:26 +0000 [thread overview]
Message-ID: <20261130104426.1384855-1-wangxiaolei01@kaihong.com> (raw)
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@kaihong.com>
---
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
next reply other threads:[~2026-11-30 10:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 10:44 Xiaolei Wang [this message]
2026-11-30 19:11 ` Brian Norris
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261130104426.1384855-1-wangxiaolei01@kaihong.com \
--to=wangxiaolei01@kaihong.com \
--cc=briannorris@chromium.org \
--cc=davidgow@google.com \
--cc=geert@linux-m68k.org \
--cc=kunit-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=radu@rendec.net \
--cc=tglx@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®