From: Matthew Dillon Date: Sat, 13 Oct 2012 17:11:43 +0000 (-0700) Subject: kernel - Fix sysclock_t comparison in usched code X-Git-Tag: v3.4.0rc~993^2 X-Git-Url: https://gitweb.dragonflybsd.org/dragonfly.git/commitdiff_plain/68a23beee83b69821e0e19230f87377e37dead9c?ds=sidebyside kernel - Fix sysclock_t comparison in usched code * Fix a sysclock_t comparison that was attempting to detect an overflow by checking if an unsigned field was negative. The field has to be cast to signed for the test to work as expected. Reported-by: enjolras --- diff --git a/sys/kern/usched_bsd4.c b/sys/kern/usched_bsd4.c index 37b2c01396..1dc67e663f 100644 --- a/sys/kern/usched_bsd4.c +++ b/sys/kern/usched_bsd4.c @@ -1024,7 +1024,7 @@ bsd4_recalculate_estcpu(struct lwp *lp) */ ttlticks = (cpbase - lp->lwp_cpbase) / gd->gd_schedclock.periodic; - if (ttlticks < 0) { + if ((ssysclock_t)ttlticks < 0) { ttlticks = 0; lp->lwp_cpbase = cpbase; } diff --git a/sys/kern/usched_dfly.c b/sys/kern/usched_dfly.c index 96b5ccf884..4fbe1535f6 100644 --- a/sys/kern/usched_dfly.c +++ b/sys/kern/usched_dfly.c @@ -928,7 +928,7 @@ dfly_recalculate_estcpu(struct lwp *lp) */ ttlticks = (cpbase - lp->lwp_cpbase) / gd->gd_schedclock.periodic; - if (ttlticks < 0) { + if ((ssysclock_t)ttlticks < 0) { ttlticks = 0; lp->lwp_cpbase = cpbase; } diff --git a/sys/sys/systimer.h b/sys/sys/systimer.h index 9c3bc1699c..eb6e5c5488 100644 --- a/sys/sys/systimer.h +++ b/sys/sys/systimer.h @@ -57,6 +57,7 @@ typedef __boolean_t boolean_t; struct intrframe; typedef __uint32_t sysclock_t; +typedef int32_t ssysclock_t; typedef TAILQ_HEAD(systimerq, systimer) *systimerq_t; typedef void (*systimer_func_t)(struct systimer *, int, struct intrframe *);