summary refs log tree commit diff
diff options
context:
space:
mode:
authorXuewen Yan <xuewen.yan@unisoc.com>2022-08-25 19:40:17 +0800
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2022-09-03 20:07:36 +0200
commitcff895277c8558221ba180aefe26799dcb4eec86 (patch)
tree1f78c2ca05bc80e4c9d163563f43845c9c007da5
parent1ea252ef299bbce16cc40d52d0635346fdc4b7ea (diff)
downloadlinux-cff895277c8558221ba180aefe26799dcb4eec86.tar.gz
thermal: cpufreq_cooling: Check the policy first in cpufreq_cooling_register()
Since the policy needs to be accessed first when obtaining cpu devices,
first check whether the policy is legal before this.

Fixes: 5130802ddbb1 ("thermal: cpu_cooling: Switch to QoS requests for freq limits")
Signed-off-by: Xuewen Yan <xuewen.yan@unisoc.com>
Acked-by: Viresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r--drivers/thermal/cpufreq_cooling.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/drivers/thermal/cpufreq_cooling.c b/drivers/thermal/cpufreq_cooling.c
index b76293cc989c..7838b6e2dba5 100644
--- a/drivers/thermal/cpufreq_cooling.c
+++ b/drivers/thermal/cpufreq_cooling.c
@@ -501,17 +501,17 @@ __cpufreq_cooling_register(struct device_node *np,
 	struct thermal_cooling_device_ops *cooling_ops;
 	char *name;
 
+	if (IS_ERR_OR_NULL(policy)) {
+		pr_err("%s: cpufreq policy isn't valid: %p\n", __func__, policy);
+		return ERR_PTR(-EINVAL);
+	}
+
 	dev = get_cpu_device(policy->cpu);
 	if (unlikely(!dev)) {
 		pr_warn("No cpu device for cpu %d\n", policy->cpu);
 		return ERR_PTR(-ENODEV);
 	}
 
-	if (IS_ERR_OR_NULL(policy)) {
-		pr_err("%s: cpufreq policy isn't valid: %p\n", __func__, policy);
-		return ERR_PTR(-EINVAL);
-	}
-
 	i = cpufreq_table_count_valid_entries(policy);
 	if (!i) {
 		pr_debug("%s: CPUFreq table not found or has no valid entries\n",