diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-11-02 06:32:03 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2016-11-02 06:32:03 +0100 |
commit | 923c05ed149c0aeba12e38aeb59212eb793a936e (patch) | |
tree | 9517afaa70d20c14318b558773e7ebd3fd015d60 | |
parent | a51f47d58a813a692698ef2a41b50313e3c2efee (diff) |
kref: elide checks
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | src/noise.c | 4 | ||||
-rw-r--r-- | src/peer.c | 8 |
2 files changed, 4 insertions, 8 deletions
diff --git a/src/noise.c b/src/noise.c index cefedee..886a1e7 100644 --- a/src/noise.c +++ b/src/noise.c @@ -98,9 +98,7 @@ void noise_keypair_put(struct noise_keypair *keypair) struct noise_keypair *noise_keypair_get(struct noise_keypair *keypair) { RCU_LOCKDEP_WARN(!rcu_read_lock_held(), "Calling noise_keypair_get without holding the RCU read lock."); - if (unlikely(!keypair)) - return NULL; - if (unlikely(!kref_get_unless_zero(&keypair->refcount))) + if (unlikely(!keypair || !kref_get_unless_zero(&keypair->refcount))) return NULL; return keypair; } @@ -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); } |