summaryrefslogtreecommitdiffhomepage
path: root/src/peer.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2016-11-02 06:32:03 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2016-11-02 06:32:03 +0100
commit923c05ed149c0aeba12e38aeb59212eb793a936e (patch)
tree9517afaa70d20c14318b558773e7ebd3fd015d60 /src/peer.c
parenta51f47d58a813a692698ef2a41b50313e3c2efee (diff)
kref: elide checks
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/peer.c')
-rw-r--r--src/peer.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/src/peer.c b/src/peer.c
index 6e6ccda..aa630a4 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -44,16 +44,14 @@ struct wireguard_peer *peer_create(struct wireguard_device *wg, const u8 public_
struct wireguard_peer *peer_get(struct wireguard_peer *peer)
{
RCU_LOCKDEP_WARN(!rcu_read_lock_held(), "Calling peer_get without holding the RCU read lock.");
- if (unlikely(!peer))
- return NULL;
- if (unlikely(!kref_get_unless_zero(&peer->refcount)))
+ if (unlikely(!peer || !kref_get_unless_zero(&peer->refcount)))
return NULL;
return peer;
}
void peer_remove(struct wireguard_peer *peer)
{
- if (!peer)
+ if (unlikely(!peer))
return;
lockdep_assert_held(&peer->device->device_update_lock);
@@ -88,7 +86,7 @@ static void kref_release(struct kref *refcount)
void peer_put(struct wireguard_peer *peer)
{
- if (!peer)
+ if (unlikely(!peer))
return;
kref_put(&peer->refcount, kref_release);
}