Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/linville/wirel...
[linux-2.6.git] / net / bluetooth / l2cap_core.c
index cb3c4ed..a378acc 100644 (file)
@@ -80,8 +80,7 @@ static struct l2cap_chan *__l2cap_get_chan_by_dcid(struct l2cap_conn *conn, u16
        struct l2cap_chan *c;
 
        list_for_each_entry(c, &conn->chan_l, list) {
-               struct sock *s = c->sk;
-               if (l2cap_pi(s)->dcid == cid)
+               if (c->dcid == cid)
                        return c;
        }
        return NULL;
@@ -93,8 +92,7 @@ static struct l2cap_chan *__l2cap_get_chan_by_scid(struct l2cap_conn *conn, u16
        struct l2cap_chan *c;
 
        list_for_each_entry(c, &conn->chan_l, list) {
-               struct sock *s = c->sk;
-               if (l2cap_pi(s)->scid == cid)
+               if (c->scid == cid)
                        return c;
        }
        return NULL;
@@ -162,38 +160,43 @@ struct l2cap_chan *l2cap_chan_alloc(struct sock *sk)
        return chan;
 }
 
+void l2cap_chan_free(struct l2cap_chan *chan)
+{
+       kfree(chan);
+}
+
 static void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan)
 {
        struct sock *sk = chan->sk;
 
        BT_DBG("conn %p, psm 0x%2.2x, dcid 0x%4.4x", conn,
-                       l2cap_pi(sk)->psm, l2cap_pi(sk)->dcid);
+                       chan->psm, chan->dcid);
 
        conn->disc_reason = 0x13;
 
-       l2cap_pi(sk)->conn = conn;
+       chan->conn = conn;
 
        if (sk->sk_type == SOCK_SEQPACKET || sk->sk_type == SOCK_STREAM) {
                if (conn->hcon->type == LE_LINK) {
                        /* LE connection */
-                       l2cap_pi(sk)->omtu = L2CAP_LE_DEFAULT_MTU;
-                       l2cap_pi(sk)->scid = L2CAP_CID_LE_DATA;
-                       l2cap_pi(sk)->dcid = L2CAP_CID_LE_DATA;
+                       chan->omtu = L2CAP_LE_DEFAULT_MTU;
+                       chan->scid = L2CAP_CID_LE_DATA;
+                       chan->dcid = L2CAP_CID_LE_DATA;
                } else {
                        /* Alloc CID for connection-oriented socket */
-                       l2cap_pi(sk)->scid = l2cap_alloc_cid(conn);
-                       l2cap_pi(sk)->omtu = L2CAP_DEFAULT_MTU;
+                       chan->scid = l2cap_alloc_cid(conn);
+                       chan->omtu = L2CAP_DEFAULT_MTU;
                }
        } else if (sk->sk_type == SOCK_DGRAM) {
                /* Connectionless socket */
-               l2cap_pi(sk)->scid = L2CAP_CID_CONN_LESS;
-               l2cap_pi(sk)->dcid = L2CAP_CID_CONN_LESS;
-               l2cap_pi(sk)->omtu = L2CAP_DEFAULT_MTU;
+               chan->scid = L2CAP_CID_CONN_LESS;
+               chan->dcid = L2CAP_CID_CONN_LESS;
+               chan->omtu = L2CAP_DEFAULT_MTU;
        } else {
                /* Raw socket can send/recv signalling messages only */
-               l2cap_pi(sk)->scid = L2CAP_CID_SIGNALING;
-               l2cap_pi(sk)->dcid = L2CAP_CID_SIGNALING;
-               l2cap_pi(sk)->omtu = L2CAP_DEFAULT_MTU;
+               chan->scid = L2CAP_CID_SIGNALING;
+               chan->dcid = L2CAP_CID_SIGNALING;
+               chan->omtu = L2CAP_DEFAULT_MTU;
        }
 
        sock_hold(sk);
@@ -206,7 +209,7 @@ static void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan)
 void l2cap_chan_del(struct l2cap_chan *chan, int err)
 {
        struct sock *sk = chan->sk;
-       struct l2cap_conn *conn = l2cap_pi(sk)->conn;
+       struct l2cap_conn *conn = chan->conn;
        struct sock *parent = bt_sk(sk)->parent;
 
        l2cap_sock_clear_timer(sk);
@@ -220,7 +223,7 @@ void l2cap_chan_del(struct l2cap_chan *chan, int err)
                write_unlock_bh(&conn->chan_lock);
                __sock_put(sk);
 
-               l2cap_pi(sk)->conn = NULL;
+               chan->conn = NULL;
                hci_conn_put(conn->hcon);
        }
 
@@ -238,11 +241,11 @@ void l2cap_chan_del(struct l2cap_chan *chan, int err)
 
        if (!(chan->conf_state & L2CAP_CONF_OUTPUT_DONE &&
                        chan->conf_state & L2CAP_CONF_INPUT_DONE))
-               goto free;
+               return;
 
        skb_queue_purge(&chan->tx_q);
 
-       if (l2cap_pi(sk)->mode == L2CAP_MODE_ERTM) {
+       if (chan->mode == L2CAP_MODE_ERTM) {
                struct srej_list *l, *tmp;
 
                del_timer(&chan->retrans_timer);
@@ -257,9 +260,6 @@ void l2cap_chan_del(struct l2cap_chan *chan, int err)
                        kfree(l);
                }
        }
-
-free:
-       kfree(chan);
 }
 
 static inline u8 l2cap_get_auth_type(struct l2cap_chan *chan)
@@ -275,7 +275,7 @@ static inline u8 l2cap_get_auth_type(struct l2cap_chan *chan)
                default:
                        return HCI_AT_NO_BONDING;
                }
-       } else if (l2cap_pi(sk)->psm == cpu_to_le16(0x0001)) {
+       } else if (chan->psm == cpu_to_le16(0x0001)) {
                if (chan->sec_level == BT_SECURITY_LOW)
                        chan->sec_level = BT_SECURITY_SDP;
 
@@ -298,7 +298,7 @@ static inline u8 l2cap_get_auth_type(struct l2cap_chan *chan)
 /* Service level security */
 static inline int l2cap_check_security(struct l2cap_chan *chan)
 {
-       struct l2cap_conn *conn = l2cap_pi(chan->sk)->conn;
+       struct l2cap_conn *conn = chan->conn;
        __u8 auth_type;
 
        auth_type = l2cap_get_auth_type(chan);
@@ -351,7 +351,7 @@ static inline void l2cap_send_sframe(struct l2cap_chan *chan, u16 control)
        struct sk_buff *skb;
        struct l2cap_hdr *lh;
        struct l2cap_pinfo *pi = l2cap_pi(chan->sk);
-       struct l2cap_conn *conn = pi->conn;
+       struct l2cap_conn *conn = chan->conn;
        struct sock *sk = (struct sock *)pi;
        int count, hlen = L2CAP_HDR_SIZE + 2;
        u8 flags;
@@ -383,7 +383,7 @@ static inline void l2cap_send_sframe(struct l2cap_chan *chan, u16 control)
 
        lh = (struct l2cap_hdr *) skb_put(skb, L2CAP_HDR_SIZE);
        lh->len = cpu_to_le16(hlen - L2CAP_HDR_SIZE);
-       lh->cid = cpu_to_le16(pi->dcid);
+       lh->cid = cpu_to_le16(chan->dcid);
        put_unaligned_le16(control, skb_put(skb, 2));
 
        if (chan->fcs == L2CAP_FCS_CRC16) {
@@ -396,7 +396,7 @@ static inline void l2cap_send_sframe(struct l2cap_chan *chan, u16 control)
        else
                flags = ACL_START;
 
-       hci_send_acl(pi->conn->hcon, skb, flags);
+       hci_send_acl(chan->conn->hcon, skb, flags);
 }
 
 static inline void l2cap_send_rr_or_rnr(struct l2cap_chan *chan, u16 control)
@@ -419,8 +419,7 @@ static inline int __l2cap_no_conn_pending(struct l2cap_chan *chan)
 
 static void l2cap_do_start(struct l2cap_chan *chan)
 {
-       struct sock *sk = chan->sk;
-       struct l2cap_conn *conn = l2cap_pi(sk)->conn;
+       struct l2cap_conn *conn = chan->conn;
 
        if (conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_SENT) {
                if (!(conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE))
@@ -429,8 +428,8 @@ static void l2cap_do_start(struct l2cap_chan *chan)
                if (l2cap_check_security(chan) &&
                                __l2cap_no_conn_pending(chan)) {
                        struct l2cap_conn_req req;
-                       req.scid = cpu_to_le16(l2cap_pi(sk)->scid);
-                       req.psm  = l2cap_pi(sk)->psm;
+                       req.scid = cpu_to_le16(chan->scid);
+                       req.psm  = chan->psm;
 
                        chan->ident = l2cap_get_ident(conn);
                        chan->conf_state |= L2CAP_CONF_CONNECT_PEND;
@@ -479,14 +478,14 @@ void l2cap_send_disconn_req(struct l2cap_conn *conn, struct l2cap_chan *chan, in
 
        sk = chan->sk;
 
-       if (l2cap_pi(sk)->mode == L2CAP_MODE_ERTM) {
+       if (chan->mode == L2CAP_MODE_ERTM) {
                del_timer(&chan->retrans_timer);
                del_timer(&chan->monitor_timer);
                del_timer(&chan->ack_timer);
        }
 
-       req.dcid = cpu_to_le16(l2cap_pi(sk)->dcid);
-       req.scid = cpu_to_le16(l2cap_pi(sk)->scid);
+       req.dcid = cpu_to_le16(chan->dcid);
+       req.scid = cpu_to_le16(chan->scid);
        l2cap_send_cmd(conn, l2cap_get_ident(conn),
                        L2CAP_DISCONN_REQ, sizeof(req), &req);
 
@@ -523,7 +522,7 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
                                continue;
                        }
 
-                       if (!l2cap_mode_supported(l2cap_pi(sk)->mode,
+                       if (!l2cap_mode_supported(chan->mode,
                                        conn->feat_mask)
                                        && chan->conf_state &
                                        L2CAP_CONF_STATE2_DEVICE) {
@@ -536,8 +535,8 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
                                continue;
                        }
 
-                       req.scid = cpu_to_le16(l2cap_pi(sk)->scid);
-                       req.psm  = l2cap_pi(sk)->psm;
+                       req.scid = cpu_to_le16(chan->scid);
+                       req.psm  = chan->psm;
 
                        chan->ident = l2cap_get_ident(conn);
                        chan->conf_state |= L2CAP_CONF_CONNECT_PEND;
@@ -548,8 +547,8 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
                } else if (sk->sk_state == BT_CONNECT2) {
                        struct l2cap_conn_rsp rsp;
                        char buf[128];
-                       rsp.scid = cpu_to_le16(l2cap_pi(sk)->dcid);
-                       rsp.dcid = cpu_to_le16(l2cap_pi(sk)->scid);
+                       rsp.scid = cpu_to_le16(chan->dcid);
+                       rsp.dcid = cpu_to_le16(chan->scid);
 
                        if (l2cap_check_security(chan)) {
                                if (bt_sk(sk)->defer_setup) {
@@ -600,10 +599,12 @@ static struct sock *l2cap_get_sock_by_scid(int state, __le16 cid, bdaddr_t *src)
        read_lock(&l2cap_sk_list.lock);
 
        sk_for_each(sk, node, &l2cap_sk_list.head) {
+               struct l2cap_chan *chan = l2cap_pi(sk)->chan;
+
                if (state && sk->sk_state != state)
                        continue;
 
-               if (l2cap_pi(sk)->scid == cid) {
+               if (chan->scid == cid) {
                        /* Exact match. */
                        if (!bacmp(&bt_sk(sk)->src, src))
                                break;
@@ -830,10 +831,12 @@ static struct sock *l2cap_get_sock_by_psm(int state, __le16 psm, bdaddr_t *src)
        read_lock(&l2cap_sk_list.lock);
 
        sk_for_each(sk, node, &l2cap_sk_list.head) {
+               struct l2cap_chan *chan = l2cap_pi(sk)->chan;
+
                if (state && sk->sk_state != state)
                        continue;
 
-               if (l2cap_pi(sk)->psm == psm) {
+               if (chan->psm == psm) {
                        /* Exact match. */
                        if (!bacmp(&bt_sk(sk)->src, src))
                                break;
@@ -861,7 +864,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan)
        int err;
 
        BT_DBG("%s -> %s psm 0x%2.2x", batostr(src), batostr(dst),
-                                                       l2cap_pi(sk)->psm);
+                                                       chan->psm);
 
        hdev = hci_get_route(dst, src);
        if (!hdev)
@@ -871,7 +874,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan)
 
        auth_type = l2cap_get_auth_type(chan);
 
-       if (l2cap_pi(sk)->dcid == L2CAP_CID_LE_DATA)
+       if (chan->dcid == L2CAP_CID_LE_DATA)
                hcon = hci_connect(hdev, LE_LINK, dst,
                                        chan->sec_level, auth_type);
        else
@@ -918,12 +921,13 @@ done:
 
 int __l2cap_wait_ack(struct sock *sk)
 {
+       struct l2cap_chan *chan = l2cap_pi(sk)->chan;
        DECLARE_WAITQUEUE(wait, current);
        int err = 0;
        int timeo = HZ/5;
 
        add_wait_queue(sk_sleep(sk), &wait);
-       while ((l2cap_pi(sk)->chan->unacked_frames > 0 && l2cap_pi(sk)->conn)) {
+       while ((chan->unacked_frames > 0 && chan->conn)) {
                set_current_state(TASK_INTERRUPTIBLE);
 
                if (!timeo)
@@ -956,7 +960,7 @@ static void l2cap_monitor_timeout(unsigned long arg)
 
        bh_lock_sock(sk);
        if (chan->retry_count >= chan->remote_max_tx) {
-               l2cap_send_disconn_req(l2cap_pi(sk)->conn, chan, ECONNABORTED);
+               l2cap_send_disconn_req(chan->conn, chan, ECONNABORTED);
                bh_unlock_sock(sk);
                return;
        }
@@ -1006,8 +1010,7 @@ static void l2cap_drop_acked_frames(struct l2cap_chan *chan)
 
 void l2cap_do_send(struct l2cap_chan *chan, struct sk_buff *skb)
 {
-       struct sock *sk = chan->sk;
-       struct hci_conn *hcon = l2cap_pi(sk)->conn->hcon;
+       struct hci_conn *hcon = chan->conn->hcon;
        u16 flags;
 
        BT_DBG("chan %p, skb %p len %d", chan, skb, skb->len);
@@ -1043,8 +1046,6 @@ void l2cap_streaming_send(struct l2cap_chan *chan)
 
 static void l2cap_retransmit_one_frame(struct l2cap_chan *chan, u8 tx_seq)
 {
-       struct sock *sk = chan->sk;
-       struct l2cap_pinfo *pi = l2cap_pi(sk);
        struct sk_buff *skb, *tx_skb;
        u16 control, fcs;
 
@@ -1063,7 +1064,7 @@ static void l2cap_retransmit_one_frame(struct l2cap_chan *chan, u8 tx_seq)
 
        if (chan->remote_max_tx &&
                        bt_cb(skb)->retries == chan->remote_max_tx) {
-               l2cap_send_disconn_req(pi->conn, chan, ECONNABORTED);
+               l2cap_send_disconn_req(chan->conn, chan, ECONNABORTED);
                return;
        }
 
@@ -1094,7 +1095,6 @@ int l2cap_ertm_send(struct l2cap_chan *chan)
 {
        struct sk_buff *skb, *tx_skb;
        struct sock *sk = chan->sk;
-       struct l2cap_pinfo *pi = l2cap_pi(sk);
        u16 control, fcs;
        int nsent = 0;
 
@@ -1105,7 +1105,7 @@ int l2cap_ertm_send(struct l2cap_chan *chan)
 
                if (chan->remote_max_tx &&
                                bt_cb(skb)->retries == chan->remote_max_tx) {
-                       l2cap_send_disconn_req(pi->conn, chan, ECONNABORTED);
+                       l2cap_send_disconn_req(chan->conn, chan, ECONNABORTED);
                        break;
                }
 
@@ -1201,7 +1201,7 @@ static void l2cap_send_srejtail(struct l2cap_chan *chan)
 
 static inline int l2cap_skbuff_fromiovec(struct sock *sk, struct msghdr *msg, int len, int count, struct sk_buff *skb)
 {
-       struct l2cap_conn *conn = l2cap_pi(sk)->conn;
+       struct l2cap_conn *conn = l2cap_pi(sk)->chan->conn;
        struct sk_buff **frag;
        int err, sent = 0;
 
@@ -1231,9 +1231,10 @@ static inline int l2cap_skbuff_fromiovec(struct sock *sk, struct msghdr *msg, in
        return sent;
 }
 
-struct sk_buff *l2cap_create_connless_pdu(struct sock *sk, struct msghdr *msg, size_t len)
+struct sk_buff *l2cap_create_connless_pdu(struct l2cap_chan *chan, struct msghdr *msg, size_t len)
 {
-       struct l2cap_conn *conn = l2cap_pi(sk)->conn;
+       struct sock *sk = chan->sk;
+       struct l2cap_conn *conn = chan->conn;
        struct sk_buff *skb;
        int err, count, hlen = L2CAP_HDR_SIZE + 2;
        struct l2cap_hdr *lh;
@@ -1248,9 +1249,9 @@ struct sk_buff *l2cap_create_connless_pdu(struct sock *sk, struct msghdr *msg, s
 
        /* Create L2CAP header */
        lh = (struct l2cap_hdr *) skb_put(skb, L2CAP_HDR_SIZE);
-       lh->cid = cpu_to_le16(l2cap_pi(sk)->dcid);
+       lh->cid = cpu_to_le16(chan->dcid);
        lh->len = cpu_to_le16(len + (hlen - L2CAP_HDR_SIZE));
-       put_unaligned_le16(l2cap_pi(sk)->psm, skb_put(skb, 2));
+       put_unaligned_le16(chan->psm, skb_put(skb, 2));
 
        err = l2cap_skbuff_fromiovec(sk, msg, len, count, skb);
        if (unlikely(err < 0)) {
@@ -1260,9 +1261,10 @@ struct sk_buff *l2cap_create_connless_pdu(struct sock *sk, struct msghdr *msg, s
        return skb;
 }
 
-struct sk_buff *l2cap_create_basic_pdu(struct sock *sk, struct msghdr *msg, size_t len)
+struct sk_buff *l2cap_create_basic_pdu(struct l2cap_chan *chan, struct msghdr *msg, size_t len)
 {
-       struct l2cap_conn *conn = l2cap_pi(sk)->conn;
+       struct sock *sk = chan->sk;
+       struct l2cap_conn *conn = chan->conn;
        struct sk_buff *skb;
        int err, count, hlen = L2CAP_HDR_SIZE;
        struct l2cap_hdr *lh;
@@ -1277,7 +1279,7 @@ struct sk_buff *l2cap_create_basic_pdu(struct sock *sk, struct msghdr *msg, size
 
        /* Create L2CAP header */
        lh = (struct l2cap_hdr *) skb_put(skb, L2CAP_HDR_SIZE);
-       lh->cid = cpu_to_le16(l2cap_pi(sk)->dcid);
+       lh->cid = cpu_to_le16(chan->dcid);
        lh->len = cpu_to_le16(len + (hlen - L2CAP_HDR_SIZE));
 
        err = l2cap_skbuff_fromiovec(sk, msg, len, count, skb);
@@ -1291,7 +1293,7 @@ struct sk_buff *l2cap_create_basic_pdu(struct sock *sk, struct msghdr *msg, size
 struct sk_buff *l2cap_create_iframe_pdu(struct l2cap_chan *chan, struct msghdr *msg, size_t len, u16 control, u16 sdulen)
 {
        struct sock *sk = chan->sk;
-       struct l2cap_conn *conn = l2cap_pi(sk)->conn;
+       struct l2cap_conn *conn = chan->conn;
        struct sk_buff *skb;
        int err, count, hlen = L2CAP_HDR_SIZE + 2;
        struct l2cap_hdr *lh;
@@ -1315,7 +1317,7 @@ struct sk_buff *l2cap_create_iframe_pdu(struct l2cap_chan *chan, struct msghdr *
 
        /* Create L2CAP header */
        lh = (struct l2cap_hdr *) skb_put(skb, L2CAP_HDR_SIZE);
-       lh->cid = cpu_to_le16(l2cap_pi(sk)->dcid);
+       lh->cid = cpu_to_le16(chan->dcid);
        lh->len = cpu_to_le16(len + (hlen - L2CAP_HDR_SIZE));
        put_unaligned_le16(control, skb_put(skb, 2));
        if (sdulen)
@@ -1607,9 +1609,8 @@ static inline __u8 l2cap_select_mode(__u8 mode, __u16 remote_feat_mask)
 
 static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data)
 {
-       struct l2cap_pinfo *pi = l2cap_pi(chan->sk);
        struct l2cap_conf_req *req = data;
-       struct l2cap_conf_rfc rfc = { .mode = pi->mode };
+       struct l2cap_conf_rfc rfc = { .mode = chan->mode };
        void *ptr = req->data;
 
        BT_DBG("chan %p", chan);
@@ -1617,7 +1618,7 @@ static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data)
        if (chan->num_conf_req || chan->num_conf_rsp)
                goto done;
 
-       switch (pi->mode) {
+       switch (chan->mode) {
        case L2CAP_MODE_STREAMING:
        case L2CAP_MODE_ERTM:
                if (chan->conf_state & L2CAP_CONF_STATE2_DEVICE)
@@ -1625,18 +1626,18 @@ static int l2cap_build_conf_req(struct l2cap_chan *chan, void *data)
 
                /* fall through */
        default:
-               pi->mode = l2cap_select_mode(rfc.mode, pi->conn->feat_mask);
+               chan->mode = l2cap_select_mode(rfc.mode, chan->conn->feat_mask);
                break;
        }
 
 done:
-       if (pi->imtu != L2CAP_DEFAULT_MTU)
-               l2cap_add_conf_opt(&ptr, L2CAP_CONF_MTU, 2, pi->imtu);
+       if (chan->imtu != L2CAP_DEFAULT_MTU)
+               l2cap_add_conf_opt(&ptr, L2CAP_CONF_MTU, 2, chan->imtu);
 
-       switch (pi->mode) {
+       switch (chan->mode) {
        case L2CAP_MODE_BASIC:
-               if (!(pi->conn->feat_mask & L2CAP_FEAT_ERTM) &&
-                               !(pi->conn->feat_mask & L2CAP_FEAT_STREAMING))
+               if (!(chan->conn->feat_mask & L2CAP_FEAT_ERTM) &&
+                               !(chan->conn->feat_mask & L2CAP_FEAT_STREAMING))
                        break;
 
                rfc.mode            = L2CAP_MODE_BASIC;
@@ -1657,13 +1658,13 @@ done:
                rfc.retrans_timeout = 0;
                rfc.monitor_timeout = 0;
                rfc.max_pdu_size    = cpu_to_le16(L2CAP_DEFAULT_MAX_PDU_SIZE);
-               if (L2CAP_DEFAULT_MAX_PDU_SIZE > pi->conn->mtu - 10)
-                       rfc.max_pdu_size = cpu_to_le16(pi->conn->mtu - 10);
+               if (L2CAP_DEFAULT_MAX_PDU_SIZE > chan->conn->mtu - 10)
+                       rfc.max_pdu_size = cpu_to_le16(chan->conn->mtu - 10);
 
                l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC, sizeof(rfc),
                                                        (unsigned long) &rfc);
 
-               if (!(pi->conn->feat_mask & L2CAP_FEAT_FCS))
+               if (!(chan->conn->feat_mask & L2CAP_FEAT_FCS))
                        break;
 
                if (chan->fcs == L2CAP_FCS_NONE ||
@@ -1680,13 +1681,13 @@ done:
                rfc.retrans_timeout = 0;
                rfc.monitor_timeout = 0;
                rfc.max_pdu_size    = cpu_to_le16(L2CAP_DEFAULT_MAX_PDU_SIZE);
-               if (L2CAP_DEFAULT_MAX_PDU_SIZE > pi->conn->mtu - 10)
-                       rfc.max_pdu_size = cpu_to_le16(pi->conn->mtu - 10);
+               if (L2CAP_DEFAULT_MAX_PDU_SIZE > chan->conn->mtu - 10)
+                       rfc.max_pdu_size = cpu_to_le16(chan->conn->mtu - 10);
 
                l2cap_add_conf_opt(&ptr, L2CAP_CONF_RFC, sizeof(rfc),
                                                        (unsigned long) &rfc);
 
-               if (!(pi->conn->feat_mask & L2CAP_FEAT_FCS))
+               if (!(chan->conn->feat_mask & L2CAP_FEAT_FCS))
                        break;
 
                if (chan->fcs == L2CAP_FCS_NONE ||
@@ -1697,7 +1698,7 @@ done:
                break;
        }
 
-       req->dcid  = cpu_to_le16(pi->dcid);
+       req->dcid  = cpu_to_le16(chan->dcid);
        req->flags = cpu_to_le16(0);
 
        return ptr - data;
@@ -1705,7 +1706,6 @@ done:
 
 static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data)
 {
-       struct l2cap_pinfo *pi = l2cap_pi(chan->sk);
        struct l2cap_conf_rsp *rsp = data;
        void *ptr = rsp->data;
        void *req = chan->conf_req;
@@ -1730,7 +1730,7 @@ static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data)
                        break;
 
                case L2CAP_CONF_FLUSH_TO:
-                       pi->flush_to = val;
+                       chan->flush_to = val;
                        break;
 
                case L2CAP_CONF_QOS:
@@ -1760,25 +1760,25 @@ static int l2cap_parse_conf_req(struct l2cap_chan *chan, void *data)
        if (chan->num_conf_rsp || chan->num_conf_req > 1)
                goto done;
 
-       switch (pi->mode) {
+       switch (chan->mode) {
        case L2CAP_MODE_STREAMING:
        case L2CAP_MODE_ERTM:
                if (!(chan->conf_state & L2CAP_CONF_STATE2_DEVICE)) {
-                       pi->mode = l2cap_select_mode(rfc.mode,
-                                       pi->conn->feat_mask);
+                       chan->mode = l2cap_select_mode(rfc.mode,
+                                       chan->conn->feat_mask);
                        break;
                }
 
-               if (pi->mode != rfc.mode)
+               if (chan->mode != rfc.mode)
                        return -ECONNREFUSED;
 
                break;
        }
 
 done:
-       if (pi->mode != rfc.mode) {
+       if (chan->mode != rfc.mode) {
                result = L2CAP_CONF_UNACCEPT;
-               rfc.mode = pi->mode;
+               rfc.mode = chan->mode;
 
                if (chan->num_conf_rsp == 1)
                        return -ECONNREFUSED;
@@ -1795,10 +1795,10 @@ done:
                if (mtu < L2CAP_DEFAULT_MIN_MTU)
                        result = L2CAP_CONF_UNACCEPT;
                else {
-                       pi->omtu = mtu;
+                       chan->omtu = mtu;
                        chan->conf_state |= L2CAP_CONF_MTU_DONE;
                }
-               l2cap_add_conf_opt(&ptr, L2CAP_CONF_MTU, 2, pi->omtu);
+               l2cap_add_conf_opt(&ptr, L2CAP_CONF_MTU, 2, chan->omtu);
 
                switch (rfc.mode) {
                case L2CAP_MODE_BASIC:
@@ -1810,8 +1810,8 @@ done:
                        chan->remote_tx_win = rfc.txwin_size;
                        chan->remote_max_tx = rfc.max_transmit;
 
-                       if (le16_to_cpu(rfc.max_pdu_size) > pi->conn->mtu - 10)
-                               rfc.max_pdu_size = cpu_to_le16(pi->conn->mtu - 10);
+                       if (le16_to_cpu(rfc.max_pdu_size) > chan->conn->mtu - 10)
+                               rfc.max_pdu_size = cpu_to_le16(chan->conn->mtu - 10);
 
                        chan->remote_mps = le16_to_cpu(rfc.max_pdu_size);
 
@@ -1828,8 +1828,8 @@ done:
                        break;
 
                case L2CAP_MODE_STREAMING:
-                       if (le16_to_cpu(rfc.max_pdu_size) > pi->conn->mtu - 10)
-                               rfc.max_pdu_size = cpu_to_le16(pi->conn->mtu - 10);
+                       if (le16_to_cpu(rfc.max_pdu_size) > chan->conn->mtu - 10)
+                               rfc.max_pdu_size = cpu_to_le16(chan->conn->mtu - 10);
 
                        chan->remote_mps = le16_to_cpu(rfc.max_pdu_size);
 
@@ -1844,13 +1844,13 @@ done:
                        result = L2CAP_CONF_UNACCEPT;
 
                        memset(&rfc, 0, sizeof(rfc));
-                       rfc.mode = pi->mode;
+                       rfc.mode = chan->mode;
                }
 
                if (result == L2CAP_CONF_SUCCESS)
                        chan->conf_state |= L2CAP_CONF_OUTPUT_DONE;
        }
-       rsp->scid   = cpu_to_le16(pi->dcid);
+       rsp->scid   = cpu_to_le16(chan->dcid);
        rsp->result = cpu_to_le16(result);
        rsp->flags  = cpu_to_le16(0x0000);
 
@@ -1859,15 +1859,13 @@ done:
 
 static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, void *data, u16 *result)
 {
-       struct sock *sk = chan->sk;
-       struct l2cap_pinfo *pi = l2cap_pi(sk);
        struct l2cap_conf_req *req = data;
        void *ptr = req->data;
        int type, olen;
        unsigned long val;
        struct l2cap_conf_rfc rfc;
 
-       BT_DBG("sk %p, rsp %p, len %d, req %p", sk, rsp, len, data);
+       BT_DBG("chan %p, rsp %p, len %d, req %p", chan, rsp, len, data);
 
        while (len >= L2CAP_CONF_OPT_SIZE) {
                len -= l2cap_get_conf_opt(&rsp, &type, &olen, &val);
@@ -1876,16 +1874,16 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
                case L2CAP_CONF_MTU:
                        if (val < L2CAP_DEFAULT_MIN_MTU) {
                                *result = L2CAP_CONF_UNACCEPT;
-                               pi->imtu = L2CAP_DEFAULT_MIN_MTU;
+                               chan->imtu = L2CAP_DEFAULT_MIN_MTU;
                        } else
-                               pi->imtu = val;
-                       l2cap_add_conf_opt(&ptr, L2CAP_CONF_MTU, 2, pi->imtu);
+                               chan->imtu = val;
+                       l2cap_add_conf_opt(&ptr, L2CAP_CONF_MTU, 2, chan->imtu);
                        break;
 
                case L2CAP_CONF_FLUSH_TO:
-                       pi->flush_to = val;
+                       chan->flush_to = val;
                        l2cap_add_conf_opt(&ptr, L2CAP_CONF_FLUSH_TO,
-                                                       2, pi->flush_to);
+                                                       2, chan->flush_to);
                        break;
 
                case L2CAP_CONF_RFC:
@@ -1893,7 +1891,7 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
                                memcpy(&rfc, (void *)val, olen);
 
                        if ((chan->conf_state & L2CAP_CONF_STATE2_DEVICE) &&
-                                                       rfc.mode != pi->mode)
+                                                       rfc.mode != chan->mode)
                                return -ECONNREFUSED;
 
                        chan->fcs = 0;
@@ -1904,10 +1902,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
                }
        }
 
-       if (pi->mode == L2CAP_MODE_BASIC && pi->mode != rfc.mode)
+       if (chan->mode == L2CAP_MODE_BASIC && chan->mode != rfc.mode)
                return -ECONNREFUSED;
 
-       pi->mode = rfc.mode;
+       chan->mode = rfc.mode;
 
        if (*result == L2CAP_CONF_SUCCESS) {
                switch (rfc.mode) {
@@ -1921,37 +1919,34 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
                }
        }
 
-       req->dcid   = cpu_to_le16(pi->dcid);
+       req->dcid   = cpu_to_le16(chan->dcid);
        req->flags  = cpu_to_le16(0x0000);
 
        return ptr - data;
 }
 
-static int l2cap_build_conf_rsp(struct sock *sk, void *data, u16 result, u16 flags)
+static int l2cap_build_conf_rsp(struct l2cap_chan *chan, void *data, u16 result, u16 flags)
 {
        struct l2cap_conf_rsp *rsp = data;
        void *ptr = rsp->data;
 
-       BT_DBG("sk %p", sk);
+       BT_DBG("chan %p", chan);
 
-       rsp->scid   = cpu_to_le16(l2cap_pi(sk)->dcid);
+       rsp->scid   = cpu_to_le16(chan->dcid);
        rsp->result = cpu_to_le16(result);
        rsp->flags  = cpu_to_le16(flags);
 
        return ptr - data;
 }
 
-void __l2cap_connect_rsp_defer(struct sock *sk)
+void __l2cap_connect_rsp_defer(struct l2cap_chan *chan)
 {
        struct l2cap_conn_rsp rsp;
-       struct l2cap_conn *conn = l2cap_pi(sk)->conn;
-       struct l2cap_chan *chan = l2cap_pi(sk)->chan;
+       struct l2cap_conn *conn = chan->conn;
        u8 buf[128];
 
-       sk->sk_state = BT_CONFIG;
-
-       rsp.scid   = cpu_to_le16(l2cap_pi(sk)->dcid);
-       rsp.dcid   = cpu_to_le16(l2cap_pi(sk)->scid);
+       rsp.scid   = cpu_to_le16(chan->dcid);
+       rsp.dcid   = cpu_to_le16(chan->scid);
        rsp.result = cpu_to_le16(L2CAP_CR_SUCCESS);
        rsp.status = cpu_to_le16(L2CAP_CS_NO_INFO);
        l2cap_send_cmd(conn, chan->ident,
@@ -1968,14 +1963,13 @@ void __l2cap_connect_rsp_defer(struct sock *sk)
 
 static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
 {
-       struct l2cap_pinfo *pi = l2cap_pi(chan->sk);
        int type, olen;
        unsigned long val;
        struct l2cap_conf_rfc rfc;
 
        BT_DBG("chan %p, rsp %p, len %d", chan, rsp, len);
 
-       if ((pi->mode != L2CAP_MODE_ERTM) && (pi->mode != L2CAP_MODE_STREAMING))
+       if ((chan->mode != L2CAP_MODE_ERTM) && (chan->mode != L2CAP_MODE_STREAMING))
                return;
 
        while (len >= L2CAP_CONF_OPT_SIZE) {
@@ -2086,14 +2080,14 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd
        l2cap_sock_init(sk, parent);
        bacpy(&bt_sk(sk)->src, conn->src);
        bacpy(&bt_sk(sk)->dst, conn->dst);
-       l2cap_pi(sk)->psm  = psm;
-       l2cap_pi(sk)->dcid = scid;
+       chan->psm  = psm;
+       chan->dcid = scid;
 
        bt_accept_enqueue(parent, sk);
 
        __l2cap_chan_add(conn, chan);
 
-       dcid = l2cap_pi(sk)->scid;
+       dcid = chan->scid;
 
        l2cap_sock_set_timer(sk, sk->sk_sndtimeo);
 
@@ -2191,7 +2185,7 @@ static inline int l2cap_connect_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hd
        case L2CAP_CR_SUCCESS:
                sk->sk_state = BT_CONFIG;
                chan->ident = 0;
-               l2cap_pi(sk)->dcid = dcid;
+               chan->dcid = dcid;
                chan->conf_state &= ~L2CAP_CONF_CONNECT_PEND;
 
                if (chan->conf_state & L2CAP_CONF_REQ_SENT)
@@ -2232,7 +2226,7 @@ static inline void set_default_fcs(struct l2cap_chan *chan)
        /* FCS is enabled only in ERTM or streaming mode, if one or both
         * sides request it.
         */
-       if (pi->mode != L2CAP_MODE_ERTM && pi->mode != L2CAP_MODE_STREAMING)
+       if (chan->mode != L2CAP_MODE_ERTM && chan->mode != L2CAP_MODE_STREAMING)
                chan->fcs = L2CAP_FCS_NONE;
        else if (!(pi->chan->conf_state & L2CAP_CONF_NO_FCS_RECV))
                chan->fcs = L2CAP_FCS_CRC16;
@@ -2271,7 +2265,7 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr
        len = cmd_len - sizeof(*req);
        if (chan->conf_len + len > sizeof(chan->conf_req)) {
                l2cap_send_cmd(conn, cmd->ident, L2CAP_CONF_RSP,
-                               l2cap_build_conf_rsp(sk, rsp,
+                               l2cap_build_conf_rsp(chan, rsp,
                                        L2CAP_CONF_REJECT, flags), rsp);
                goto unlock;
        }
@@ -2283,7 +2277,7 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr
        if (flags & 0x0001) {
                /* Incomplete config. Send empty response. */
                l2cap_send_cmd(conn, cmd->ident, L2CAP_CONF_RSP,
-                               l2cap_build_conf_rsp(sk, rsp,
+                               l2cap_build_conf_rsp(chan, rsp,
                                        L2CAP_CONF_SUCCESS, 0x0001), rsp);
                goto unlock;
        }
@@ -2312,7 +2306,7 @@ static inline int l2cap_config_req(struct l2cap_conn *conn, struct l2cap_cmd_hdr
                chan->next_tx_seq = 0;
                chan->expected_tx_seq = 0;
                skb_queue_head_init(&chan->tx_q);
-               if (l2cap_pi(sk)->mode == L2CAP_MODE_ERTM)
+               if (chan->mode == L2CAP_MODE_ERTM)
                        l2cap_ertm_init(chan);
 
                l2cap_chan_ready(sk);
@@ -2403,7 +2397,7 @@ static inline int l2cap_config_rsp(struct l2cap_conn *conn, struct l2cap_cmd_hdr
                chan->next_tx_seq = 0;
                chan->expected_tx_seq = 0;
                skb_queue_head_init(&chan->tx_q);
-               if (l2cap_pi(sk)->mode ==  L2CAP_MODE_ERTM)
+               if (chan->mode ==  L2CAP_MODE_ERTM)
                        l2cap_ertm_init(chan);
 
                l2cap_chan_ready(sk);
@@ -2433,8 +2427,8 @@ static inline int l2cap_disconnect_req(struct l2cap_conn *conn, struct l2cap_cmd
 
        sk = chan->sk;
 
-       rsp.dcid = cpu_to_le16(l2cap_pi(sk)->scid);
-       rsp.scid = cpu_to_le16(l2cap_pi(sk)->dcid);
+       rsp.dcid = cpu_to_le16(chan->scid);
+       rsp.scid = cpu_to_le16(chan->dcid);
        l2cap_send_cmd(conn, cmd->ident, L2CAP_DISCONN_RSP, sizeof(rsp), &rsp);
 
        sk->sk_shutdown = SHUTDOWN_MASK;
@@ -2855,7 +2849,6 @@ static int l2cap_add_to_srej_queue(struct l2cap_chan *chan, struct sk_buff *skb,
 
 static int l2cap_ertm_reassembly_sdu(struct l2cap_chan *chan, struct sk_buff *skb, u16 control)
 {
-       struct l2cap_pinfo *pi = l2cap_pi(chan->sk);
        struct sk_buff *_skb;
        int err;
 
@@ -2876,7 +2869,7 @@ static int l2cap_ertm_reassembly_sdu(struct l2cap_chan *chan, struct sk_buff *sk
 
                chan->sdu_len = get_unaligned_le16(skb->data);
 
-               if (chan->sdu_len > pi->imtu)
+               if (chan->sdu_len > chan->imtu)
                        goto disconnect;
 
                chan->sdu = bt_skb_alloc(chan->sdu_len, GFP_ATOMIC);
@@ -2919,7 +2912,7 @@ static int l2cap_ertm_reassembly_sdu(struct l2cap_chan *chan, struct sk_buff *sk
                if (!(chan->conn_state & L2CAP_CONN_SAR_RETRY)) {
                        chan->partial_sdu_len += skb->len;
 
-                       if (chan->partial_sdu_len > pi->imtu)
+                       if (chan->partial_sdu_len > chan->imtu)
                                goto drop;
 
                        if (chan->partial_sdu_len != chan->sdu_len)
@@ -2956,7 +2949,7 @@ drop:
        chan->sdu = NULL;
 
 disconnect:
-       l2cap_send_disconn_req(pi->conn, chan, ECONNRESET);
+       l2cap_send_disconn_req(chan->conn, chan, ECONNRESET);
        kfree_skb(skb);
        return 0;
 }
@@ -3017,7 +3010,7 @@ static void l2cap_busy_work(struct work_struct *work)
 
                if (n_tries++ > L2CAP_LOCAL_BUSY_TRIES) {
                        err = -EBUSY;
-                       l2cap_send_disconn_req(l2cap_pi(sk)->conn, chan, EBUSY);
+                       l2cap_send_disconn_req(chan->conn, chan, EBUSY);
                        break;
                }
 
@@ -3087,7 +3080,6 @@ static int l2cap_push_rx_skb(struct l2cap_chan *chan, struct sk_buff *skb, u16 c
 
 static int l2cap_streaming_reassembly_sdu(struct l2cap_chan *chan, struct sk_buff *skb, u16 control)
 {
-       struct l2cap_pinfo *pi = l2cap_pi(chan->sk);
        struct sk_buff *_skb;
        int err = -EINVAL;
 
@@ -3118,7 +3110,7 @@ static int l2cap_streaming_reassembly_sdu(struct l2cap_chan *chan, struct sk_buf
                chan->sdu_len = get_unaligned_le16(skb->data);
                skb_pull(skb, 2);
 
-               if (chan->sdu_len > pi->imtu) {
+               if (chan->sdu_len > chan->imtu) {
                        err = -EMSGSIZE;
                        break;
                }
@@ -3159,7 +3151,7 @@ static int l2cap_streaming_reassembly_sdu(struct l2cap_chan *chan, struct sk_buf
                chan->conn_state &= ~L2CAP_CONN_SAR_SDU;
                chan->partial_sdu_len += skb->len;
 
-               if (chan->partial_sdu_len > pi->imtu)
+               if (chan->partial_sdu_len > chan->imtu)
                        goto drop;
 
                if (chan->partial_sdu_len == chan->sdu_len) {
@@ -3236,7 +3228,6 @@ static void l2cap_send_srejframe(struct l2cap_chan *chan, u8 tx_seq)
 
 static inline int l2cap_data_channel_iframe(struct l2cap_chan *chan, u16 rx_control, struct sk_buff *skb)
 {
-       struct l2cap_pinfo *pi = l2cap_pi(chan->sk);
        u8 tx_seq = __get_txseq(rx_control);
        u8 req_seq = __get_reqseq(rx_control);
        u8 sar = rx_control >> L2CAP_CTRL_SAR_SHIFT;
@@ -3267,7 +3258,7 @@ static inline int l2cap_data_channel_iframe(struct l2cap_chan *chan, u16 rx_cont
 
        /* invalid tx_seq */
        if (tx_seq_offset >= chan->tx_win) {
-               l2cap_send_disconn_req(pi->conn, chan, ECONNRESET);
+               l2cap_send_disconn_req(chan->conn, chan, ECONNRESET);
                goto drop;
        }
 
@@ -3534,7 +3525,6 @@ static inline int l2cap_data_channel_sframe(struct l2cap_chan *chan, u16 rx_cont
 static int l2cap_ertm_data_rcv(struct sock *sk, struct sk_buff *skb)
 {
        struct l2cap_chan *chan = l2cap_pi(sk)->chan;
-       struct l2cap_pinfo *pi = l2cap_pi(sk);
        u16 control;
        u8 req_seq;
        int len, next_tx_seq_offset, req_seq_offset;
@@ -3558,7 +3548,7 @@ static int l2cap_ertm_data_rcv(struct sock *sk, struct sk_buff *skb)
                len -= 2;
 
        if (len > chan->mps) {
-               l2cap_send_disconn_req(pi->conn, chan, ECONNRESET);
+               l2cap_send_disconn_req(chan->conn, chan, ECONNRESET);
                goto drop;
        }
 
@@ -3574,13 +3564,13 @@ static int l2cap_ertm_data_rcv(struct sock *sk, struct sk_buff *skb)
 
        /* check for invalid req-seq */
        if (req_seq_offset > next_tx_seq_offset) {
-               l2cap_send_disconn_req(pi->conn, chan, ECONNRESET);
+               l2cap_send_disconn_req(chan->conn, chan, ECONNRESET);
                goto drop;
        }
 
        if (__is_iframe(control)) {
                if (len < 0) {
-                       l2cap_send_disconn_req(pi->conn, chan, ECONNRESET);
+                       l2cap_send_disconn_req(chan->conn, chan, ECONNRESET);
                        goto drop;
                }
 
@@ -3588,7 +3578,7 @@ static int l2cap_ertm_data_rcv(struct sock *sk, struct sk_buff *skb)
        } else {
                if (len != 0) {
                        BT_ERR("%d", len);
-                       l2cap_send_disconn_req(pi->conn, chan, ECONNRESET);
+                       l2cap_send_disconn_req(chan->conn, chan, ECONNRESET);
                        goto drop;
                }
 
@@ -3605,7 +3595,7 @@ drop:
 static inline int l2cap_data_channel(struct l2cap_conn *conn, u16 cid, struct sk_buff *skb)
 {
        struct l2cap_chan *chan;
-       struct sock *sk;
+       struct sock *sk = NULL;
        struct l2cap_pinfo *pi;
        u16 control;
        u8 tx_seq;
@@ -3625,14 +3615,14 @@ static inline int l2cap_data_channel(struct l2cap_conn *conn, u16 cid, struct sk
        if (sk->sk_state != BT_CONNECTED)
                goto drop;
 
-       switch (pi->mode) {
+       switch (chan->mode) {
        case L2CAP_MODE_BASIC:
                /* If socket recv buffers overflows we drop data here
                 * which is *bad* because L2CAP has to be reliable.
                 * But we don't have any other choice. L2CAP doesn't
                 * provide flow control mechanism. */
 
-               if (pi->imtu < skb->len)
+               if (chan->imtu < skb->len)
                        goto drop;
 
                if (!sock_queue_rcv_skb(sk, skb))
@@ -3678,7 +3668,7 @@ static inline int l2cap_data_channel(struct l2cap_conn *conn, u16 cid, struct sk
                goto done;
 
        default:
-               BT_DBG("chan %p: bad mode 0x%2.2x", chan, pi->mode);
+               BT_DBG("chan %p: bad mode 0x%2.2x", chan, chan->mode);
                break;
        }
 
@@ -3707,7 +3697,7 @@ static inline int l2cap_conless_channel(struct l2cap_conn *conn, __le16 psm, str
        if (sk->sk_state != BT_BOUND && sk->sk_state != BT_CONNECTED)
                goto drop;
 
-       if (l2cap_pi(sk)->imtu < skb->len)
+       if (l2cap_pi(sk)->chan->imtu < skb->len)
                goto drop;
 
        if (!sock_queue_rcv_skb(sk, skb))
@@ -3737,7 +3727,7 @@ static inline int l2cap_att_channel(struct l2cap_conn *conn, __le16 cid, struct
        if (sk->sk_state != BT_BOUND && sk->sk_state != BT_CONNECTED)
                goto drop;
 
-       if (l2cap_pi(sk)->imtu < skb->len)
+       if (l2cap_pi(sk)->chan->imtu < skb->len)
                goto drop;
 
        if (!sock_queue_rcv_skb(sk, skb))
@@ -3922,8 +3912,8 @@ static int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
                if (sk->sk_state == BT_CONNECT) {
                        if (!status) {
                                struct l2cap_conn_req req;
-                               req.scid = cpu_to_le16(l2cap_pi(sk)->scid);
-                               req.psm  = l2cap_pi(sk)->psm;
+                               req.scid = cpu_to_le16(chan->scid);
+                               req.psm  = chan->psm;
 
                                chan->ident = l2cap_get_ident(conn);
                                chan->conf_state |= L2CAP_CONF_CONNECT_PEND;
@@ -3947,8 +3937,8 @@ static int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
                                result = L2CAP_CR_SEC_BLOCK;
                        }
 
-                       rsp.scid   = cpu_to_le16(l2cap_pi(sk)->dcid);
-                       rsp.dcid   = cpu_to_le16(l2cap_pi(sk)->scid);
+                       rsp.scid   = cpu_to_le16(chan->dcid);
+                       rsp.dcid   = cpu_to_le16(chan->scid);
                        rsp.result = cpu_to_le16(result);
                        rsp.status = cpu_to_le16(L2CAP_CS_NO_INFO);
                        l2cap_send_cmd(conn, chan->ident, L2CAP_CONN_RSP,
@@ -4020,10 +4010,10 @@ static int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 fl
                if (chan && chan->sk) {
                        struct sock *sk = chan->sk;
 
-                       if (l2cap_pi(sk)->imtu < len - L2CAP_HDR_SIZE) {
+                       if (chan->imtu < len - L2CAP_HDR_SIZE) {
                                BT_ERR("Frame exceeding recv MTU (len %d, "
                                                        "MTU %d)", len,
-                                                       l2cap_pi(sk)->imtu);
+                                                       chan->imtu);
                                bh_unlock_sock(sk);
                                l2cap_conn_unreliable(conn, ECOMM);
                                goto drop;
@@ -4083,14 +4073,15 @@ static int l2cap_debugfs_show(struct seq_file *f, void *p)
 
        sk_for_each(sk, node, &l2cap_sk_list.head) {
                struct l2cap_pinfo *pi = l2cap_pi(sk);
+               struct l2cap_chan *chan = pi->chan;
 
                seq_printf(f, "%s %s %d %d 0x%4.4x 0x%4.4x %d %d %d %d\n",
                                        batostr(&bt_sk(sk)->src),
                                        batostr(&bt_sk(sk)->dst),
-                                       sk->sk_state, __le16_to_cpu(pi->psm),
-                                       pi->scid, pi->dcid,
-                                       pi->imtu, pi->omtu, pi->chan->sec_level,
-                                       pi->mode);
+                                       sk->sk_state, __le16_to_cpu(chan->psm),
+                                       chan->scid, chan->dcid,
+                                       chan->imtu, chan->omtu, chan->sec_level,
+                                       chan->mode);
        }
 
        read_unlock_bh(&l2cap_sk_list.lock);