Commit dc50a06d authored by Gustavo F. Padovan's avatar Gustavo F. Padovan

Bluetooth: Merge l2cap_chan_create() in the l2cap_sock_alloc()

As a first step to remove l2cap_sock_alloc() and l2cap_sock_init() from
l2cap_core.c
Signed-off-by: default avatarGustavo F. Padovan <padovan@profusion.mobi>
parent 448f2627
...@@ -846,13 +846,7 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn) ...@@ -846,13 +846,7 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn)
if (!sk) if (!sk)
goto clean; goto clean;
chan = l2cap_chan_create(sk); chan = l2cap_pi(sk)->chan;
if (!chan) {
l2cap_sock_kill(sk);
goto clean;
}
l2cap_pi(sk)->chan = chan;
write_lock_bh(&conn->chan_lock); write_lock_bh(&conn->chan_lock);
...@@ -2339,14 +2333,6 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd ...@@ -2339,14 +2333,6 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd
if (!sk) if (!sk)
goto response; goto response;
chan = l2cap_chan_create(sk);
if (!chan) {
l2cap_sock_kill(sk);
goto response;
}
l2cap_pi(sk)->chan = chan;
write_lock_bh(&conn->chan_lock); write_lock_bh(&conn->chan_lock);
/* Check if we already have channel with that dcid */ /* Check if we already have channel with that dcid */
...@@ -2359,6 +2345,8 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd ...@@ -2359,6 +2345,8 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd
hci_conn_hold(conn->hcon); hci_conn_hold(conn->hcon);
chan = l2cap_pi(sk)->chan;
l2cap_sock_init(sk, parent); l2cap_sock_init(sk, parent);
bacpy(&bt_sk(sk)->src, conn->src); bacpy(&bt_sk(sk)->src, conn->src);
bacpy(&bt_sk(sk)->dst, conn->dst); bacpy(&bt_sk(sk)->dst, conn->dst);
......
...@@ -853,6 +853,7 @@ static struct proto l2cap_proto = { ...@@ -853,6 +853,7 @@ static struct proto l2cap_proto = {
struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, int proto, gfp_t prio) struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, int proto, gfp_t prio)
{ {
struct sock *sk; struct sock *sk;
struct l2cap_chan *chan;
sk = sk_alloc(net, PF_BLUETOOTH, prio, &l2cap_proto); sk = sk_alloc(net, PF_BLUETOOTH, prio, &l2cap_proto);
if (!sk) if (!sk)
...@@ -869,6 +870,14 @@ struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, int proto, g ...@@ -869,6 +870,14 @@ struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, int proto, g
sk->sk_protocol = proto; sk->sk_protocol = proto;
sk->sk_state = BT_OPEN; sk->sk_state = BT_OPEN;
chan = l2cap_chan_create(sk);
if (!chan) {
l2cap_sock_kill(sk);
return NULL;
}
l2cap_pi(sk)->chan = chan;
return sk; return sk;
} }
...@@ -876,7 +885,6 @@ static int l2cap_sock_create(struct net *net, struct socket *sock, int protocol, ...@@ -876,7 +885,6 @@ static int l2cap_sock_create(struct net *net, struct socket *sock, int protocol,
int kern) int kern)
{ {
struct sock *sk; struct sock *sk;
struct l2cap_chan *chan;
BT_DBG("sock %p", sock); BT_DBG("sock %p", sock);
...@@ -895,14 +903,6 @@ static int l2cap_sock_create(struct net *net, struct socket *sock, int protocol, ...@@ -895,14 +903,6 @@ static int l2cap_sock_create(struct net *net, struct socket *sock, int protocol,
if (!sk) if (!sk)
return -ENOMEM; return -ENOMEM;
chan = l2cap_chan_create(sk);
if (!chan) {
l2cap_sock_kill(sk);
return -ENOMEM;
}
l2cap_pi(sk)->chan = chan;
l2cap_sock_init(sk, NULL); l2cap_sock_init(sk, NULL);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment