Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cpuidle: Use s64 as exit_latency_ns and target_residency_ns data type

Subsequent changes will cause the exit_latency_ns and target_residency_ns
fields in struct cpuidle_state to be used in computations in which data
type conversions to u64 may turn a negative number close to zero into
a verly large positive number leading to incorrect results.

In preparation for that, change the data type of the fields mentioned
above to s64, but ensure that they will not be negative themselves.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

+6 -2
+4
drivers/cpuidle/driver.c
··· 181 181 */ 182 182 if (s->target_residency > 0) 183 183 s->target_residency_ns = s->target_residency * NSEC_PER_USEC; 184 + else if (s->target_residency_ns < 0) 185 + s->target_residency_ns = 0; 184 186 185 187 if (s->exit_latency > 0) 186 188 s->exit_latency_ns = s->exit_latency * NSEC_PER_USEC; 189 + else if (s->exit_latency_ns < 0) 190 + s->exit_latency_ns = 0; 187 191 } 188 192 } 189 193
+2 -2
include/linux/cpuidle.h
··· 49 49 char name[CPUIDLE_NAME_LEN]; 50 50 char desc[CPUIDLE_DESC_LEN]; 51 51 52 - u64 exit_latency_ns; 53 - u64 target_residency_ns; 52 + s64 exit_latency_ns; 53 + s64 target_residency_ns; 54 54 unsigned int flags; 55 55 unsigned int exit_latency; /* in US */ 56 56 int power_usage; /* in mW */