diff options
| author | Paolo Abeni <[email protected]> | 2017-06-12 11:23:41 +0200 |
|---|---|---|
| committer | David S. Miller <[email protected]> | 2017-06-12 10:01:29 -0400 |
| commit | 3889a803e1da9bd7cd10d6504bf281ee7e55dfd6 (patch) | |
| tree | a02fdf7382352a186732bb51028ccebcdc2afde1 /include/linux/skbuff.h | |
| parent | 78d6102256fe46fcd0c78798a9391cf1f112f117 (diff) | |
net: factor out a helper to decrement the skb refcount
The same code is replicated in 3 different places; move it to a
common helper.
Signed-off-by: Paolo Abeni <[email protected]>
Acked-by: Eric Dumazet <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
Diffstat (limited to 'include/linux/skbuff.h')
| -rw-r--r-- | include/linux/skbuff.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index d460a4cbda1c..decce3655a48 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -867,6 +867,19 @@ static inline unsigned int skb_napi_id(const struct sk_buff *skb) #endif } +/* decrement the reference count and return true if we can free the skb */ +static inline bool skb_unref(struct sk_buff *skb) +{ + if (unlikely(!skb)) + return false; + if (likely(atomic_read(&skb->users) == 1)) + smp_rmb(); + else if (likely(!atomic_dec_and_test(&skb->users))) + return false; + + return true; +} + void kfree_skb(struct sk_buff *skb); void kfree_skb_list(struct sk_buff *segs); void skb_tx_error(struct sk_buff *skb); |