Author: glebius
Date: Wed Jun 27 22:00:50 2018
New Revision: 335748
URL: https://svnweb.freebsd.org/changeset/base/335748

Log:
  Correct r335242. Use unsigned cast instead of abs(). Using abs() gives
  incorrect result when ticks has already wrapped, and are about to reach
  the cr_ticks value (cr_ticks - ticks < hz).
  
  Submitted by: bde

Modified:
  head/sys/kern/subr_counter.c

Modified: head/sys/kern/subr_counter.c
==============================================================================
--- head/sys/kern/subr_counter.c        Wed Jun 27 21:36:57 2018        
(r335747)
+++ head/sys/kern/subr_counter.c        Wed Jun 27 22:00:50 2018        
(r335748)
@@ -140,7 +140,7 @@ counter_ratecheck(struct counter_rate *cr, int64_t lim
        val = cr->cr_over;
        now = ticks;
 
-       if (abs(now - cr->cr_ticks) >= hz) {
+       if ((u_int)(now - cr->cr_ticks) >= hz) {
                /*
                 * Time to clear the structure, we are in the next second.
                 * First try unlocked read, and then proceed with atomic.
@@ -151,7 +151,7 @@ counter_ratecheck(struct counter_rate *cr, int64_t lim
                         * Check if other thread has just went through the
                         * reset sequence before us.
                         */
-                       if (abs(now - cr->cr_ticks) >= hz) {
+                       if ((u_int)(now - cr->cr_ticks) >= hz) {
                                val = counter_u64_fetch(cr->cr_rate);
                                counter_u64_zero(cr->cr_rate);
                                cr->cr_over = 0;
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to