Skip to contentSkip to conversation

x86: Plug memory leak in sparse irq

PATCH In review Thomas Gleixner 2 participants 3 messages Sep 28, 2010 1 message not in the archive x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: Plug memory leak in sparse irq

free_irq_cfg() is not freeing the cpumask_vars in irq_cfg.

---
 arch/x86/kernel/apic/io_apic.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
arch/x86/kernel/apic/io_apic.c +4 -2
Index: linux-2.6/arch/x86/kernel/apic/io_apic.c
===================================================================
@@ -311,9 +311,11 @@ void arch_init_copy_chip_data(struct irq
 	init_copy_irq_2_pin(old_cfg, cfg, node);
 }
 
-static void free_irq_cfg(struct irq_cfg *old_cfg)
+static void free_irq_cfg(struct irq_cfg *cfg)
 {
-	kfree(old_cfg);
+	free_cpumask_var(cfg->domain);
+	free_cpumask_var(cfg->old_domain);
+	kfree(cfg);
 }
 
 void arch_free_chip_data(struct irq_desc *old_desc, struct irq_desc *desc)

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw
Quoted 23 lines

From: Thomas Gleixner <[email protected]>
Date: Tue, Sep 28, 2010 at 11:57 AM
Subject: [PATCH] x86: Plug memory leak in sparse irq
To: LKML <[email protected]>
Cc: [email protected], Yinghai Lu <[email protected]>

free_irq_cfg() is not freeing the cpumask_vars in irq_cfg.

---
 arch/x86/kernel/apic/io_apic.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Index: linux-2.6/arch/x86/kernel/apic/io_apic.c
===================================================================

arch/x86/kernel/apic/io_apic.c +0 -0
@@ -311,9 +311,11 @@ void arch_init_copy_chip_data(struct irq
       init_copy_irq_2_pin(old_cfg, cfg, node);
 }
 

arch/x86/kernel/apic/io_apic.c void arch_init_copy_chip_data(struct irq · line 321

Quoted 10 lines
arch/x86/kernel/apic/io_apic.c +4 -2
-static void free_irq_cfg(struct irq_cfg *old_cfg)
+static void free_irq_cfg(struct irq_cfg *cfg)
 {
-       kfree(old_cfg);
+       free_cpumask_var(cfg->domain);
+       free_cpumask_var(cfg->old_domain);
+       kfree(cfg);
 }
 
 void arch_free_chip_data(struct irq_desc *old_desc, struct irq_desc *desc)

yes. still need

[PATCH] x86: copy cpumask while copying chip_data for offstack cpumask

While looking Thomas's
| x86: Plug memory leak in sparse irq

found copy_chip_data() could copy the cpumask pointers instead of real data. Need to use cpumask_copy there.

---
 arch/x86/kernel/apic/io_apic.c |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
arch/x86/kernel/apic/io_apic.c +4 -1
Index: linux-2.6/arch/x86/kernel/apic/io_apic.c
===================================================================
@@ -306,7 +306,10 @@ void arch_init_copy_chip_data(struct irq
 
 	old_cfg = old_desc->chip_data;
 
-	memcpy(cfg, old_cfg, sizeof(struct irq_cfg));
+	cfg->vector = old_cfg->vector;
+	cfg->move_in_progress = old_cfg->move_in_progress;
+	cpumask_copy(cfg->domain, old_cfg->domain);
+	cpumask_copy(cfg->old_domain, old_cfg->old_domain);
 
 	init_copy_irq_2_pin(old_cfg, cfg, node);
 }
#3 lore raw
Quoted 32 lines · Yinghai Lu
Quoted 32 lines

From: Thomas Gleixner <[email protected]>
Date: Tue, Sep 28, 2010 at 11:57 AM
Subject: [PATCH] x86: Plug memory leak in sparse irq
To: LKML <[email protected]>
Cc: [email protected], Yinghai Lu <[email protected]>

free_irq_cfg() is not freeing the cpumask_vars in irq_cfg.

---
 arch/x86/kernel/apic/io_apic.c |    6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

Index: linux-2.6/arch/x86/kernel/apic/io_apic.c
===================================================================

arch/x86/kernel/apic/io_apic.c +4 -2
@@ -311,9 +311,11 @@ void arch_init_copy_chip_data(struct irq
       init_copy_irq_2_pin(old_cfg, cfg, node);
 }
 
-static void free_irq_cfg(struct irq_cfg *old_cfg)
+static void free_irq_cfg(struct irq_cfg *cfg)
 {
-       kfree(old_cfg);
+       free_cpumask_var(cfg->domain);
+       free_cpumask_var(cfg->old_domain);
+       kfree(cfg);
 }
 
Quoted 3 lines

arch/x86/kernel/apic/io_apic.c void arch_init_copy_chip_data(struct irq · line 321

Quoted 1 line
arch/x86/kernel/apic/io_apic.c +0 -0
 void arch_free_chip_data(struct irq_desc *old_desc, struct irq_desc *desc)

yes. still need

Was about to send that out next.

Quoted 7 lines

[PATCH] x86: copy cpumask while copying chip_data for offstack cpumask

While looking Thomas's
| x86: Plug memory leak in sparse irq

found copy_chip_data() could copy the cpumask pointers instead of real data. Need to use cpumask_copy there.

Sigh. That code should just depend on CONFIG_BROKEN, really.

Thanks,

tglx