Sfoglia il codice sorgente

[time] Report attempts to use timers before initialisation

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 7 anni fa
parent
commit
a8f80a75d2
1 ha cambiato i file con 25 aggiunte e 3 eliminazioni
  1. 25
    3
      src/core/timer.c

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

@@ -24,7 +24,6 @@
24 24
 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 25
 
26 26
 #include <string.h>
27
-#include <assert.h>
28 27
 #include <ipxe/process.h>
29 28
 #include <ipxe/console.h>
30 29
 #include <ipxe/keys.h>
@@ -42,7 +41,14 @@ static struct timer *timer;
42 41
  */
43 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 52
 	return timer->currticks();
47 53
 }
48 54
 
@@ -53,7 +59,14 @@ unsigned long currticks ( void ) {
53 59
  */
54 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 70
 	timer->udelay ( usecs );
58 71
 }
59 72
 
@@ -63,6 +76,15 @@ void udelay ( unsigned long usecs ) {
63 76
  * @v msecs		Number of milliseconds for which to delay
64 77
  */
65 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 88
 	while ( msecs-- )
67 89
 		udelay ( 1000 );
68 90
 }

Loading…
Annulla
Salva