irq/generic-chip: Fix memory leak of domain->name
PATCH 1/1 irq/generic-chip: Fix memory leak of domain->name
Free domain->name when IRQ_DOMAIN_NAME_ALLOCATED been set.
---
kernel/irq/generic-chip.c | 4 ++++ 1 file changed, 4 insertions(+)
kernel/irq/generic-chip.c +4 -0
@@ -322,6 +322,10 @@ int __irq_alloc_domain_generic_chips(struct irq_domain *d, int irqs_per_chip,/* Calc pointer to the next generic chip */ tmp +=sizeof (*gc) + num_ct *sizeof (struct irq_chip_type ); } +if (d->flags &IRQ_DOMAIN_NAME_ALLOCATED ) { +kfree (d->name); + d->flags &= ~IRQ_DOMAIN_NAME_ALLOCATED ; + } d->name = name;return 0 ; }
Signature · 1 line
2.11.0
Quoted 1 line · Jeffy Chen
Free
domain->namewhenIRQ_DOMAIN_NAME_ALLOCATEDbeen set.
I can see that from the patch, but you fail to explain what the problem is.
It's actually more than just a memory leak. If the domain gets destroyed then the domain free code would try to free d->name which might be a string constant .....
kernel/irq/generic-chip.c int __irq_alloc_domain_generic_chips(struct irq_domain *d, int irqs_per_chip, · line 329
Quoted 5 lines
kernel/irq/generic-chip.c +4
-0+if (d->flags &IRQ_DOMAIN_NAME_ALLOCATED ) { +kfree (d->name); + d->flags &= ~IRQ_DOMAIN_NAME_ALLOCATED ; + } d->name = name;
I don't think that this is the proper thing to do. There is no reason why the domain should have the same name as the irq chip. So we rather should do:
if (!d->name) d->name = name;
Along with a proper comment.
Thanks,
tglx
Hi Thomas,
Thanks for your review.
Quoted 10 lines · Thomas Gleixner
Quoted 1 line · Jeffy Chen
Free
domain->namewhenIRQ_DOMAIN_NAME_ALLOCATEDbeen set.I can see that from the patch, but you fail to explain what the problem is.
It's actually more than just a memory leak. If the domain gets destroyed then the domain free code would try to free
d->namewhich might be a string constant .....
ok, i'll add that to commit msg.
Quoted 11 lines
kernel/irq/generic-chip.c int __irq_alloc_domain_generic_chips(struct irq_domain *d, int irqs_per_chip, · line 329
Quoted 6 lines
kernel/irq/generic-chip.c +4
-0+if (d->flags &IRQ_DOMAIN_NAME_ALLOCATED ) { +kfree (d->name); + d->flags &= ~IRQ_DOMAIN_NAME_ALLOCATED ; + } d->name = name;I don't think that this is the proper thing to do. There is no reason why the domain should have the same name as the irq chip. So we rather should do:
Quoted 4 lines
if (!d->name) d->name = name;Along with a proper comment.
that is better, will do it in next version :)
Quoted 8 lines
Thanks,
tglx
Hi Thomas,
Quoted 10 lines · jeffy
Quoted 9 lines
I don't think that this is the proper thing to do. There is no reason why the domain should have the same name as the irq chip. So we rather should do:
if (!d->name) d->name = name;Along with a proper comment.
that is better, will do it in next version :)
it looks like the __irq_domain_add() would guarantee every domain has a valid name, maybe we can just remove this?