x86/cpu: Fix bootup crashes by sanitizing the argument of the 'clearcpuid=' command...
[pandora-kernel.git] / arch / x86 / kernel / microcode_core.c
index 9d46f5e..29c95d7 100644 (file)
@@ -297,20 +297,31 @@ static ssize_t reload_store(struct sys_device *dev,
                            const char *buf, size_t size)
 {
        unsigned long val;
-       int cpu = dev->id;
-       int ret = 0;
-       char *end;
+       int cpu;
+       ssize_t ret = 0, tmp_ret;
 
-       val = simple_strtoul(buf, &end, 0);
-       if (end == buf)
+       /* allow reload only from the BSP */
+       if (boot_cpu_data.cpu_index != dev->id)
                return -EINVAL;
 
-       if (val == 1) {
-               get_online_cpus();
-               if (cpu_online(cpu))
-                       ret = reload_for_cpu(cpu);
-               put_online_cpus();
+       ret = kstrtoul(buf, 0, &val);
+       if (ret)
+               return ret;
+
+       if (val != 1)
+               return size;
+
+       get_online_cpus();
+       for_each_online_cpu(cpu) {
+               tmp_ret = reload_for_cpu(cpu);
+               if (tmp_ret != 0)
+                       pr_warn("Error reloading microcode on CPU %d\n", cpu);
+
+               /* save retval of the first encountered reload error */
+               if (!ret)
+                       ret = tmp_ret;
        }
+       put_online_cpus();
 
        if (!ret)
                ret = size;
@@ -418,10 +429,8 @@ static int mc_sysdev_add(struct sys_device *sys_dev)
        if (err)
                return err;
 
-       if (microcode_init_cpu(cpu) == UCODE_ERROR) {
-               sysfs_remove_group(&sys_dev->kobj, &mc_attr_group);
+       if (microcode_init_cpu(cpu) == UCODE_ERROR)
                return -EINVAL;
-       }
 
        return err;
 }