Linux-PM Archive mirror
 help / color / mirror / Atom feed
From: chizhiling@163.com
To: rafael@kernel.org, viresh.kumar@linaro.org
Cc: linux-pm@vger.kernel.org, Chi Zhiling <chizhiling@kylinos.cn>
Subject: [PATCH] cpufreq: add a check for unsupported CPU frequencies
Date: Wed, 15 May 2024 10:20:37 +0800	[thread overview]
Message-ID: <20240515022037.818078-1-chizhiling@163.com> (raw)

From: Chi Zhiling <chizhiling@kylinos.cn>

When user wants to control the CPU frequency on their own,
if they write an unsupported frequency to the
scaling_min_freq/scaling_max_freq node, the execution will not report an
error, which will make the user think that the execution is successful.

So, this patch add a check to return an error if an unsupported frequency
is written.

Testing:
CPU supported frequency [min, max] = [800000, 4600000]

before patch:
root: echo 0 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq
root: echo 5000000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq
root: echo 0 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq
root: echo 5000000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq
root:

after patch:
root: echo 0 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq
-bash: echo: Invalid argument
root: echo 5000000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_min_freq
-bash: echo: Invalid argument
root: echo 0 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq
-bash: echo: Invalid argument
root: echo 5000000 > /sys/devices/system/cpu/cpu1/cpufreq/scaling_max_freq
-bash: echo: Invalid argument
root:

Signed-off-by: Chi Zhiling <chizhiling@kylinos.cn>
---
 drivers/cpufreq/freq_table.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/cpufreq/freq_table.c b/drivers/cpufreq/freq_table.c
index 10e80d912b8d..416826d582a4 100644
--- a/drivers/cpufreq/freq_table.c
+++ b/drivers/cpufreq/freq_table.c
@@ -76,6 +76,11 @@ int cpufreq_frequency_table_verify(struct cpufreq_policy_data *policy,
 	pr_debug("request for verification of policy (%u - %u kHz) for cpu %u\n",
 					policy->min, policy->max, policy->cpu);
 
+	if (policy->min > policy->max ||
+	    policy->max > policy->cpuinfo.max_freq ||
+	    policy->min < policy->cpuinfo.min_freq)
+		return -EINVAL;
+
 	cpufreq_verify_within_cpu_limits(policy);
 
 	cpufreq_for_each_valid_entry(pos, table) {
-- 
2.27.0


             reply	other threads:[~2024-05-15  2:21 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-15  2:20 chizhiling [this message]
2024-05-20  7:55 ` [PATCH] cpufreq: add a check for unsupported CPU frequencies Viresh Kumar
2024-05-21  6:18   ` chizhiling

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=20240515022037.818078-1-chizhiling@163.com \
    --to=chizhiling@163.com \
    --cc=chizhiling@kylinos.cn \
    --cc=linux-pm@vger.kernel.org \
    --cc=rafael@kernel.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 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 read-only IMAP folder(s) and NNTP newsgroup(s).