hwmon: Use smp_call_on_cpu() for dell-smm i8k
[cascardo/linux.git] / drivers / hwmon / dell-smm-hwmon.c
index acf9c03..34704b0 100644 (file)
@@ -21,6 +21,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <linux/cpu.h>
 #include <linux/delay.h>
 #include <linux/module.h>
 #include <linux/types.h>
@@ -36,6 +37,7 @@
 #include <linux/io.h>
 #include <linux/sched.h>
 #include <linux/ctype.h>
+#include <linux/smp.h>
 
 #include <linux/i8k.h>
 
@@ -134,11 +136,11 @@ static inline const char *i8k_get_dmi_data(int field)
 /*
  * Call the System Management Mode BIOS. Code provided by Jonathan Buzzard.
  */
-static int i8k_smm(struct smm_regs *regs)
+static int i8k_smm_func(void *par)
 {
        int rc;
+       struct smm_regs *regs = par;
        int eax = regs->eax;
-       cpumask_var_t old_mask;
 
 #ifdef DEBUG
        int ebx = regs->ebx;
@@ -149,16 +151,8 @@ static int i8k_smm(struct smm_regs *regs)
 #endif
 
        /* SMM requires CPU 0 */
-       if (!alloc_cpumask_var(&old_mask, GFP_KERNEL))
-               return -ENOMEM;
-       cpumask_copy(old_mask, &current->cpus_allowed);
-       rc = set_cpus_allowed_ptr(current, cpumask_of(0));
-       if (rc)
-               goto out;
-       if (smp_processor_id() != 0) {
-               rc = -EBUSY;
-               goto out;
-       }
+       if (smp_processor_id() != 0)
+               return -EBUSY;
 
 #if defined(CONFIG_X86_64)
        asm volatile("pushq %%rax\n\t"
@@ -216,10 +210,6 @@ static int i8k_smm(struct smm_regs *regs)
        if (rc != 0 || (regs->eax & 0xffff) == 0xffff || regs->eax == eax)
                rc = -EINVAL;
 
-out:
-       set_cpus_allowed_ptr(current, old_mask);
-       free_cpumask_var(old_mask);
-
 #ifdef DEBUG
        rettime = ktime_get();
        delta = ktime_sub(rettime, calltime);
@@ -231,6 +221,20 @@ out:
        return rc;
 }
 
+/*
+ * Call the System Management Mode BIOS.
+ */
+static int i8k_smm(struct smm_regs *regs)
+{
+       int ret;
+
+       get_online_cpus();
+       ret = smp_call_on_cpu(0, i8k_smm_func, regs, true);
+       put_online_cpus();
+
+       return ret;
+}
+
 /*
  * Read the fan status.
  */