PM / devfreq: Lock CPU online/offline in rockchip_dmcfreq_target()
authorFinley Xiao <finley.xiao@rock-chips.com>
Mon, 15 May 2017 01:42:29 +0000 (09:42 +0800)
committerHuang, Tao <huangtao@rock-chips.com>
Wed, 17 May 2017 03:45:40 +0000 (11:45 +0800)
To protect against races with concurrent CPU online/offline, call
get_online_cpus() before change frequency.

Change-Id: I5b97cd7eff6a1c4828ab30bc165fb2aa8b460bb3
Signed-off-by: Finley Xiao <finley.xiao@rock-chips.com>
drivers/devfreq/rockchip_dmc.c

index 4cf6a1999248298ddd520ab231e723d13576cd26..81a2f2c89897cce41a61ce54fb1677b197bb949c 100644 (file)
@@ -17,6 +17,7 @@
 #include <drm/drmP.h>
 #include <linux/arm-smccc.h>
 #include <linux/clk.h>
+#include <linux/cpu.h>
 #include <linux/delay.h>
 #include <linux/devfreq.h>
 #include <linux/devfreq-event.h>
@@ -217,7 +218,16 @@ static int rockchip_dmcfreq_target(struct device *dev, unsigned long *freq,
                }
        }
 
+       /*
+        * We need to prevent cpu hotplug from happening while a dmc freq rate
+        * change is happening.
+        */
+       get_online_cpus();
+
        err = clk_set_rate(dmcfreq->dmc_clk, target_rate);
+
+       put_online_cpus();
+
        if (err) {
                dev_err(dev, "Cannot set frequency %lu (%d)\n",
                        target_rate, err);