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

Bluetooth: Consolidate code around sk_alloc into a helper function

This consolidates code around sk_alloc into bt_sock_alloc which does
take care of common initialization.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

+32 -54
+2
include/net/bluetooth/bluetooth.h
··· 400 400 void bt_sock_unregister(int proto); 401 401 void bt_sock_link(struct bt_sock_list *l, struct sock *s); 402 402 void bt_sock_unlink(struct bt_sock_list *l, struct sock *s); 403 + struct sock *bt_sock_alloc(struct net *net, struct socket *sock, 404 + struct proto *prot, int proto, gfp_t prio, int kern); 403 405 int bt_sock_recvmsg(struct socket *sock, struct msghdr *msg, size_t len, 404 406 int flags); 405 407 int bt_sock_stream_recvmsg(struct socket *sock, struct msghdr *msg,
+21
net/bluetooth/af_bluetooth.c
··· 140 140 return err; 141 141 } 142 142 143 + struct sock *bt_sock_alloc(struct net *net, struct socket *sock, 144 + struct proto *prot, int proto, gfp_t prio, int kern) 145 + { 146 + struct sock *sk; 147 + 148 + sk = sk_alloc(net, PF_BLUETOOTH, prio, prot, kern); 149 + if (!sk) 150 + return NULL; 151 + 152 + sock_init_data(sock, sk); 153 + INIT_LIST_HEAD(&bt_sk(sk)->accept_q); 154 + 155 + sock_reset_flag(sk, SOCK_ZAPPED); 156 + 157 + sk->sk_protocol = proto; 158 + sk->sk_state = BT_OPEN; 159 + 160 + return sk; 161 + } 162 + EXPORT_SYMBOL(bt_sock_alloc); 163 + 143 164 void bt_sock_link(struct bt_sock_list *l, struct sock *sk) 144 165 { 145 166 write_lock(&l->lock);
+1 -9
net/bluetooth/bnep/sock.c
··· 205 205 if (sock->type != SOCK_RAW) 206 206 return -ESOCKTNOSUPPORT; 207 207 208 - sk = sk_alloc(net, PF_BLUETOOTH, GFP_ATOMIC, &bnep_proto, kern); 208 + sk = bt_sock_alloc(net, sock, &bnep_proto, protocol, GFP_ATOMIC, kern); 209 209 if (!sk) 210 210 return -ENOMEM; 211 211 212 - sock_init_data(sock, sk); 213 - 214 212 sock->ops = &bnep_sock_ops; 215 - 216 213 sock->state = SS_UNCONNECTED; 217 - 218 - sock_reset_flag(sk, SOCK_ZAPPED); 219 - 220 - sk->sk_protocol = protocol; 221 - sk->sk_state = BT_OPEN; 222 214 223 215 bt_sock_link(&bnep_sk_list, sk); 224 216 return 0;
+2 -8
net/bluetooth/hci_sock.c
··· 2143 2143 2144 2144 sock->ops = &hci_sock_ops; 2145 2145 2146 - sk = sk_alloc(net, PF_BLUETOOTH, GFP_ATOMIC, &hci_sk_proto, kern); 2146 + sk = bt_sock_alloc(net, sock, &hci_sk_proto, protocol, GFP_ATOMIC, 2147 + kern); 2147 2148 if (!sk) 2148 2149 return -ENOMEM; 2149 2150 2150 - sock_init_data(sock, sk); 2151 - 2152 - sock_reset_flag(sk, SOCK_ZAPPED); 2153 - 2154 - sk->sk_protocol = protocol; 2155 - 2156 2151 sock->state = SS_UNCONNECTED; 2157 - sk->sk_state = BT_OPEN; 2158 2152 sk->sk_destruct = hci_sock_destruct; 2159 2153 2160 2154 bt_sock_link(&hci_sk_list, sk);
+1 -9
net/bluetooth/iso.c
··· 738 738 { 739 739 struct sock *sk; 740 740 741 - sk = sk_alloc(net, PF_BLUETOOTH, prio, &iso_proto, kern); 741 + sk = bt_sock_alloc(net, sock, &iso_proto, proto, prio, kern); 742 742 if (!sk) 743 743 return NULL; 744 744 745 - sock_init_data(sock, sk); 746 - INIT_LIST_HEAD(&bt_sk(sk)->accept_q); 747 - 748 745 sk->sk_destruct = iso_sock_destruct; 749 746 sk->sk_sndtimeo = ISO_CONN_TIMEOUT; 750 - 751 - sock_reset_flag(sk, SOCK_ZAPPED); 752 - 753 - sk->sk_protocol = proto; 754 - sk->sk_state = BT_OPEN; 755 747 756 748 /* Set address type as public as default src address is BDADDR_ANY */ 757 749 iso_pi(sk)->src_type = BDADDR_LE_PUBLIC;
+1 -9
net/bluetooth/l2cap_sock.c
··· 1858 1858 struct sock *sk; 1859 1859 struct l2cap_chan *chan; 1860 1860 1861 - sk = sk_alloc(net, PF_BLUETOOTH, prio, &l2cap_proto, kern); 1861 + sk = bt_sock_alloc(net, sock, &l2cap_proto, proto, prio, kern); 1862 1862 if (!sk) 1863 1863 return NULL; 1864 1864 1865 - sock_init_data(sock, sk); 1866 - INIT_LIST_HEAD(&bt_sk(sk)->accept_q); 1867 - 1868 1865 sk->sk_destruct = l2cap_sock_destruct; 1869 1866 sk->sk_sndtimeo = L2CAP_CONN_TIMEOUT; 1870 - 1871 - sock_reset_flag(sk, SOCK_ZAPPED); 1872 - 1873 - sk->sk_protocol = proto; 1874 - sk->sk_state = BT_OPEN; 1875 1867 1876 1868 chan = l2cap_chan_create(); 1877 1869 if (!chan) {
+3 -10
net/bluetooth/rfcomm/sock.c
··· 268 268 .obj_size = sizeof(struct rfcomm_pinfo) 269 269 }; 270 270 271 - static struct sock *rfcomm_sock_alloc(struct net *net, struct socket *sock, int proto, gfp_t prio, int kern) 271 + static struct sock *rfcomm_sock_alloc(struct net *net, struct socket *sock, 272 + int proto, gfp_t prio, int kern) 272 273 { 273 274 struct rfcomm_dlc *d; 274 275 struct sock *sk; 275 276 276 - sk = sk_alloc(net, PF_BLUETOOTH, prio, &rfcomm_proto, kern); 277 + sk = bt_sock_alloc(net, sock, &rfcomm_proto, proto, prio, kern); 277 278 if (!sk) 278 279 return NULL; 279 - 280 - sock_init_data(sock, sk); 281 - INIT_LIST_HEAD(&bt_sk(sk)->accept_q); 282 280 283 281 d = rfcomm_dlc_alloc(prio); 284 282 if (!d) { ··· 295 297 296 298 sk->sk_sndbuf = RFCOMM_MAX_CREDITS * RFCOMM_DEFAULT_MTU * 10; 297 299 sk->sk_rcvbuf = RFCOMM_MAX_CREDITS * RFCOMM_DEFAULT_MTU * 10; 298 - 299 - sock_reset_flag(sk, SOCK_ZAPPED); 300 - 301 - sk->sk_protocol = proto; 302 - sk->sk_state = BT_OPEN; 303 300 304 301 bt_sock_link(&rfcomm_sk_list, sk); 305 302
+1 -9
net/bluetooth/sco.c
··· 504 504 { 505 505 struct sock *sk; 506 506 507 - sk = sk_alloc(net, PF_BLUETOOTH, prio, &sco_proto, kern); 507 + sk = bt_sock_alloc(net, sock, &sco_proto, proto, prio, kern); 508 508 if (!sk) 509 509 return NULL; 510 510 511 - sock_init_data(sock, sk); 512 - INIT_LIST_HEAD(&bt_sk(sk)->accept_q); 513 - 514 511 sk->sk_destruct = sco_sock_destruct; 515 512 sk->sk_sndtimeo = SCO_CONN_TIMEOUT; 516 - 517 - sock_reset_flag(sk, SOCK_ZAPPED); 518 - 519 - sk->sk_protocol = proto; 520 - sk->sk_state = BT_OPEN; 521 513 522 514 sco_pi(sk)->setting = BT_VOICE_CVSD_16BIT; 523 515 sco_pi(sk)->codec.id = BT_CODEC_CVSD;