Browse Source

[time] Report attempts to use timers before initialisation

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 7 years ago
parent
commit
a8f80a75d2
1 changed files with 25 additions and 3 deletions
  1. 25
    3
      src/core/timer.c

+ 25
- 3
src/core/timer.c View File

24
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
24
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
 
25
 
26
 #include <string.h>
26
 #include <string.h>
27
-#include <assert.h>
28
 #include <ipxe/process.h>
27
 #include <ipxe/process.h>
29
 #include <ipxe/console.h>
28
 #include <ipxe/console.h>
30
 #include <ipxe/keys.h>
29
 #include <ipxe/keys.h>
42
  */
41
  */
43
 unsigned long currticks ( void ) {
42
 unsigned long currticks ( void ) {
44
 
43
 
45
-	assert ( timer != NULL );
44
+	/* Guard against use during early initialisation */
45
+	if ( ! timer ) {
46
+		DBGC ( &timer, "TIMER currticks() called before initialisation "
47
+		       "from %p\n", __builtin_return_address ( 0 ) );
48
+		return 0;
49
+	}
50
+
51
+	/* Use selected timer */
46
 	return timer->currticks();
52
 	return timer->currticks();
47
 }
53
 }
48
 
54
 
53
  */
59
  */
54
 void udelay ( unsigned long usecs ) {
60
 void udelay ( unsigned long usecs ) {
55
 
61
 
56
-	assert ( timer != NULL );
62
+	/* Guard against use during early initialisation */
63
+	if ( ! timer ) {
64
+		DBGC ( &timer, "TIMER udelay() called before initialisation "
65
+		       "from %p\n", __builtin_return_address ( 0 ) );
66
+		return;
67
+	}
68
+
69
+	/* Use selected timer */
57
 	timer->udelay ( usecs );
70
 	timer->udelay ( usecs );
58
 }
71
 }
59
 
72
 
63
  * @v msecs		Number of milliseconds for which to delay
76
  * @v msecs		Number of milliseconds for which to delay
64
  */
77
  */
65
 void mdelay ( unsigned long msecs ) {
78
 void mdelay ( unsigned long msecs ) {
79
+
80
+	/* Guard against use during early initialisation */
81
+	if ( ! timer ) {
82
+		DBGC ( &timer, "TIMER mdelay() called before initialisation "
83
+		       "from %p\n", __builtin_return_address ( 0 ) );
84
+		return;
85
+	}
86
+
87
+	/* Delay for specified number of milliseconds */
66
 	while ( msecs-- )
88
 	while ( msecs-- )
67
 		udelay ( 1000 );
89
 		udelay ( 1000 );
68
 }
90
 }

Loading…
Cancel
Save