Re: [PATCH v4 16/22] cpupower: add the function to get the sysfs value from specific table
From: Huang Rui <ray.huang@amd.com>
Date: 2021-11-22 02:41:38
Also in:
lkml
On Sat, Nov 20, 2021 at 06:19:43AM +0800, Juuso Alasuutari wrote:
On Fri, 19 Nov 2021 14:38:58 -0600, Nathan Fontenot wrote:quoted
On 11/19/21 4:30 AM, Huang Rui wrote:quoted
Expose the helper into cpufreq header, then cpufreq driver can use this function to get the sysfs value if it has any specific sysfs interfaces. Signed-off-by: Huang Rui <ray.huang@amd.com> --- tools/power/cpupower/lib/cpufreq.c | 21 +++++++++++++++------ tools/power/cpupower/lib/cpufreq.h | 12 ++++++++++++ 2 files changed, 27 insertions(+), 6 deletions(-)diff --git a/tools/power/cpupower/lib/cpufreq.c b/tools/power/cpupower/lib/cpufreq.c index c3b56db8b921..02719cc400a1 100644 --- a/tools/power/cpupower/lib/cpufreq.c +++ b/tools/power/cpupower/lib/cpufreq.c@@ -83,20 +83,21 @@ static const char *cpufreq_value_files[MAX_CPUFREQ_VALUE_READ_FILES] = { [STATS_NUM_TRANSITIONS] = "stats/total_trans" }; - -static unsigned long sysfs_cpufreq_get_one_value(unsigned int cpu, - enum cpufreq_value which) +unsigned long cpufreq_get_sysfs_value_from_table(unsigned int cpu, + const char **table, + unsigned index, + unsigned size) { unsigned long value; unsigned int len; char linebuf[MAX_LINE_LEN]; char *endp; - if (which >= MAX_CPUFREQ_VALUE_READ_FILES) + if (!table && !table[index] && index >= size)Should you validate the index before accessing table[index] if (!table && index >= size && !table[index])The operator is wrong as well. I believe this is what was originally intended: if (!table || index >= size || !table[index])
Yes, nice catch. Thanks. Updated it. Thanks, Ray