timekeeping: Fix cross-timestamp interpolation on counter wrap
authorPeter Hilber <peter.hilber@opensynergy.com>
Mon, 18 Dec 2023 07:38:39 +0000 (08:38 +0100)
committerThomas Gleixner <tglx@linutronix.de>
Mon, 19 Feb 2024 11:18:51 +0000 (12:18 +0100)
cycle_between() decides whether get_device_system_crosststamp() will
interpolate for older counter readings.

cycle_between() yields wrong results for a counter wrap-around where after
< before < test, and for the case after < test < before.

Fix the comparison logic.

Fixes: 2c756feb18d9 ("time: Add history to cross timestamp interface supporting slower devices")
Signed-off-by: Peter Hilber <peter.hilber@opensynergy.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: John Stultz <jstultz@google.com>
Link: https://lore.kernel.org/r/20231218073849.35294-2-peter.hilber@opensynergy.com
kernel/time/timekeeping.c

index 266d02809dbb1dceabfb2a05276385c6a3be9b0c..8f35455b62509d9db74459cba9426198b4b16d4e 100644 (file)
@@ -1186,7 +1186,7 @@ static bool cycle_between(u64 before, u64 test, u64 after)
 {
        if (test > before && test < after)
                return true;
-       if (test < before && before > after)
+       if (before > after && (test > before || test < after))
                return true;
        return false;
 }