summaryrefslogtreecommitdiffstats
path: root/src/net
diff options
context:
space:
mode:
authorMichael Brown2006-12-22 02:35:21 +0100
committerMichael Brown2006-12-22 02:35:21 +0100
commit66a7ed23cb3fbfea574b79d3ca4aed9f626c6e3f (patch)
tree614848e50f4a41f92d877ac1a4028652991fcf25 /src/net
parentibft_fill_data() prototype change. (diff)
downloadipxe-66a7ed23cb3fbfea574b79d3ca4aed9f626c6e3f.tar.gz
ipxe-66a7ed23cb3fbfea574b79d3ca4aed9f626c6e3f.tar.xz
ipxe-66a7ed23cb3fbfea574b79d3ca4aed9f626c6e3f.zip
Make start_timer() and stop_timer() robust against incorrect usage.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/retry.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/net/retry.c b/src/net/retry.c
index 0fb479522..3d9fb9899 100644
--- a/src/net/retry.c
+++ b/src/net/retry.c
@@ -64,10 +64,11 @@ static LIST_HEAD ( timers );
* be stopped and the timer's callback function will be called.
*/
void start_timer ( struct retry_timer *timer ) {
+ if ( ! timer->start )
+ list_add ( &timer->list, &timers );
timer->start = currticks();
if ( timer->timeout < MIN_TIMEOUT )
timer->timeout = MIN_TIMEOUT;
- list_add ( &timer->list, &timers );
DBG2 ( "Timer %p started\n", timer );
}
@@ -82,9 +83,14 @@ void stop_timer ( struct retry_timer *timer ) {
unsigned long old_timeout = timer->timeout;
unsigned long runtime;
+ /* If timer was already stopped, do nothing */
+ if ( ! timer->start )
+ return;
+
DBG2 ( "Timer %p stopped\n", timer );
list_del ( &timer->list );
runtime = currticks() - timer->start;
+ timer->start = 0;
/* Update timer. Variables are:
*
@@ -124,6 +130,7 @@ static void timer_expired ( struct retry_timer *timer ) {
/* Stop timer without performing RTT calculations */
DBG2 ( "Timer %p stopped on expiry\n", timer );
list_del ( &timer->list );
+ timer->start = 0;
timer->count++;
/* Back off the timeout value */