Преглед изворни кода

Make start_timer() and stop_timer() robust against incorrect usage.

tags/v0.9.3
Michael Brown пре 18 година
родитељ
комит
66a7ed23cb
2 измењених фајлова са 12 додато и 2 уклоњено
  1. 4
    1
      src/include/gpxe/retry.h
  2. 8
    1
      src/net/retry.c

+ 4
- 1
src/include/gpxe/retry.h Прегледај датотеку

@@ -15,7 +15,10 @@ struct retry_timer {
15 15
 	struct list_head list;
16 16
 	/** Timeout value (in ticks) */
17 17
 	unsigned long timeout;
18
-	/** Start time (in ticks) */
18
+	/** Start time (in ticks)
19
+	 *
20
+	 * A start time of zero indicates a stopped timer.
21
+	 */
19 22
 	unsigned long start;
20 23
 	/** Retry count */
21 24
 	unsigned int count;

+ 8
- 1
src/net/retry.c Прегледај датотеку

@@ -64,10 +64,11 @@ static LIST_HEAD ( timers );
64 64
  * be stopped and the timer's callback function will be called.
65 65
  */
66 66
 void start_timer ( struct retry_timer *timer ) {
67
+	if ( ! timer->start )
68
+		list_add ( &timer->list, &timers );
67 69
 	timer->start = currticks();
68 70
 	if ( timer->timeout < MIN_TIMEOUT )
69 71
 		timer->timeout = MIN_TIMEOUT;
70
-	list_add ( &timer->list, &timers );
71 72
 	DBG2 ( "Timer %p started\n", timer );
72 73
 }
73 74
 
@@ -82,9 +83,14 @@ void stop_timer ( struct retry_timer *timer ) {
82 83
 	unsigned long old_timeout = timer->timeout;
83 84
 	unsigned long runtime;
84 85
 
86
+	/* If timer was already stopped, do nothing */
87
+	if ( ! timer->start )
88
+		return;
89
+
85 90
 	DBG2 ( "Timer %p stopped\n", timer );
86 91
 	list_del ( &timer->list );
87 92
 	runtime = currticks() - timer->start;
93
+	timer->start = 0;
88 94
 
89 95
 	/* Update timer.  Variables are:
90 96
 	 *
@@ -124,6 +130,7 @@ static void timer_expired ( struct retry_timer *timer ) {
124 130
 	/* Stop timer without performing RTT calculations */
125 131
 	DBG2 ( "Timer %p stopped on expiry\n", timer );
126 132
 	list_del ( &timer->list );
133
+	timer->start = 0;
127 134
 	timer->count++;
128 135
 
129 136
 	/* Back off the timeout value */

Loading…
Откажи
Сачувај