net: include/net/sock.h cleanup

bool/const conversions where possible

__inline__ -> inline

space cleanups

Signed-off-by: Eric Dumazet <edumazet@google.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
Eric Dumazet 2012-05-16 22:48:15 +00:00 committed by David S. Miller
parent 1f352920b9
commit dc6b9b7823
4 changed files with 84 additions and 87 deletions

View File

@ -97,7 +97,7 @@ void mem_cgroup_sockets_destroy(struct cgroup *cgrp)
#else #else
/* Validate arguments and do nothing */ /* Validate arguments and do nothing */
static inline __printf(2, 3) static inline __printf(2, 3)
void SOCK_DEBUG(struct sock *sk, const char *msg, ...) void SOCK_DEBUG(const struct sock *sk, const char *msg, ...)
{ {
} }
#endif #endif
@ -454,40 +454,40 @@ static inline struct sock *sk_nulls_next(const struct sock *sk)
NULL; NULL;
} }
static inline int sk_unhashed(const struct sock *sk) static inline bool sk_unhashed(const struct sock *sk)
{ {
return hlist_unhashed(&sk->sk_node); return hlist_unhashed(&sk->sk_node);
} }
static inline int sk_hashed(const struct sock *sk) static inline bool sk_hashed(const struct sock *sk)
{ {
return !sk_unhashed(sk); return !sk_unhashed(sk);
} }
static __inline__ void sk_node_init(struct hlist_node *node) static inline void sk_node_init(struct hlist_node *node)
{ {
node->pprev = NULL; node->pprev = NULL;
} }
static __inline__ void sk_nulls_node_init(struct hlist_nulls_node *node) static inline void sk_nulls_node_init(struct hlist_nulls_node *node)
{ {
node->pprev = NULL; node->pprev = NULL;
} }
static __inline__ void __sk_del_node(struct sock *sk) static inline void __sk_del_node(struct sock *sk)
{ {
__hlist_del(&sk->sk_node); __hlist_del(&sk->sk_node);
} }
/* NB: equivalent to hlist_del_init_rcu */ /* NB: equivalent to hlist_del_init_rcu */
static __inline__ int __sk_del_node_init(struct sock *sk) static inline bool __sk_del_node_init(struct sock *sk)
{ {
if (sk_hashed(sk)) { if (sk_hashed(sk)) {
__sk_del_node(sk); __sk_del_node(sk);
sk_node_init(&sk->sk_node); sk_node_init(&sk->sk_node);
return 1; return true;
} }
return 0; return false;
} }
/* Grab socket reference count. This operation is valid only /* Grab socket reference count. This operation is valid only
@ -509,9 +509,9 @@ static inline void __sock_put(struct sock *sk)
atomic_dec(&sk->sk_refcnt); atomic_dec(&sk->sk_refcnt);
} }
static __inline__ int sk_del_node_init(struct sock *sk) static inline bool sk_del_node_init(struct sock *sk)
{ {
int rc = __sk_del_node_init(sk); bool rc = __sk_del_node_init(sk);
if (rc) { if (rc) {
/* paranoid for a while -acme */ /* paranoid for a while -acme */
@ -522,18 +522,18 @@ static __inline__ int sk_del_node_init(struct sock *sk)
} }
#define sk_del_node_init_rcu(sk) sk_del_node_init(sk) #define sk_del_node_init_rcu(sk) sk_del_node_init(sk)
static __inline__ int __sk_nulls_del_node_init_rcu(struct sock *sk) static inline bool __sk_nulls_del_node_init_rcu(struct sock *sk)
{ {
if (sk_hashed(sk)) { if (sk_hashed(sk)) {
hlist_nulls_del_init_rcu(&sk->sk_nulls_node); hlist_nulls_del_init_rcu(&sk->sk_nulls_node);
return 1; return true;
} }
return 0; return false;
} }
static __inline__ int sk_nulls_del_node_init_rcu(struct sock *sk) static inline bool sk_nulls_del_node_init_rcu(struct sock *sk)
{ {
int rc = __sk_nulls_del_node_init_rcu(sk); bool rc = __sk_nulls_del_node_init_rcu(sk);
if (rc) { if (rc) {
/* paranoid for a while -acme */ /* paranoid for a while -acme */
@ -543,40 +543,40 @@ static __inline__ int sk_nulls_del_node_init_rcu(struct sock *sk)
return rc; return rc;
} }
static __inline__ void __sk_add_node(struct sock *sk, struct hlist_head *list) static inline void __sk_add_node(struct sock *sk, struct hlist_head *list)
{ {
hlist_add_head(&sk->sk_node, list); hlist_add_head(&sk->sk_node, list);
} }
static __inline__ void sk_add_node(struct sock *sk, struct hlist_head *list) static inline void sk_add_node(struct sock *sk, struct hlist_head *list)
{ {
sock_hold(sk); sock_hold(sk);
__sk_add_node(sk, list); __sk_add_node(sk, list);
} }
static __inline__ void sk_add_node_rcu(struct sock *sk, struct hlist_head *list) static inline void sk_add_node_rcu(struct sock *sk, struct hlist_head *list)
{ {
sock_hold(sk); sock_hold(sk);
hlist_add_head_rcu(&sk->sk_node, list); hlist_add_head_rcu(&sk->sk_node, list);
} }
static __inline__ void __sk_nulls_add_node_rcu(struct sock *sk, struct hlist_nulls_head *list) static inline void __sk_nulls_add_node_rcu(struct sock *sk, struct hlist_nulls_head *list)
{ {
hlist_nulls_add_head_rcu(&sk->sk_nulls_node, list); hlist_nulls_add_head_rcu(&sk->sk_nulls_node, list);
} }
static __inline__ void sk_nulls_add_node_rcu(struct sock *sk, struct hlist_nulls_head *list) static inline void sk_nulls_add_node_rcu(struct sock *sk, struct hlist_nulls_head *list)
{ {
sock_hold(sk); sock_hold(sk);
__sk_nulls_add_node_rcu(sk, list); __sk_nulls_add_node_rcu(sk, list);
} }
static __inline__ void __sk_del_bind_node(struct sock *sk) static inline void __sk_del_bind_node(struct sock *sk)
{ {
__hlist_del(&sk->sk_bind_node); __hlist_del(&sk->sk_bind_node);
} }
static __inline__ void sk_add_bind_node(struct sock *sk, static inline void sk_add_bind_node(struct sock *sk,
struct hlist_head *list) struct hlist_head *list)
{ {
hlist_add_head(&sk->sk_bind_node, list); hlist_add_head(&sk->sk_bind_node, list);
@ -665,7 +665,7 @@ static inline void sk_acceptq_added(struct sock *sk)
sk->sk_ack_backlog++; sk->sk_ack_backlog++;
} }
static inline int sk_acceptq_is_full(struct sock *sk) static inline bool sk_acceptq_is_full(const struct sock *sk)
{ {
return sk->sk_ack_backlog > sk->sk_max_ack_backlog; return sk->sk_ack_backlog > sk->sk_max_ack_backlog;
} }
@ -673,19 +673,19 @@ static inline int sk_acceptq_is_full(struct sock *sk)
/* /*
* Compute minimal free write space needed to queue new packets. * Compute minimal free write space needed to queue new packets.
*/ */
static inline int sk_stream_min_wspace(struct sock *sk) static inline int sk_stream_min_wspace(const struct sock *sk)
{ {
return sk->sk_wmem_queued >> 1; return sk->sk_wmem_queued >> 1;
} }
static inline int sk_stream_wspace(struct sock *sk) static inline int sk_stream_wspace(const struct sock *sk)
{ {
return sk->sk_sndbuf - sk->sk_wmem_queued; return sk->sk_sndbuf - sk->sk_wmem_queued;
} }
extern void sk_stream_write_space(struct sock *sk); extern void sk_stream_write_space(struct sock *sk);
static inline int sk_stream_memory_free(struct sock *sk) static inline bool sk_stream_memory_free(const struct sock *sk)
{ {
return sk->sk_wmem_queued < sk->sk_sndbuf; return sk->sk_wmem_queued < sk->sk_sndbuf;
} }
@ -1173,7 +1173,7 @@ proto_memory_pressure(struct proto *prot)
extern void sock_prot_inuse_add(struct net *net, struct proto *prot, int inc); extern void sock_prot_inuse_add(struct net *net, struct proto *prot, int inc);
extern int sock_prot_inuse_get(struct net *net, struct proto *proto); extern int sock_prot_inuse_get(struct net *net, struct proto *proto);
#else #else
static void inline sock_prot_inuse_add(struct net *net, struct proto *prot, static inline void sock_prot_inuse_add(struct net *net, struct proto *prot,
int inc) int inc)
{ {
} }
@ -1260,24 +1260,24 @@ static inline int sk_mem_pages(int amt)
return (amt + SK_MEM_QUANTUM - 1) >> SK_MEM_QUANTUM_SHIFT; return (amt + SK_MEM_QUANTUM - 1) >> SK_MEM_QUANTUM_SHIFT;
} }
static inline int sk_has_account(struct sock *sk) static inline bool sk_has_account(struct sock *sk)
{ {
/* return true if protocol supports memory accounting */ /* return true if protocol supports memory accounting */
return !!sk->sk_prot->memory_allocated; return !!sk->sk_prot->memory_allocated;
} }
static inline int sk_wmem_schedule(struct sock *sk, int size) static inline bool sk_wmem_schedule(struct sock *sk, int size)
{ {
if (!sk_has_account(sk)) if (!sk_has_account(sk))
return 1; return true;
return size <= sk->sk_forward_alloc || return size <= sk->sk_forward_alloc ||
__sk_mem_schedule(sk, size, SK_MEM_SEND); __sk_mem_schedule(sk, size, SK_MEM_SEND);
} }
static inline int sk_rmem_schedule(struct sock *sk, int size) static inline bool sk_rmem_schedule(struct sock *sk, int size)
{ {
if (!sk_has_account(sk)) if (!sk_has_account(sk))
return 1; return true;
return size <= sk->sk_forward_alloc || return size <= sk->sk_forward_alloc ||
__sk_mem_schedule(sk, size, SK_MEM_RECV); __sk_mem_schedule(sk, size, SK_MEM_RECV);
} }
@ -1690,7 +1690,7 @@ extern struct dst_entry *__sk_dst_check(struct sock *sk, u32 cookie);
extern struct dst_entry *sk_dst_check(struct sock *sk, u32 cookie); extern struct dst_entry *sk_dst_check(struct sock *sk, u32 cookie);
static inline int sk_can_gso(const struct sock *sk) static inline bool sk_can_gso(const struct sock *sk)
{ {
return net_gso_ok(sk->sk_route_caps, sk->sk_gso_type); return net_gso_ok(sk->sk_route_caps, sk->sk_gso_type);
} }
@ -1807,7 +1807,7 @@ static inline int sk_rmem_alloc_get(const struct sock *sk)
* *
* Returns true if socket has write or read allocations * Returns true if socket has write or read allocations
*/ */
static inline int sk_has_allocations(const struct sock *sk) static inline bool sk_has_allocations(const struct sock *sk)
{ {
return sk_wmem_alloc_get(sk) || sk_rmem_alloc_get(sk); return sk_wmem_alloc_get(sk) || sk_rmem_alloc_get(sk);
} }
@ -1846,9 +1846,7 @@ static inline int sk_has_allocations(const struct sock *sk)
*/ */
static inline bool wq_has_sleeper(struct socket_wq *wq) static inline bool wq_has_sleeper(struct socket_wq *wq)
{ {
/* We need to be sure we are in sync with the
/*
* We need to be sure we are in sync with the
* add_wait_queue modifications to the wait queue. * add_wait_queue modifications to the wait queue.
* *
* This memory barrier is paired in the sock_poll_wait. * This memory barrier is paired in the sock_poll_wait.
@ -1870,8 +1868,7 @@ static inline void sock_poll_wait(struct file *filp,
{ {
if (!poll_does_not_wait(p) && wait_address) { if (!poll_does_not_wait(p) && wait_address) {
poll_wait(filp, wait_address, p); poll_wait(filp, wait_address, p);
/* /* We need to be sure we are in sync with the
* We need to be sure we are in sync with the
* socket flags modification. * socket flags modification.
* *
* This memory barrier is paired in the wq_has_sleeper. * This memory barrier is paired in the wq_has_sleeper.
@ -1983,7 +1980,7 @@ static inline struct page *sk_stream_alloc_page(struct sock *sk)
/* /*
* Default write policy as shown to user space via poll/select/SIGIO * Default write policy as shown to user space via poll/select/SIGIO
*/ */
static inline int sock_writeable(const struct sock *sk) static inline bool sock_writeable(const struct sock *sk)
{ {
return atomic_read(&sk->sk_wmem_alloc) < (sk->sk_sndbuf >> 1); return atomic_read(&sk->sk_wmem_alloc) < (sk->sk_sndbuf >> 1);
} }
@ -1993,12 +1990,12 @@ static inline gfp_t gfp_any(void)
return in_softirq() ? GFP_ATOMIC : GFP_KERNEL; return in_softirq() ? GFP_ATOMIC : GFP_KERNEL;
} }
static inline long sock_rcvtimeo(const struct sock *sk, int noblock) static inline long sock_rcvtimeo(const struct sock *sk, bool noblock)
{ {
return noblock ? 0 : sk->sk_rcvtimeo; return noblock ? 0 : sk->sk_rcvtimeo;
} }
static inline long sock_sndtimeo(const struct sock *sk, int noblock) static inline long sock_sndtimeo(const struct sock *sk, bool noblock)
{ {
return noblock ? 0 : sk->sk_sndtimeo; return noblock ? 0 : sk->sk_sndtimeo;
} }
@ -2021,7 +2018,7 @@ extern void __sock_recv_timestamp(struct msghdr *msg, struct sock *sk,
extern void __sock_recv_wifi_status(struct msghdr *msg, struct sock *sk, extern void __sock_recv_wifi_status(struct msghdr *msg, struct sock *sk,
struct sk_buff *skb); struct sk_buff *skb);
static __inline__ void static inline void
sock_recv_timestamp(struct msghdr *msg, struct sock *sk, struct sk_buff *skb) sock_recv_timestamp(struct msghdr *msg, struct sock *sk, struct sk_buff *skb)
{ {
ktime_t kt = skb->tstamp; ktime_t kt = skb->tstamp;
@ -2091,7 +2088,7 @@ extern int sock_tx_timestamp(struct sock *sk, __u8 *tx_flags);
* locked so that the sk_buff queue operation is ok. * locked so that the sk_buff queue operation is ok.
*/ */
#ifdef CONFIG_NET_DMA #ifdef CONFIG_NET_DMA
static inline void sk_eat_skb(struct sock *sk, struct sk_buff *skb, int copied_early) static inline void sk_eat_skb(struct sock *sk, struct sk_buff *skb, bool copied_early)
{ {
__skb_unlink(skb, &sk->sk_receive_queue); __skb_unlink(skb, &sk->sk_receive_queue);
if (!copied_early) if (!copied_early)
@ -2100,7 +2097,7 @@ static inline void sk_eat_skb(struct sock *sk, struct sk_buff *skb, int copied_e
__skb_queue_tail(&sk->sk_async_wait_queue, skb); __skb_queue_tail(&sk->sk_async_wait_queue, skb);
} }
#else #else
static inline void sk_eat_skb(struct sock *sk, struct sk_buff *skb, int copied_early) static inline void sk_eat_skb(struct sock *sk, struct sk_buff *skb, bool copied_early)
{ {
__skb_unlink(skb, &sk->sk_receive_queue); __skb_unlink(skb, &sk->sk_receive_queue);
__kfree_skb(skb); __kfree_skb(skb);

View File

@ -848,7 +848,7 @@ int dccp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
default: default:
dccp_pr_debug("packet_type=%s\n", dccp_pr_debug("packet_type=%s\n",
dccp_packet_name(dh->dccph_type)); dccp_packet_name(dh->dccph_type));
sk_eat_skb(sk, skb, 0); sk_eat_skb(sk, skb, false);
} }
verify_sock_status: verify_sock_status:
if (sock_flag(sk, SOCK_DONE)) { if (sock_flag(sk, SOCK_DONE)) {
@ -905,7 +905,7 @@ verify_sock_status:
len = skb->len; len = skb->len;
found_fin_ok: found_fin_ok:
if (!(flags & MSG_PEEK)) if (!(flags & MSG_PEEK))
sk_eat_skb(sk, skb, 0); sk_eat_skb(sk, skb, false);
break; break;
} while (1); } while (1);
out: out:

View File

@ -1473,11 +1473,11 @@ int tcp_read_sock(struct sock *sk, read_descriptor_t *desc,
break; break;
} }
if (tcp_hdr(skb)->fin) { if (tcp_hdr(skb)->fin) {
sk_eat_skb(sk, skb, 0); sk_eat_skb(sk, skb, false);
++seq; ++seq;
break; break;
} }
sk_eat_skb(sk, skb, 0); sk_eat_skb(sk, skb, false);
if (!desc->count) if (!desc->count)
break; break;
tp->copied_seq = seq; tp->copied_seq = seq;
@ -1513,7 +1513,7 @@ int tcp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
int target; /* Read at least this many bytes */ int target; /* Read at least this many bytes */
long timeo; long timeo;
struct task_struct *user_recv = NULL; struct task_struct *user_recv = NULL;
int copied_early = 0; bool copied_early = false;
struct sk_buff *skb; struct sk_buff *skb;
u32 urg_hole = 0; u32 urg_hole = 0;
@ -1801,7 +1801,7 @@ do_prequeue:
dma_async_memcpy_issue_pending(tp->ucopy.dma_chan); dma_async_memcpy_issue_pending(tp->ucopy.dma_chan);
if ((offset + used) == skb->len) if ((offset + used) == skb->len)
copied_early = 1; copied_early = true;
} else } else
#endif #endif
@ -1835,7 +1835,7 @@ skip_copy:
goto found_fin_ok; goto found_fin_ok;
if (!(flags & MSG_PEEK)) { if (!(flags & MSG_PEEK)) {
sk_eat_skb(sk, skb, copied_early); sk_eat_skb(sk, skb, copied_early);
copied_early = 0; copied_early = false;
} }
continue; continue;
@ -1844,7 +1844,7 @@ skip_copy:
++*seq; ++*seq;
if (!(flags & MSG_PEEK)) { if (!(flags & MSG_PEEK)) {
sk_eat_skb(sk, skb, copied_early); sk_eat_skb(sk, skb, copied_early);
copied_early = 0; copied_early = false;
} }
break; break;
} while (len > 0); } while (len > 0);

View File

@ -838,7 +838,7 @@ static int llc_ui_recvmsg(struct kiocb *iocb, struct socket *sock,
if (!(flags & MSG_PEEK)) { if (!(flags & MSG_PEEK)) {
spin_lock_irqsave(&sk->sk_receive_queue.lock, cpu_flags); spin_lock_irqsave(&sk->sk_receive_queue.lock, cpu_flags);
sk_eat_skb(sk, skb, 0); sk_eat_skb(sk, skb, false);
spin_unlock_irqrestore(&sk->sk_receive_queue.lock, cpu_flags); spin_unlock_irqrestore(&sk->sk_receive_queue.lock, cpu_flags);
*seq = 0; *seq = 0;
} }
@ -861,7 +861,7 @@ copy_uaddr:
if (!(flags & MSG_PEEK)) { if (!(flags & MSG_PEEK)) {
spin_lock_irqsave(&sk->sk_receive_queue.lock, cpu_flags); spin_lock_irqsave(&sk->sk_receive_queue.lock, cpu_flags);
sk_eat_skb(sk, skb, 0); sk_eat_skb(sk, skb, false);
spin_unlock_irqrestore(&sk->sk_receive_queue.lock, cpu_flags); spin_unlock_irqrestore(&sk->sk_receive_queue.lock, cpu_flags);
*seq = 0; *seq = 0;
} }