Skip to contentSkip to conversation

irq/generic-chip: Fix memory leak of domain->name

PATCH In review Jeffy Chen 2 participants 4 messages Sep 27, 2017 – Sep 28, 2017 IRQ

lore
Share & tools
lore

Jeffy Chen

author
#0 lore raw

PATCH 1/1 irq/generic-chip: Fix memory leak of domain->name

Free domain->name when IRQ_DOMAIN_NAME_ALLOCATED been set.

Fixes d59f6617eef0 ("genirq: Allow fwnode to carry name information only")

---

 kernel/irq/generic-chip.c | 4 ++++
 1 file changed, 4 insertions(+)
kernel/irq/generic-chip.c +4 -0
index f7086b78ad6e..174dae8ee7fe 100644
@@ -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
#1 lore raw
Quoted 1 line · Jeffy Chen

Free domain->name when IRQ_DOMAIN_NAME_ALLOCATED been 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

author
#2 lore raw

Hi Thomas,

Thanks for your review.

Quoted 10 lines · Thomas Gleixner
Quoted 1 line · Jeffy Chen

Free domain->name when IRQ_DOMAIN_NAME_ALLOCATED been 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 .....

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

author
#3 lore raw

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?