[PATCH] genirq/generic-chip: Set IRQ_DOMAIN_FLAG_DESTROY_GC in irq_domain_alloc_generic_chips()

From: Qingshuang Fu

Date: Wed Sep 02 2026 - 03:00:00 EST


irq_domain_alloc_generic_chips() allocates generic irq chips and stores
them via d->gc. However, it does not set the IRQ_DOMAIN_FLAG_DESTROY_GC
flag on the domain. This means that when irq_domain_remove() is later
called, the generic chips are not freed because the check for
IRQ_DOMAIN_FLAG_DESTROY_GC fails, resulting in a memory leak.

Currently, every caller of irq_domain_alloc_generic_chips(), including
irq_domain_instantiate() when supplied with dgc_info, must manually set
this flag. If a caller forgets to do so, the allocated generic chips
will silently leak on domain removal.

Fix this by setting IRQ_DOMAIN_FLAG_DESTROY_GC in
irq_domain_alloc_generic_chips() right after d->gc is assigned. This
ensures that any domain using generic chips will automatically have the
chips cleaned up when the domain is removed.

The flag is set using an idempotent OR‑operation, so existing callers
which already set this flag manually remain unaffected. Even if the
allocation fails halfway and frees the gc memory in the error path,
irq_domain_remove_generic_chips() checks d->gc for NULL before
proceeding, thus no double‑free can occur. Setting the flag here is
always safe.

Fixes: e6f67ce32e8e ("irqdomain: Add support for generic irq chips creation before publishing a domain")
Signed-off-by: Qingshuang Fu <fuqingshuang@xxxxxxxxxx>
---
kernel/irq/generic-chip.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/kernel/irq/generic-chip.c b/kernel/irq/generic-chip.c
index 2c8bc6ce082e..13b634053a3e 100644
--- a/kernel/irq/generic-chip.c
+++ b/kernel/irq/generic-chip.c
@@ -308,6 +308,7 @@ int irq_domain_alloc_generic_chips(struct irq_domain *d,
dgc->gc_flags = info->gc_flags;
dgc->exit = info->exit;
d->gc = dgc;
+ d->flags |= IRQ_DOMAIN_FLAG_DESTROY_GC;

/* Calc pointer to the first generic chip */
tmp += dgc_sz;

base-commit: 89a312991dc6e638a36adc43ccb91dbc25504c04
--
2.25.1