提交 4b972f0b 编写于 作者: V viresh kumar 提交者: Rafael J. Wysocki

cpufreq / core: Fix printing of governor and driver name

Arrays for governer and driver name are of size CPUFREQ_NAME_LEN or 16.
i.e. 15 bytes for name and 1 for trailing '\0'.

When cpufreq driver print these names (for sysfs), it includes '\n' or ' ' in
the fmt string and still passes length as CPUFREQ_NAME_LEN. If the driver or
governor names are using all 15 fields allocated to them, then the trailing '\n'
or ' ' will never be printed. And so commands like:

root@linaro-developer# cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_driver

will print something like:

cpufreq_foodrvroot@linaro-developer#

Fix this by increasing print length by one character.
Signed-off-by: NViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: NRafael J. Wysocki <rafael.j.wysocki@intel.com>
上级 8bf1ac72
...@@ -445,7 +445,7 @@ static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf) ...@@ -445,7 +445,7 @@ static ssize_t show_scaling_governor(struct cpufreq_policy *policy, char *buf)
else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE) else if (policy->policy == CPUFREQ_POLICY_PERFORMANCE)
return sprintf(buf, "performance\n"); return sprintf(buf, "performance\n");
else if (policy->governor) else if (policy->governor)
return scnprintf(buf, CPUFREQ_NAME_LEN, "%s\n", return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n",
policy->governor->name); policy->governor->name);
return -EINVAL; return -EINVAL;
} }
...@@ -491,7 +491,7 @@ static ssize_t store_scaling_governor(struct cpufreq_policy *policy, ...@@ -491,7 +491,7 @@ static ssize_t store_scaling_governor(struct cpufreq_policy *policy,
*/ */
static ssize_t show_scaling_driver(struct cpufreq_policy *policy, char *buf) static ssize_t show_scaling_driver(struct cpufreq_policy *policy, char *buf)
{ {
return scnprintf(buf, CPUFREQ_NAME_LEN, "%s\n", cpufreq_driver->name); return scnprintf(buf, CPUFREQ_NAME_PLEN, "%s\n", cpufreq_driver->name);
} }
/** /**
...@@ -512,7 +512,7 @@ static ssize_t show_scaling_available_governors(struct cpufreq_policy *policy, ...@@ -512,7 +512,7 @@ static ssize_t show_scaling_available_governors(struct cpufreq_policy *policy,
if (i >= (ssize_t) ((PAGE_SIZE / sizeof(char)) if (i >= (ssize_t) ((PAGE_SIZE / sizeof(char))
- (CPUFREQ_NAME_LEN + 2))) - (CPUFREQ_NAME_LEN + 2)))
goto out; goto out;
i += scnprintf(&buf[i], CPUFREQ_NAME_LEN, "%s ", t->name); i += scnprintf(&buf[i], CPUFREQ_NAME_PLEN, "%s ", t->name);
} }
out: out:
i += sprintf(&buf[i], "\n"); i += sprintf(&buf[i], "\n");
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#include <asm/div64.h> #include <asm/div64.h>
#define CPUFREQ_NAME_LEN 16 #define CPUFREQ_NAME_LEN 16
/* Print length for names. Extra 1 space for accomodating '\n' in prints */
#define CPUFREQ_NAME_PLEN (CPUFREQ_NAME_LEN + 1)
/********************************************************************* /*********************************************************************
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册