aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-10-25 14:58:17 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-10-25 23:19:50 +0200
commit2a4af9191d25a3c5ef21f6f837d480749fc2ae5d (patch)
tree4339d97b68f694de9436f6e5af785cfc71ae39e6 /src
parentglobal: do not allow compiler to reorder is_valid or is_dead (diff)
downloadwireguard-monolithic-historical-2a4af9191d25a3c5ef21f6f837d480749fc2ae5d.tar.xz
wireguard-monolithic-historical-2a4af9191d25a3c5ef21f6f837d480749fc2ae5d.zip
ratelimiter: refcounter doesn't need to be atomic
Suggested-by: Jann Horn <jann@thejh.net>
Diffstat (limited to 'src')
-rw-r--r--src/ratelimiter.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/ratelimiter.c b/src/ratelimiter.c
index a3d334b..b3413e4 100644
--- a/src/ratelimiter.c
+++ b/src/ratelimiter.c
@@ -13,7 +13,7 @@ static struct kmem_cache *entry_cache;
static hsiphash_key_t key;
static spinlock_t table_lock = __SPIN_LOCK_UNLOCKED("ratelimiter_table_lock");
static DEFINE_MUTEX(init_lock);
-static atomic64_t refcnt = ATOMIC64_INIT(0);
+static u64 init_refcnt; /* Protected by init_lock, hence not atomic. */
static atomic_t total_entries = ATOMIC_INIT(0);
static unsigned int max_entries, table_size;
static void wg_ratelimiter_gc_entries(struct work_struct *);
@@ -155,7 +155,7 @@ err_oom:
int wg_ratelimiter_init(void)
{
mutex_lock(&init_lock);
- if (atomic64_inc_return(&refcnt) != 1)
+ if (++init_refcnt != 1)
goto out;
entry_cache = KMEM_CACHE(ratelimiter_entry, 0);
@@ -194,7 +194,7 @@ out:
err_kmemcache:
kmem_cache_destroy(entry_cache);
err:
- atomic64_dec(&refcnt);
+ --init_refcnt;
mutex_unlock(&init_lock);
return -ENOMEM;
}
@@ -202,7 +202,7 @@ err:
void wg_ratelimiter_uninit(void)
{
mutex_lock(&init_lock);
- if (atomic64_dec_if_positive(&refcnt))
+ if (!init_refcnt || --init_refcnt)
goto out;
cancel_delayed_work_sync(&gc_work);