mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] genirq/generic-chip: Set IRQ_DOMAIN_FLAG_DESTROY_GC in irq_domain_alloc_generic_chips()
@ 2026-09-02  6:59 Qingshuang Fu
  2026-09-03 22:37 ` Herve Codina
  2026-09-04  7:09 ` [PATCH v2] irqdomain: Auto-set IRQ_DOMAIN_FLAG_DESTROY_GC in __irq_domain_instantiate() Qingshuang Fu
  0 siblings, 2 replies; 7+ messages in thread
From: Qingshuang Fu @ 2026-09-02  6:59 UTC (permalink / raw)
  To: Thomas Gleixner, Radu Rendec, Andy Whitcroft, Joe Perches, Herve Codina
  Cc: linux-kernel, Qingshuang Fu

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@kylinos.cn>
---
 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


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2026-09-04 15:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-09-02  6:59 [PATCH] genirq/generic-chip: Set IRQ_DOMAIN_FLAG_DESTROY_GC in irq_domain_alloc_generic_chips() Qingshuang Fu
2026-09-03 22:37 ` Herve Codina
2026-09-04  6:26   ` Thomas Gleixner
2026-09-04  7:25     ` Qingshuang Fu
2026-09-04  7:09 ` [PATCH v2] irqdomain: Auto-set IRQ_DOMAIN_FLAG_DESTROY_GC in __irq_domain_instantiate() Qingshuang Fu
2026-09-04 11:09   ` Herve Codina
2026-09-04 15:19   ` Thomas Gleixner

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®