Author: jhb
Date: Thu Jan  4 22:07:58 2018
New Revision: 327562
URL: https://svnweb.freebsd.org/changeset/base/327562

Log:
  Always use atomic_fetchadd() when updating per-user accounting values.
  
  This avoids re-reading a variable after it has been updated via an
  atomic op.  It is just a cosmetic cleanup as the read value was only
  used to control a diagnostic printf that should rarely occur (if ever).
  
  Reviewed by:  kib
  Differential Revision:        https://reviews.freebsd.org/D13768

Modified:
  head/sys/kern/kern_resource.c

Modified: head/sys/kern/kern_resource.c
==============================================================================
--- head/sys/kern/kern_resource.c       Thu Jan  4 21:59:34 2018        
(r327561)
+++ head/sys/kern/kern_resource.c       Thu Jan  4 22:07:58 2018        
(r327562)
@@ -1384,18 +1384,17 @@ ui_racct_foreach(void (*callback)(struct racct *racct,
 static inline int
 chglimit(struct uidinfo *uip, long *limit, int diff, rlim_t max, const char 
*name)
 {
+       long new;
 
        /* Don't allow them to exceed max, but allow subtraction. */
+       new = atomic_fetchadd_long(limit, (long)diff) + diff;
        if (diff > 0 && max != 0) {
-               if (atomic_fetchadd_long(limit, (long)diff) + diff > max) {
+               if (new < 0 || new > max) {
                        atomic_subtract_long(limit, (long)diff);
                        return (0);
                }
-       } else {
-               atomic_add_long(limit, (long)diff);
-               if (*limit < 0)
-                       printf("negative %s for uid = %d\n", name, uip->ui_uid);
-       }
+       } else if (new < 0)
+               printf("negative %s for uid = %d\n", name, uip->ui_uid);
        return (1);
 }
 
_______________________________________________
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