]> www.infradead.org Git - linux-platform-drivers-x86.git/commitdiff
cpuidle: Use s64 as exit_latency_ns and target_residency_ns data type
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Mon, 29 Mar 2021 18:15:19 +0000 (20:15 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 7 Apr 2021 17:26:44 +0000 (19:26 +0200)
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>
drivers/cpuidle/driver.c
include/linux/cpuidle.h

index 4070e573bf43a49ee638085448d46e705894e74d..f70aa17e2a8e0e9e9576252f8a33280c3d601115 100644 (file)
@@ -181,9 +181,13 @@ static void __cpuidle_driver_init(struct cpuidle_driver *drv)
                 */
                if (s->target_residency > 0)
                        s->target_residency_ns = s->target_residency * NSEC_PER_USEC;
+               else if (s->target_residency_ns < 0)
+                       s->target_residency_ns = 0;
 
                if (s->exit_latency > 0)
                        s->exit_latency_ns = s->exit_latency * NSEC_PER_USEC;
+               else if (s->exit_latency_ns < 0)
+                       s->exit_latency_ns =  0;
        }
 }
 
index bd605b5585cf6793d350f74227f150b4f82ca41e..fce476275e16ced61c5fdb105b8112e829996c80 100644 (file)
@@ -49,8 +49,8 @@ struct cpuidle_state {
        char            name[CPUIDLE_NAME_LEN];
        char            desc[CPUIDLE_DESC_LEN];
 
-       u64             exit_latency_ns;
-       u64             target_residency_ns;
+       s64             exit_latency_ns;
+       s64             target_residency_ns;
        unsigned int    flags;
        unsigned int    exit_latency; /* in US */
        int             power_usage; /* in mW */