From 6ff4688b09c90803fbaed232ea78010565082ada Mon Sep 17 00:00:00 2001 From: Mateusz Guzik Date: Fri, 7 Dec 2018 16:11:45 +0000 Subject: [PATCH] Replace hand-rolled unrefs if > 1 with refcount_release_if_not_last Sponsored by: The FreeBSD Foundation --- sys/kern/kern_jail.c | 4 +--- sys/kern/kern_loginclass.c | 4 +--- sys/kern/kern_resource.c | 6 +----- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/sys/kern/kern_jail.c b/sys/kern/kern_jail.c index 9b7b30ee441c..8bef36c319c9 100644 --- a/sys/kern/kern_jail.c +++ b/sys/kern/kern_jail.c @@ -4023,13 +4023,11 @@ prison_racct_free_locked(struct prison_racct *prr) void prison_racct_free(struct prison_racct *prr) { - int old; ASSERT_RACCT_ENABLED(); sx_assert(&allprison_lock, SA_UNLOCKED); - old = prr->prr_refcount; - if (old > 1 && atomic_cmpset_int(&prr->prr_refcount, old, old - 1)) + if (refcount_release_if_not_last(&prr->prr_refcount)) return; sx_xlock(&allprison_lock); diff --git a/sys/kern/kern_loginclass.c b/sys/kern/kern_loginclass.c index 0fce0cbabf01..e24129e5c69b 100644 --- a/sys/kern/kern_loginclass.c +++ b/sys/kern/kern_loginclass.c @@ -84,10 +84,8 @@ loginclass_hold(struct loginclass *lc) void loginclass_free(struct loginclass *lc) { - int old; - old = lc->lc_refcount; - if (old > 1 && atomic_cmpset_int(&lc->lc_refcount, old, old - 1)) + if (refcount_release_if_not_last(&lc->lc_refcount)) return; rw_wlock(&loginclasses_lock); diff --git a/sys/kern/kern_resource.c b/sys/kern/kern_resource.c index 271339e5c4c4..a48a7df8cfdb 100644 --- a/sys/kern/kern_resource.c +++ b/sys/kern/kern_resource.c @@ -1323,14 +1323,10 @@ uihold(struct uidinfo *uip) void uifree(struct uidinfo *uip) { - int old; - /* Prepare for optimal case. */ - old = uip->ui_ref; - if (old > 1 && atomic_cmpset_int(&uip->ui_ref, old, old - 1)) + if (refcount_release_if_not_last(&uip->ui_ref)) return; - /* Prepare for suboptimal case. */ rw_wlock(&uihashtbl_lock); if (refcount_release(&uip->ui_ref) == 0) { rw_wunlock(&uihashtbl_lock);