mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Gow <david@davidgow.net>
To: Xiaolei Wang <wangxiaolei01@kaihong.com>,
	tglx@kernel.org, radu@rendec.net, briannorris@chromium.org,
	linux@roeck-us.net, davidgow@google.com
Cc: linux-kernel@vger.kernel.org, geert@linux-m68k.org,
	kunit-dev@googlegroups.com
Subject: Re: [PATCH] genirq/test: Release fake irq descriptors after KUnit tests
Date: Tue, 1 Dec 2026 21:04:40 +0800	[thread overview]
Message-ID: <b7c89511-efbf-4ac7-8de8-7ef9af6bb4f4@davidgow.net> (raw)
In-Reply-To: <20261130104426.1384855-1-wangxiaolei01@kaihong.com>

Le 30/11/2026 à 18:44, Xiaolei Wang a écrit :
> 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>
> ---

Tested-by: David Gow <david@davidgow.net>

Cheers,
-- David

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


      parent reply	other threads:[~2026-12-01 13:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 10:44 Xiaolei Wang
2026-11-30 19:11 ` Brian Norris
2026-12-01 13:04 ` David Gow [this message]

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=b7c89511-efbf-4ac7-8de8-7ef9af6bb4f4@davidgow.net \
    --to=david@davidgow.net \
    --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 \
    --cc=wangxiaolei01@kaihong.com \
    /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®