diff options
author | Joseph Xu <josephzxu@gmail.com> | 2008-07-11 00:14:54 -0400 |
---|---|---|
committer | Dominik Brodowski <linux@dominikbrodowski.net> | 2008-07-11 17:43:26 +0200 |
commit | b88f8975d27690e04e520b05a1ed66bf1e306ee6 (patch) | |
tree | f8fb521d04138a4ff3b3221822e2a88219b45dca | |
parent | e124df1ac3a25e62c33477343aff610a443f8f28 (diff) | |
download | cpufrequtils-b88f8975d27690e04e520b05a1ed66bf1e306ee6.tar.gz |
sysfs: fix sysfs_set_policy()
Fix a bug that causes a failure when trying to write a new cpufreq
policy whose maximum frequency value is less than the old policy's
minimum frequency value. Since the max value is not allowed to be
lower than the min value, writing to the sysfs file scaling_max_freq
will fail. The patch checks for this situation, and if it occurs, will
write the new min value before writing the new max value.
Signed-off-by: Joseph Xu <josephzxu@gmail.com>
Signed-off-by: Dominik Brodowski <linux@dominikbrodowski.net>
-rw-r--r-- | lib/sysfs.c | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/sysfs.c b/lib/sysfs.c index 3065ae7..6bae2ba 100644 --- a/lib/sysfs.c +++ b/lib/sysfs.c @@ -562,6 +562,8 @@ int sysfs_set_policy(unsigned int cpu, struct cpufreq_policy *policy) char max[SYSFS_PATH_MAX]; char gov[SYSFS_PATH_MAX]; int ret; + unsigned long old_min; + int write_max_first; if (!policy || !(policy->governor)) return -EINVAL; @@ -575,14 +577,25 @@ int sysfs_set_policy(unsigned int cpu, struct cpufreq_policy *policy) snprintf(min, SYSFS_PATH_MAX, "%lu", policy->min); snprintf(max, SYSFS_PATH_MAX, "%lu", policy->max); - ret = sysfs_write_one_value(cpu, WRITE_SCALING_MAX_FREQ, max, strlen(max)); - if (ret) - return ret; + old_min = sysfs_get_one_value(cpu, SCALING_MIN_FREQ); + write_max_first = (old_min && (policy->max < old_min) ? 0 : 1); + + if (write_max_first) { + ret = sysfs_write_one_value(cpu, WRITE_SCALING_MAX_FREQ, max, strlen(max)); + if (ret) + return ret; + } ret = sysfs_write_one_value(cpu, WRITE_SCALING_MIN_FREQ, min, strlen(min)); if (ret) return ret; + if (!write_max_first) { + ret = sysfs_write_one_value(cpu, WRITE_SCALING_MAX_FREQ, max, strlen(max)); + if (ret) + return ret; + } + return sysfs_write_one_value(cpu, WRITE_SCALING_GOVERNOR, gov, strlen(gov)); } |