History

[PATCH] check return value of cpu_callback

Spawing ksoftirqd, migration, or watchdog, and calling init_timers_cpu() may fail with small memory. If it happens in initcalls, kernel NULL pointer dereference happens later. This patch makes crash happen immediately in such cases. It seems a bit better than getting kernel NULL pointer dereference later.

Akinobu Mita committed 20 years ago

Commit 07dccf31 parent 6c2d8b54 files · +11 −4Browse files

Unified · Split

4 files
  1. kernel/sched.c +3 −1
  2. kernel/softirq.c +3 −1
  3. kernel/softlockup.c +2 −1
  4. kernel/timer.c +3 −1
kernel/sched.c+3−1
@@ -5272,9 +5272,11 @@ static struct notifier_block __cpuinitdata migration_notifier = { · 5271 unmodified lines
52725272 int __init migration_init(void)
52735273 {
52745274 void *cpu = (void *)(long)smp_processor_id();
5275+ int err;
52755276
52765277 /* Start one for the boot CPU: */
5277− migration_call(&migration_notifier, CPU_UP_PREPARE, cpu);
5278+ err = migration_call(&migration_notifier, CPU_UP_PREPARE, cpu);
5279+ BUG_ON(err == NOTIFY_BAD);
52785280 migration_call(&migration_notifier, CPU_ONLINE, cpu);
52795281 register_cpu_notifier(&migration_notifier);
52805282
kernel/softirq.c+3−1
@@ -612,7 +612,9 @@ static struct notifier_block __cpuinitdata cpu_nfb = { · 611 unmodified lines
612612 __init int spawn_ksoftirqd(void)
613613 {
614614 void *cpu = (void *)(long)smp_processor_id();
615− cpu_callback(&cpu_nfb, CPU_UP_PREPARE, cpu);
615+ int err = cpu_callback(&cpu_nfb, CPU_UP_PREPARE, cpu);
616+
617+ BUG_ON(err == NOTIFY_BAD);
616618 cpu_callback(&cpu_nfb, CPU_ONLINE, cpu);
617619 register_cpu_notifier(&cpu_nfb);
618620 return 0;
kernel/softlockup.c+2−1
@@ -149,8 +149,9 @@ static struct notifier_block __cpuinitdata cpu_nfb = { · 148 unmodified lines
149149 __init void spawn_softlockup_task(void)
150150 {
151151 void *cpu = (void *)(long)smp_processor_id();
152+ int err = cpu_callback(&cpu_nfb, CPU_UP_PREPARE, cpu);
152153
153− cpu_callback(&cpu_nfb, CPU_UP_PREPARE, cpu);
154+ BUG_ON(err == NOTIFY_BAD);
154155 cpu_callback(&cpu_nfb, CPU_ONLINE, cpu);
155156 register_cpu_notifier(&cpu_nfb);
156157
kernel/timer.c+3−1
@@ -1694,8 +1694,10 @@ static struct notifier_block __cpuinitdata timers_nb = { · 1693 unmodified lines
16941694
16951695 void __init init_timers(void)
16961696 {
1697− timer_cpu_notify(&timers_nb, (unsigned long)CPU_UP_PREPARE,
1697+ int err = timer_cpu_notify(&timers_nb, (unsigned long)CPU_UP_PREPARE,
16981698 (void *)(long)smp_processor_id());
1699+
1700+ BUG_ON(err == NOTIFY_BAD);
16991701 register_cpu_notifier(&timers_nb);
17001702 open_softirq(TIMER_SOFTIRQ, run_timer_softirq, NULL);
17011703 }