[PATCH] arch/arm/lib/delay.c: Add warning for unregistered delay_timer in read_current_timer()

From: stephen eta zhou
Date: Thu Feb 20 2025 - 23:38:47 EST


Hi Russell

While debugging Linux, I found that the kernel relies on the read_current_timer function when inserting canary values into the interrupt stack or generating entropy. However, if the current clock source has not called register_current_timer_delay for proper registration, read_current_timer will return an incorrect timer value. This issue is somewhat subtle, as even if read_current_timer doesn't work properly, the function that wraps it may still return 0 without triggering any warning or error.
For example, when generating entropy, rdseed might incorrectly be set to 0. Since no obvious warning or error occurs, this problem may go unnoticed, leading to calculated values that do not meet the ideal pseudorandom number requirements.
To make it easier to debug and trace this issue, I added a WARN warning in the relevant conditional checks. This helps developers more easily trace the stack, quickly locate the issue, and significantly reduce debugging time.

=======================================

From 3b3b2cc22ad9e1af0d3321aac27e09b263797c52 Mon Sep 17 00:00:00 2001
From: Stephen Eta Zhou <stephen.eta.zhou@xxxxxxxxxxx>
Date: Fri, 21 Feb 2025 11:55:18 +0800
Subject: [PATCH] arch/arm/lib/delay.c: Add warning for unregistered
 delay_timer in read_current_timer()

Added a WARN to track when delay_timer is NULL in read_current_timer.

Signed-off-by: Stephen Eta Zhou <stephen.eta.zhou@xxxxxxxxxxx>
---
 arch/arm/lib/delay.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
index b7fe84f68bf1..a15015861d25 100644
--- a/arch/arm/lib/delay.c
+++ b/arch/arm/lib/delay.c
@@ -29,8 +29,10 @@ static u64 delay_res;
 
 int read_current_timer(unsigned long *timer_val)
 {
-     if (!delay_timer)
+     if (!delay_timer) {
+           WARN(1, "Delay timer is NULL\n");
            return -ENXIO;
+     }
 
      *timer_val = delay_timer->read_current_timer();
      return 0;
-- 
2.25.1