aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrendan Jackman <brendan.jackman@arm.com>2016-08-17 11:14:59 -0400
committerZhang Rui <rui.zhang@intel.com>2016-08-19 09:32:18 -0400
commita305a4387acb01cecadeeea5151c049a022a1bfc (patch)
tree4563fb3c6b8956491b1326ba5ec3d160b9850fda
parent694d0d0bb2030d2e36df73e2d23d5770511dbc8d (diff)
thermal: cpu_cooling: Fix NULL dereference in cpufreq_state2power
Currently all CPU cooling devices share a `struct thermal_cooling_device_ops` instance. The thermal core uses the presence of functions in this struct to determine if a cooling device has a power model (see cdev_is_power_actor). cpu_cooling.c adds the power model functions to the shared struct when a device is registered with a power model. Therefore, if a CPU cooling device is registered using [of_]cpufreq_power_cooling_register, _all_ devices will be determined to have a power model, including any registered with [of_]cpufreq_cooling_register. This can result in cpufreq_state2power being called on a device where dyn_power_table is NULL. With this commit, instead of having a shared thermal_cooling_device_ops which is mutated, we have two versions: one with the power functions and one without. Signed-off-by: Brendan Jackman <brendan.jackman@arm.com> Cc: Amit Daniel Kachhap <amit.kachhap@gmail.com> Cc: Viresh Kumar <viresh.kumar@linaro.org> Cc: Javi Merino <javi.merino@arm.com> Acked-by: Viresh Kumar <viresh.kumar@linaro.org> Acked-by: Javi Merino <javi.merino@arm.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
-rw-r--r--drivers/thermal/cpu_cooling.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 3788ed74c9ab..a32b41783b77 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -740,12 +740,22 @@ static int cpufreq_power2state(struct thermal_cooling_device *cdev,
740} 740}
741 741
742/* Bind cpufreq callbacks to thermal cooling device ops */ 742/* Bind cpufreq callbacks to thermal cooling device ops */
743
743static struct thermal_cooling_device_ops cpufreq_cooling_ops = { 744static struct thermal_cooling_device_ops cpufreq_cooling_ops = {
744 .get_max_state = cpufreq_get_max_state, 745 .get_max_state = cpufreq_get_max_state,
745 .get_cur_state = cpufreq_get_cur_state, 746 .get_cur_state = cpufreq_get_cur_state,
746 .set_cur_state = cpufreq_set_cur_state, 747 .set_cur_state = cpufreq_set_cur_state,
747}; 748};
748 749
750static struct thermal_cooling_device_ops cpufreq_power_cooling_ops = {
751 .get_max_state = cpufreq_get_max_state,
752 .get_cur_state = cpufreq_get_cur_state,
753 .set_cur_state = cpufreq_set_cur_state,
754 .get_requested_power = cpufreq_get_requested_power,
755 .state2power = cpufreq_state2power,
756 .power2state = cpufreq_power2state,
757};
758
749/* Notifier for cpufreq policy change */ 759/* Notifier for cpufreq policy change */
750static struct notifier_block thermal_cpufreq_notifier_block = { 760static struct notifier_block thermal_cpufreq_notifier_block = {
751 .notifier_call = cpufreq_thermal_notifier, 761 .notifier_call = cpufreq_thermal_notifier,
@@ -795,6 +805,7 @@ __cpufreq_cooling_register(struct device_node *np,
795 struct cpumask temp_mask; 805 struct cpumask temp_mask;
796 unsigned int freq, i, num_cpus; 806 unsigned int freq, i, num_cpus;
797 int ret; 807 int ret;
808 struct thermal_cooling_device_ops *cooling_ops;
798 809
799 cpumask_and(&temp_mask, clip_cpus, cpu_online_mask); 810 cpumask_and(&temp_mask, clip_cpus, cpu_online_mask);
800 policy = cpufreq_cpu_get(cpumask_first(&temp_mask)); 811 policy = cpufreq_cpu_get(cpumask_first(&temp_mask));
@@ -850,10 +861,6 @@ __cpufreq_cooling_register(struct device_node *np,
850 cpumask_copy(&cpufreq_dev->allowed_cpus, clip_cpus); 861 cpumask_copy(&cpufreq_dev->allowed_cpus, clip_cpus);
851 862
852 if (capacitance) { 863 if (capacitance) {
853 cpufreq_cooling_ops.get_requested_power =
854 cpufreq_get_requested_power;
855 cpufreq_cooling_ops.state2power = cpufreq_state2power;
856 cpufreq_cooling_ops.power2state = cpufreq_power2state;
857 cpufreq_dev->plat_get_static_power = plat_static_func; 864 cpufreq_dev->plat_get_static_power = plat_static_func;
858 865
859 ret = build_dyn_power_table(cpufreq_dev, capacitance); 866 ret = build_dyn_power_table(cpufreq_dev, capacitance);
@@ -861,6 +868,10 @@ __cpufreq_cooling_register(struct device_node *np,
861 cool_dev = ERR_PTR(ret); 868 cool_dev = ERR_PTR(ret);
862 goto free_table; 869 goto free_table;
863 } 870 }
871
872 cooling_ops = &cpufreq_power_cooling_ops;
873 } else {
874 cooling_ops = &cpufreq_cooling_ops;
864 } 875 }
865 876
866 ret = get_idr(&cpufreq_idr, &cpufreq_dev->id); 877 ret = get_idr(&cpufreq_idr, &cpufreq_dev->id);
@@ -885,7 +896,7 @@ __cpufreq_cooling_register(struct device_node *np,
885 cpufreq_dev->id); 896 cpufreq_dev->id);
886 897
887 cool_dev = thermal_of_cooling_device_register(np, dev_name, cpufreq_dev, 898 cool_dev = thermal_of_cooling_device_register(np, dev_name, cpufreq_dev,
888 &cpufreq_cooling_ops); 899 cooling_ops);
889 if (IS_ERR(cool_dev)) 900 if (IS_ERR(cool_dev))
890 goto remove_idr; 901 goto remove_idr;
891 902