i386: do cpuid_device_create() in CPU_UP_PREPARE instead of CPU_ONLINE.
authorAkinobu Mita <akinobu.mita@gmail.com>
Fri, 19 Oct 2007 18:35:03 +0000 (20:35 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Fri, 19 Oct 2007 18:35:03 +0000 (20:35 +0200)
Do cpuid_device_create() in CPU_UP_PREPARE instead of CPU_ONLINE.

[ tglx: arch/x86 adaptation ]

Cc: "H. Peter Anvin" <hpa@zytor.com>
Signed-off-by: Akinobu Mita <akinobu.mita@gmail.com>
Signed-off-by: Andi Kleen <ak@suse.de>
Cc: Gautham R Shenoy <ego@in.ibm.com>
Cc: Oleg Nesterov <oleg@tv-sign.ru>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
arch/x86/kernel/cpuid.c

index 70dcf912d9fb3076e1116a438a3dcde699205ab9..2086c727fb090c46478c77ae498d922f48a7fe5a 100644 (file)
@@ -134,15 +134,18 @@ static const struct file_operations cpuid_fops = {
        .open = cpuid_open,
 };
 
-static int __cpuinit cpuid_device_create(int i)
+static __cpuinit int cpuid_device_create(int cpu)
 {
-       int err = 0;
        struct device *dev;
 
-       dev = device_create(cpuid_class, NULL, MKDEV(CPUID_MAJOR, i), "cpu%d",i);
-       if (IS_ERR(dev))
-               err = PTR_ERR(dev);
-       return err;
+       dev = device_create(cpuid_class, NULL, MKDEV(CPUID_MAJOR, cpu),
+                           "cpu%d", cpu);
+       return IS_ERR(dev) ? PTR_ERR(dev) : 0;
+}
+
+static void cpuid_device_destroy(int cpu)
+{
+       device_destroy(cpuid_class, MKDEV(CPUID_MAJOR, cpu));
 }
 
 static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
@@ -150,18 +153,21 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
                                              void *hcpu)
 {
        unsigned int cpu = (unsigned long)hcpu;
+       int err = 0;
 
        switch (action) {
-       case CPU_ONLINE:
-       case CPU_ONLINE_FROZEN:
-               cpuid_device_create(cpu);
+       case CPU_UP_PREPARE:
+       case CPU_UP_PREPARE_FROZEN:
+               err = cpuid_device_create(cpu);
                break;
+       case CPU_UP_CANCELED:
+       case CPU_UP_CANCELED_FROZEN:
        case CPU_DEAD:
        case CPU_DEAD_FROZEN:
-               device_destroy(cpuid_class, MKDEV(CPUID_MAJOR, cpu));
+               cpuid_device_destroy(cpu);
                break;
        }
-       return NOTIFY_OK;
+       return err ? NOTIFY_BAD : NOTIFY_OK;
 }
 
 static struct notifier_block __cpuinitdata cpuid_class_cpu_notifier =
@@ -198,7 +204,7 @@ static int __init cpuid_init(void)
 out_class:
        i = 0;
        for_each_online_cpu(i) {
-               device_destroy(cpuid_class, MKDEV(CPUID_MAJOR, i));
+               cpuid_device_destroy(i);
        }
        class_destroy(cpuid_class);
 out_chrdev:
@@ -212,7 +218,7 @@ static void __exit cpuid_exit(void)
        int cpu = 0;
 
        for_each_online_cpu(cpu)
-               device_destroy(cpuid_class, MKDEV(CPUID_MAJOR, cpu));
+               cpuid_device_destroy(cpu);
        class_destroy(cpuid_class);
        unregister_chrdev(CPUID_MAJOR, "cpu/cpuid");
        unregister_hotcpu_notifier(&cpuid_class_cpu_notifier);