aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCyrill Gorcunov <gorcunov@gmail.com>2008-09-18 15:37:57 -0400
committerIngo Molnar <mingo@elte.hu>2008-10-16 10:53:11 -0400
commit5ffa4eb2224343ec3fbd492ffe71e28e797435b7 (patch)
tree728cd604177a5d4f392ef3f5290af37f06c8b033
parent2976fe20125587c944c8df48d991c38f0891fb28 (diff)
x86: io-apic - interrupt remapping fix
Interrupt remapping could lead to NULL dereference in case of kzalloc failed and memory leak in other way. So fix the both cases. Signed-off-by: Cyrill Gorcunov <gorcunov@gmail.com> Cc: "Maciej W. Rozycki" <macro@linux-mips.org> Cc: Suresh Siddha <suresh.b.siddha@intel.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
-rw-r--r--arch/x86/kernel/apic.c13
-rw-r--r--arch/x86/kernel/io_apic.c19
2 files changed, 27 insertions, 5 deletions
diff --git a/arch/x86/kernel/apic.c b/arch/x86/kernel/apic.c
index 784116933c70..1f48bd1c9f2d 100644
--- a/arch/x86/kernel/apic.c
+++ b/arch/x86/kernel/apic.c
@@ -1360,7 +1360,12 @@ void enable_IR_x2apic(void)
1360 1360
1361 local_irq_save(flags); 1361 local_irq_save(flags);
1362 mask_8259A(); 1362 mask_8259A();
1363 save_mask_IO_APIC_setup(); 1363
1364 ret = save_mask_IO_APIC_setup();
1365 if (ret) {
1366 printk(KERN_INFO "Saving IO-APIC state failed: %d\n", ret);
1367 goto end;
1368 }
1364 1369
1365 ret = enable_intr_remapping(1); 1370 ret = enable_intr_remapping(1);
1366 1371
@@ -1370,14 +1375,15 @@ void enable_IR_x2apic(void)
1370 } 1375 }
1371 1376
1372 if (ret) 1377 if (ret)
1373 goto end; 1378 goto end_restore;
1374 1379
1375 if (!x2apic) { 1380 if (!x2apic) {
1376 x2apic = 1; 1381 x2apic = 1;
1377 apic_ops = &x2apic_ops; 1382 apic_ops = &x2apic_ops;
1378 enable_x2apic(); 1383 enable_x2apic();
1379 } 1384 }
1380end: 1385
1386end_restore:
1381 if (ret) 1387 if (ret)
1382 /* 1388 /*
1383 * IR enabling failed 1389 * IR enabling failed
@@ -1386,6 +1392,7 @@ end:
1386 else 1392 else
1387 reinit_intr_remapped_IO_APIC(x2apic_preenabled); 1393 reinit_intr_remapped_IO_APIC(x2apic_preenabled);
1388 1394
1395end:
1389 unmask_8259A(); 1396 unmask_8259A();
1390 local_irq_restore(flags); 1397 local_irq_restore(flags);
1391 1398
diff --git a/arch/x86/kernel/io_apic.c b/arch/x86/kernel/io_apic.c
index 01419fdc1d5d..4cc9cb64c811 100644
--- a/arch/x86/kernel/io_apic.c
+++ b/arch/x86/kernel/io_apic.c
@@ -812,7 +812,7 @@ int save_mask_IO_APIC_setup(void)
812 kzalloc(sizeof(struct IO_APIC_route_entry) * 812 kzalloc(sizeof(struct IO_APIC_route_entry) *
813 nr_ioapic_registers[apic], GFP_KERNEL); 813 nr_ioapic_registers[apic], GFP_KERNEL);
814 if (!early_ioapic_entries[apic]) 814 if (!early_ioapic_entries[apic])
815 return -ENOMEM; 815 goto nomem;
816 } 816 }
817 817
818 for (apic = 0; apic < nr_ioapics; apic++) 818 for (apic = 0; apic < nr_ioapics; apic++)
@@ -826,17 +826,32 @@ int save_mask_IO_APIC_setup(void)
826 ioapic_write_entry(apic, pin, entry); 826 ioapic_write_entry(apic, pin, entry);
827 } 827 }
828 } 828 }
829
829 return 0; 830 return 0;
831
832nomem:
833 for (; apic > 0; apic--)
834 kfree(early_ioapic_entries[apic]);
835 kfree(early_ioapic_entries[apic]);
836 memset(early_ioapic_entries, 0,
837 ARRAY_SIZE(early_ioapic_entries));
838
839 return -ENOMEM;
830} 840}
831 841
832void restore_IO_APIC_setup(void) 842void restore_IO_APIC_setup(void)
833{ 843{
834 int apic, pin; 844 int apic, pin;
835 845
836 for (apic = 0; apic < nr_ioapics; apic++) 846 for (apic = 0; apic < nr_ioapics; apic++) {
847 if (!early_ioapic_entries[apic])
848 break;
837 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++) 849 for (pin = 0; pin < nr_ioapic_registers[apic]; pin++)
838 ioapic_write_entry(apic, pin, 850 ioapic_write_entry(apic, pin,
839 early_ioapic_entries[apic][pin]); 851 early_ioapic_entries[apic][pin]);
852 kfree(early_ioapic_entries[apic]);
853 early_ioapic_entries[apic] = NULL;
854 }
840} 855}
841 856
842void reinit_intr_remapped_IO_APIC(int intr_remapping) 857void reinit_intr_remapped_IO_APIC(int intr_remapping)