lkml.org 
[lkml]   [2021]   [Nov]   [21]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    /
    Date
    From
    SubjectRe: [PATCH v4 16/22] cpupower: add the function to get the sysfs value from specific table
    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:
    > > 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@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

    \
     
     \ /
      Last update: 2021-11-22 03:42    [W:2.176 / U:0.380 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site