linux-pm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/3] thermal: cpufreq_cooling: Use a copy of local ops for each cooling device
@ 2022-06-10 10:03 Lukasz Luba
  2022-06-10 10:03 ` [PATCH 2/3] thermal: cpufreq_cooling : Refactor thermal_power_cpu_get_power Lukasz Luba
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Lukasz Luba @ 2022-06-10 10:03 UTC (permalink / raw)
  To: linux-kernel, linux-pm
  Cc: daniel.lezcano, amitk, rui.zhang, lukasz.luba, viresh.kumar,
	rafael, dietmar.eggemann

It is very unlikely that one CPU cluster would have the EM and some other
won't have it (because EM registration failed or DT lacks needed entry).
Although, we should avoid modifying global variable with callbacks anyway.
Redesign this and add safety for such situation.

Signed-off-by: Lukasz Luba <lukasz.luba@arm.com>
---
 drivers/thermal/cpufreq_cooling.c | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/drivers/thermal/cpufreq_cooling.c b/drivers/thermal/cpufreq_cooling.c
index b8151d95a806..e33183785fac 100644
--- a/drivers/thermal/cpufreq_cooling.c
+++ b/drivers/thermal/cpufreq_cooling.c
@@ -554,7 +554,12 @@ __cpufreq_cooling_register(struct device_node *np,
 	/* max_level is an index, not a counter */
 	cpufreq_cdev->max_level = i - 1;
 
-	cooling_ops = &cpufreq_cooling_ops;
+	cooling_ops = kmemdup(&cpufreq_cooling_ops, sizeof(*cooling_ops),
+			      GFP_KERNEL);
+	if (!cooling_ops) {
+		cdev = ERR_PTR(-ENOMEM);
+		goto free_idle_time;
+	}
 
 #ifdef CONFIG_THERMAL_GOV_POWER_ALLOCATOR
 	if (em_is_sane(cpufreq_cdev, em)) {
@@ -568,7 +573,7 @@ __cpufreq_cooling_register(struct device_node *np,
 		pr_err("%s: unsorted frequency tables are not supported\n",
 		       __func__);
 		cdev = ERR_PTR(-EINVAL);
-		goto free_idle_time;
+		goto free_cooling_ops;
 	}
 
 	ret = freq_qos_add_request(&policy->constraints,
@@ -578,7 +583,7 @@ __cpufreq_cooling_register(struct device_node *np,
 		pr_err("%s: Failed to add freq constraint (%d)\n", __func__,
 		       ret);
 		cdev = ERR_PTR(ret);
-		goto free_idle_time;
+		goto free_cooling_ops;
 	}
 
 	cdev = ERR_PTR(-ENOMEM);
@@ -597,6 +602,8 @@ __cpufreq_cooling_register(struct device_node *np,
 
 remove_qos_req:
 	freq_qos_remove_request(&cpufreq_cdev->qos_req);
+free_cooling_ops:
+	kfree(cooling_ops);
 free_idle_time:
 	free_idle_time(cpufreq_cdev);
 free_cdev:
@@ -677,16 +684,19 @@ EXPORT_SYMBOL_GPL(of_cpufreq_cooling_register);
  */
 void cpufreq_cooling_unregister(struct thermal_cooling_device *cdev)
 {
+	const struct thermal_cooling_device_ops *ops;
 	struct cpufreq_cooling_device *cpufreq_cdev;
 
 	if (!cdev)
 		return;
 
 	cpufreq_cdev = cdev->devdata;
+	ops = cdev->ops;
 
 	thermal_cooling_device_unregister(cdev);
 	freq_qos_remove_request(&cpufreq_cdev->qos_req);
 	free_idle_time(cpufreq_cdev);
 	kfree(cpufreq_cdev);
+	kfree(ops);
 }
 EXPORT_SYMBOL_GPL(cpufreq_cooling_unregister);
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-06-13 13:22 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-10 10:03 [PATCH 1/3] thermal: cpufreq_cooling: Use a copy of local ops for each cooling device Lukasz Luba
2022-06-10 10:03 ` [PATCH 2/3] thermal: cpufreq_cooling : Refactor thermal_power_cpu_get_power Lukasz Luba
2022-06-13  9:41   ` Viresh Kumar
2022-06-10 10:03 ` [PATCH 3/3] thermal: cpufreq_cooling: Update outdated comments Lukasz Luba
2022-06-13  9:42   ` Viresh Kumar
2022-06-13  9:16 ` [PATCH 1/3] thermal: cpufreq_cooling: Use a copy of local ops for each cooling device Viresh Kumar
2022-06-13 10:37   ` Lukasz Luba
2022-06-13 10:53     ` Viresh Kumar
2022-06-13 11:23       ` Lukasz Luba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).