lkml.org 
[lkml]   [2017]   [Sep]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] cpufreq: cpufreq_stats: make last_index signed int
On 15-09-17, 13:13, Bo Yan wrote:
> It is possible for last_index to get a -1 if current frequency
> is not found in the freq table when stats is created. If the
> function "cpufreq_stats_update" is called before last_index is
> updated with a valid value, the "-1" will be used as index to
> update stats->time_in_state, triggering an exception.

No, that's not how it works AFAIK and if it did, then can you explain how your
solution fixes it?

AFAIK, what happens right now is that stats->last_index eventually stores
2147483647 (uint max) and the exception comes while accessing that value.

While with your change, it will become -1 and accessing array[-1] is fine by C
standards, though it is still the wrong thing to do as you are accessing
something outside of the array.

We should just check last_index == -1 before calling cpufreq_stats_update(),
which is already done by one of the callers.

--
viresh

\
 
 \ /
  Last update: 2017-09-18 03:50    [W:0.104 / U:1.348 seconds]
©2003-2017 Jasper Spaans. hosted at Digital OceanAdvertise on this site