From d6fc869ebdcb33da81bdfc501d962bc255921778 Mon Sep 17 00:00:00 2001 From: Andriy Gapon Date: Tue, 9 Jul 2013 09:01:44 +0000 Subject: [PATCH] should_yield: protect from td_swvoltick being uninitialized or too stale The distance between ticks and td_swvoltick should be calculated as an unsigned number. Previously we could end up comparing a negative number with hogticks in which case should_yield() would give incorrect answer. We should probably ensure that td_swvoltick is properly initialized. Sponsored by: HybridCluster MFC after: 5 days --- sys/kern/kern_synch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sys/kern/kern_synch.c b/sys/kern/kern_synch.c index 84b1c61e70e..fb9c9bfcf5c 100644 --- a/sys/kern/kern_synch.c +++ b/sys/kern/kern_synch.c @@ -581,7 +581,7 @@ int should_yield(void) { - return (ticks - curthread->td_swvoltick >= hogticks); + return ((unsigned int)(ticks - curthread->td_swvoltick) >= hogticks); } void