Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

inet: factor out inet_send_prepare()

The same code is replicated verbatim in multiple places, and the next
patches will introduce an additional user for it. Factor out a
helper and use it where appropriate. No functional change intended.

Signed-off-by: Paolo Abeni <pabeni@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Paolo Abeni and committed by
David S. Miller
e4730936 2559d7c4

+14 -8
+1
include/net/inet_common.h
··· 25 25 int addr_len, int flags); 26 26 int inet_accept(struct socket *sock, struct socket *newsock, int flags, 27 27 bool kern); 28 + int inet_send_prepare(struct sock *sk); 28 29 int inet_sendmsg(struct socket *sock, struct msghdr *msg, size_t size); 29 30 ssize_t inet_sendpage(struct socket *sock, struct page *page, int offset, 30 31 size_t size, int flags);
+13 -8
net/ipv4/af_inet.c
··· 784 784 } 785 785 EXPORT_SYMBOL(inet_getname); 786 786 787 - int inet_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) 787 + int inet_send_prepare(struct sock *sk) 788 788 { 789 - struct sock *sk = sock->sk; 790 - 791 789 sock_rps_record_flow(sk); 792 790 793 791 /* We may need to bind the socket. */ 794 792 if (!inet_sk(sk)->inet_num && !sk->sk_prot->no_autobind && 795 793 inet_autobind(sk)) 794 + return -EAGAIN; 795 + 796 + return 0; 797 + } 798 + EXPORT_SYMBOL_GPL(inet_send_prepare); 799 + 800 + int inet_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) 801 + { 802 + struct sock *sk = sock->sk; 803 + 804 + if (unlikely(inet_send_prepare(sk))) 796 805 return -EAGAIN; 797 806 798 807 return sk->sk_prot->sendmsg(sk, msg, size); ··· 813 804 { 814 805 struct sock *sk = sock->sk; 815 806 816 - sock_rps_record_flow(sk); 817 - 818 - /* We may need to bind the socket. */ 819 - if (!inet_sk(sk)->inet_num && !sk->sk_prot->no_autobind && 820 - inet_autobind(sk)) 807 + if (unlikely(inet_send_prepare(sk))) 821 808 return -EAGAIN; 822 809 823 810 if (sk->sk_prot->sendpage)