From: Hauke Mehrtens Date: Wed, 1 Aug 2012 23:05:24 +0000 (+0200) Subject: compat: add sk_wmem_alloc_get and sk_has_allocations X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=656d3e6e6b3bfc014b0610031f7e3b0a53da6eb8;p=openwrt%2Fstaging%2Fblogic.git compat: add sk_wmem_alloc_get and sk_has_allocations These functions are copied from the kernel. Signed-off-by: Hauke Mehrtens Signed-off-by: Luis R. Rodriguez --- diff --git a/include/linux/compat-2.6.31.h b/include/linux/compat-2.6.31.h index 25db973dff99..347ae26d14be 100644 --- a/include/linux/compat-2.6.31.h +++ b/include/linux/compat-2.6.31.h @@ -11,6 +11,7 @@ #include #include #include +#include /* * These macros allow us to backport rfkill without any @@ -215,6 +216,39 @@ extern long long atomic64_add_return(long long a, atomic64_t *v); #endif +/** + * sk_rmem_alloc_get - returns read allocations + * @sk: socket + * + * Returns sk_rmem_alloc + */ +static inline int sk_rmem_alloc_get(const struct sock *sk) +{ + return atomic_read(&sk->sk_rmem_alloc); +} + +/** + * sk_wmem_alloc_get - returns write allocations + * @sk: socket + * + * Returns sk_wmem_alloc minus initial offset of one + */ +static inline int sk_wmem_alloc_get(const struct sock *sk) +{ + return atomic_read(&sk->sk_wmem_alloc) - 1; +} + +/** + * sk_has_allocations - check if allocations are outstanding + * @sk: socket + * + * Returns true if socket has write or read allocations + */ +static inline bool sk_has_allocations(const struct sock *sk) +{ + return sk_wmem_alloc_get(sk) || sk_rmem_alloc_get(sk); +} + #endif /* (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,31)) */