Skip to content

Commit d570d86

Browse files
Jon Paul Maloydavem330
authored andcommitted
tipc: enqueue arrived buffers in socket in separate function
The code for enqueuing arriving buffers in the function tipc_sk_rcv() contains long code lines and currently goes to two indentation levels. As a cosmetic preparaton for the next commits, we break it out into a separate function. Reviewed-by: Ying Xue <ying.xue@windriver.com> Signed-off-by: Jon Maloy <jon.maloy@ericsson.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 1186adf commit d570d86

1 file changed

Lines changed: 31 additions & 15 deletions

File tree

‎net/tipc/socket.c‎

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,6 +1764,35 @@ static int tipc_backlog_rcv(struct sock *sk, struct sk_buff *skb)
17641764
return 0;
17651765
}
17661766

1767+
/**
1768+
* tipc_sk_enqueue_skb - enqueue buffer to socket or backlog queue
1769+
* @sk: socket
1770+
* @skb: pointer to message. Set to NULL if buffer is consumed.
1771+
* @dnode: if buffer should be forwarded/returned, send to this node
1772+
*
1773+
* Caller must hold socket lock
1774+
*
1775+
* Returns TIPC_OK (0) or -tipc error code
1776+
*/
1777+
static int tipc_sk_enqueue_skb(struct sock *sk, struct sk_buff **skb)
1778+
{
1779+
unsigned int lim;
1780+
atomic_t *dcnt;
1781+
1782+
if (unlikely(!*skb))
1783+
return TIPC_OK;
1784+
if (!sock_owned_by_user(sk))
1785+
return filter_rcv(sk, skb);
1786+
dcnt = &tipc_sk(sk)->dupl_rcvcnt;
1787+
if (sk->sk_backlog.len)
1788+
atomic_set(dcnt, 0);
1789+
lim = rcvbuf_limit(sk, *skb) + atomic_read(dcnt);
1790+
if (unlikely(sk_add_backlog(sk, *skb, lim)))
1791+
return -TIPC_ERR_OVERLOAD;
1792+
*skb = NULL;
1793+
return TIPC_OK;
1794+
}
1795+
17671796
/**
17681797
* tipc_sk_rcv - handle incoming message
17691798
* @skb: buffer containing arriving message
@@ -1776,8 +1805,7 @@ int tipc_sk_rcv(struct net *net, struct sk_buff *skb)
17761805
struct tipc_net *tn;
17771806
struct sock *sk;
17781807
u32 dport = msg_destport(buf_msg(skb));
1779-
int err = TIPC_OK;
1780-
uint limit;
1808+
int err;
17811809
u32 dnode;
17821810

17831811
/* Validate destination and message */
@@ -1788,20 +1816,8 @@ int tipc_sk_rcv(struct net *net, struct sk_buff *skb)
17881816
}
17891817
sk = &tsk->sk;
17901818

1791-
/* Queue message */
17921819
spin_lock_bh(&sk->sk_lock.slock);
1793-
1794-
if (!sock_owned_by_user(sk)) {
1795-
err = filter_rcv(sk, &skb);
1796-
} else {
1797-
if (sk->sk_backlog.len == 0)
1798-
atomic_set(&tsk->dupl_rcvcnt, 0);
1799-
limit = rcvbuf_limit(sk, skb) + atomic_read(&tsk->dupl_rcvcnt);
1800-
if (likely(!sk_add_backlog(sk, skb, limit)))
1801-
skb = NULL;
1802-
else
1803-
err = -TIPC_ERR_OVERLOAD;
1804-
}
1820+
err = tipc_sk_enqueue_skb(sk, &skb);
18051821
spin_unlock_bh(&sk->sk_lock.slock);
18061822
sock_put(sk);
18071823
exit:

0 commit comments

Comments
 (0)