[PATCH] ARM: Restore get_cycles() return value

Ryan Chen ryan_chen at aspeedtech.com
Thu Aug 20 02:10:48 PDT 2026


read_current_timer() returned 0 on success, so the get_cycles() ternary
yielded the cycle count on success and 0 on failure. delay_read_timer()
returns true on success, but the ternary was left alone, so get_cycles()
now yields 0 on success and an uninitialised variable on failure.

Swap the arms of the ternary to restore the original meaning.

Fixes: dfc256dac54c ("calibrate: Rework delay timer calibration")
Signed-off-by: Ryan Chen <ryan_chen at aspeedtech.com>
---
Found by bisecting a boot failure on an Aspeed AST2600 EVB (ARMv7):

  3ed403bbc967 ("treewide: Remove CLOCK_TICK_RATE")       boots
  030c9f813b8e (Merge tag 'timers-cleanups-2026-08-17')   hangs

dfc256dac54c is the only commit between the two that touches ARM. With
earlycon enabled the output stops at:

  Serial: 8250/16550 driver, 6 ports, IRQ sharing enabled
  printk: legacy console [ttyS4] disabled

where a working kernel continues with:

  1e784000.serial: ttyS4 at MMIO 0x1e784000 (irq = 33, ...) is a 16550A
  printk: legacy console [ttyS4] enabled
  printk: legacy bootconsole [uart8250] disabled

The earlycon is still registered where the output stops, so this is a hang
rather than lost output. Without earlycon there is no output at all, since
the real console only registers at ~0.19s on this platform.

With this patch applied the AST2600 EVB boots to userspace again, and the
8250 registration completes as it did before dfc256dac54c:

  Serial: 8250/16550 driver, 6 ports, IRQ sharing enabled
  printk: legacy console [ttyS4] disabled
  1e784000.serial: ttyS4 at MMIO 0x1e784000 (irq = 33, ...) is a 16550A
  printk: legacy console [ttyS4] enabled

Note that every other architecture touched by dfc256dac54c dropped its
asm/timex.h in favour of the asm-generic one. ARM kept its copy with the
"Temporary workaround until timex.h is cleaned up" comment, which is where
the inversion slipped in.
---
 arch/arm/include/asm/timex.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/include/asm/timex.h b/arch/arm/include/asm/timex.h
index 94e40c19cfc5..4d31eab9dba2 100644
--- a/arch/arm/include/asm/timex.h
+++ b/arch/arm/include/asm/timex.h
@@ -13,7 +13,7 @@ typedef unsigned long cycles_t;
 // Temporary workaround until timex.h is cleaned up
 bool delay_read_timer(unsigned long *t);
 
-#define get_cycles()	({ cycles_t c; delay_read_timer(&c) ? 0 : c; })
+#define get_cycles()	({ cycles_t c; delay_read_timer(&c) ? c : 0; })
 #define random_get_entropy() (((unsigned long)get_cycles()) ?: random_get_entropy_fallback())
 
 #endif

---
base-commit: bd5f485f3f026225b86573e559af0b7254ef4184
change-id: 20260820-b4-arm-get-cycles-474449adcca1

Best regards,
-- 
Ryan Chen <ryan_chen at aspeedtech.com>




More information about the linux-arm-kernel mailing list