diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-07-31 07:03:07 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-07-31 07:19:52 +0200 |
commit | 488b7dcba7a5dcf5d65349992c7fc32b3d9c17d1 (patch) | |
tree | 847677cfc90dee98bfe86d64a991f3ff0d8f428d /src/netlink.c | |
parent | 0c942d003c4291fe05d0de296ac040c7b0d0503c (diff) |
peer: simplify rcu reference counts
Use RCU reference counts only when we must, and otherwise use a more
reasonably named function.
Reported-by: Jann Horn <jann@thejh.net>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/netlink.c')
-rw-r--r-- | src/netlink.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/src/netlink.c b/src/netlink.c index aef743f..90c7aa2 100644 --- a/src/netlink.c +++ b/src/netlink.c @@ -221,8 +221,8 @@ static int get_device_dump(struct sk_buff *skb, struct netlink_callback *cb) out: peer_put(last_peer_cursor); - if (!ret && !done) - next_peer_cursor = peer_rcu_get(next_peer_cursor); + if (!ret && !done && next_peer_cursor) + peer_get(next_peer_cursor); mutex_unlock(&wg->device_update_lock); rtnl_unlock(); @@ -326,9 +326,11 @@ static int set_peer(struct wireguard_device *wg, struct nlattr **attrs) up_read(&wg->static_identity.lock); ret = -ENOMEM; - peer = peer_rcu_get(peer_create(wg, public_key, preshared_key)); + peer = peer_create(wg, public_key, preshared_key); if (!peer) goto out; + /* Take additional reference, as though we've just been looked up. */ + peer_get(peer); } ret = 0; |