[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20211119221943.92479-1-juuso.alasuutari@gmail.com>
Date: Sat, 20 Nov 2021 00:19:43 +0200
From: Juuso Alasuutari <juuso.alasuutari@...il.com>
To: nafonten@....com
Cc: Jinzhou.Su@....com, Xiaojian.Du@....com, alexander.deucher@....com,
bp@...e.de, deepak.sharma@....com, ggherdovich@...e.cz,
linux-kernel@...r.kernel.org, linux-pm@...r.kernel.org,
mario.limonciello@....com, mingo@...nel.org,
nathan.fontenot@....com, peterz@...radead.org,
rafael.j.wysocki@...el.com, ray.huang@....com,
skhan@...uxfoundation.org, steven@...vesoftware.com,
viresh.kumar@...aro.org, x86@...nel.org
Subject: Re: [PATCH v4 16/22] cpupower: add the function to get the sysfs value from specific table
On Fri, 19 Nov 2021 14:38:58 -0600, Nathan Fontenot wrote:
> On 11/19/21 4:30 AM, Huang Rui wrote:
> > 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@....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])
- Juuso
Powered by blists - more mailing lists