All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukasz Luba <lukasz.luba@arm.com>
To: Viresh Kumar <viresh.kumar@linaro.org>,
	Eduardo Valentin <edubezval@gmail.com>
Cc: javi.merino@kernel.org, rui.zhang@intel.com,
	linaro-kernel@lists.linaro.org, amit.kachhap@gmail.com,
	rjw@rjwysocki.net, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org, vincent.guittot@linaro.org
Subject: [PATCH] thermal: fix cpu cooling initialization
Date: Tue, 18 Apr 2017 15:51:48 +0100	[thread overview]
Message-ID: <20170418145148.GD6898@e105217-lin.cambridge.arm.com> (raw)
In-Reply-To: <3925c07c-1442-9e00-6f50-c4ae900ed834@arm.com>

This patch fixes issues with incorrect initialization
during cpu cooling registration.
The 'policy' and 'freq_table' must be initialized in cpufreq_cooling_device
before usage.

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

This patch fixes some issues to the patch set posted by Viresh.
I have tested it on Juno r2.

Regards,
Lukasz

diff --git a/drivers/thermal/cpu_cooling.c b/drivers/thermal/cpu_cooling.c
index 99ffd9f..c682e25 100644
--- a/drivers/thermal/cpu_cooling.c
+++ b/drivers/thermal/cpu_cooling.c
@@ -691,6 +691,9 @@ static unsigned int find_next_max(struct cpufreq_frequency_table *table,
 	struct thermal_cooling_device_ops *cooling_ops;
 	bool first;
 
+	if (WARN_ON(!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",
@@ -711,6 +714,7 @@ static unsigned int find_next_max(struct cpufreq_frequency_table *table,
 		goto free_cdev;
 	}
 
+	cpufreq_cdev->policy = policy;
 	/* max_level is an index, not a counter */
 	cpufreq_cdev->max_level = i - 1;
 
@@ -721,6 +725,18 @@ static unsigned int find_next_max(struct cpufreq_frequency_table *table,
 		goto free_idle_time;
 	}
 
+	/* Fill freq-table in descending order of frequencies */
+	for (i = 0, freq = -1; i <= cpufreq_cdev->max_level; i++) {
+		freq = find_next_max(policy->freq_table, freq);
+		cpufreq_cdev->freq_table[i].frequency = freq;
+
+		/* Warn for duplicate entries */
+		if (!freq)
+			pr_warn("%s: table has duplicate entries\n", __func__);
+		else
+			pr_debug("%s: freq:%u KHz\n", __func__, freq);
+	}
+
 	if (capacitance) {
 		cpufreq_cdev->plat_get_static_power = plat_static_func;
 
@@ -742,18 +758,6 @@ static unsigned int find_next_max(struct cpufreq_frequency_table *table,
 	}
 	cpufreq_cdev->id = ret;
 
-	/* Fill freq-table in descending order of frequencies */
-	for (i = 0, freq = -1; i <= cpufreq_cdev->max_level; i++) {
-		freq = find_next_max(policy->freq_table, freq);
-		cpufreq_cdev->freq_table[i].frequency = freq;
-
-		/* Warn for duplicate entries */
-		if (!freq)
-			pr_warn("%s: table has duplicate entries\n", __func__);
-		else
-			pr_debug("%s: freq:%u KHz\n", __func__, freq);
-	}
-
 	snprintf(dev_name, sizeof(dev_name), "thermal-cpufreq-%d",
 		 cpufreq_cdev->id);
 
-- 
1.9.1

  reply	other threads:[~2017-04-18 14:51 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-17  6:01 [PATCH V2 00/17] thermal: cpu_cooling: improve interaction with cpufreq core Viresh Kumar
2017-04-17  6:01 ` [PATCH V2 01/17] thermal: cpu_cooling: Avoid accessing potentially freed structures Viresh Kumar
2017-04-17  6:01 ` [PATCH V2 02/17] thermal: cpu_cooling: rearrange globals Viresh Kumar
2017-04-17  6:01 ` [PATCH V2 03/17] thermal: cpu_cooling: Name cpufreq cooling devices as cpufreq_cdev Viresh Kumar
2017-04-17  6:01 ` [PATCH V2 04/17] thermal: cpu_cooling: replace cool_dev with cdev Viresh Kumar
2017-04-17  6:01 ` [PATCH V2 05/17] thermal: cpu_cooling: remove cpufreq_cooling_get_level() Viresh Kumar
2017-04-17  6:01 ` [PATCH V2 06/17] thermal: cpu_cooling: get rid of a variable in cpufreq_set_cur_state() Viresh Kumar
2017-04-17  6:01 ` [PATCH V2 07/17] thermal: cpu_cooling: use cpufreq_policy to register cooling device Viresh Kumar
2017-04-17  6:01 ` [PATCH V2 08/17] cpufreq: create cpufreq_table_count_valid_entries() Viresh Kumar
2017-04-17  6:01 ` [PATCH V2 09/17] thermal: cpu_cooling: store cpufreq policy Viresh Kumar
2017-04-17  6:01 ` [PATCH V2 10/17] thermal: cpu_cooling: OPPs are registered for all CPUs Viresh Kumar
2017-04-17  6:01 ` [PATCH V2 11/17] thermal: cpu_cooling: get rid of 'allowed_cpus' Viresh Kumar
2017-04-17  6:01 ` [PATCH V2 12/17] thermal: cpu_cooling: merge frequency and power tables Viresh Kumar
2017-04-17  6:01 ` [PATCH V2 13/17] thermal: cpu_cooling: create structure for idle time stats Viresh Kumar
2017-04-17  6:01 ` [PATCH V2 14/17] thermal: cpu_cooling: get_level() can't fail Viresh Kumar
2017-04-17  6:02 ` [PATCH V2 15/17] thermal: cpu_cooling: don't store cpu_dev in cpufreq_cdev Viresh Kumar
2017-04-17  6:02 ` [PATCH V2 16/17] thermal: cpu_cooling: 'freq' can't be zero in cpufreq_state2power() Viresh Kumar
2017-04-17  6:02 ` [PATCH V2 17/17] thermal: cpu_cooling: Rearrange struct cpufreq_cooling_device Viresh Kumar
2017-04-17 17:34 ` [PATCH V2 00/17] thermal: cpu_cooling: improve interaction with cpufreq core Eduardo Valentin
2017-04-17 17:51   ` Eduardo Valentin
2017-04-18  7:23     ` Lukasz Luba
2017-04-18 10:38   ` Viresh Kumar
2017-04-18 14:40     ` Lukasz Luba
2017-04-18 14:51       ` Lukasz Luba [this message]
2017-04-19  5:22       ` Viresh Kumar
2017-04-24 10:43         ` Lukasz Luba
2017-04-24 10:44           ` Viresh Kumar

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170418145148.GD6898@e105217-lin.cambridge.arm.com \
    --to=lukasz.luba@arm.com \
    --cc=amit.kachhap@gmail.com \
    --cc=edubezval@gmail.com \
    --cc=javi.merino@kernel.org \
    --cc=linaro-kernel@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=rjw@rjwysocki.net \
    --cc=rui.zhang@intel.com \
    --cc=vincent.guittot@linaro.org \
    --cc=viresh.kumar@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.