module: make module param bint handle nul value
[linux-2.6.git] / net / bluetooth / l2cap_core.c
index d616519..faf0b11 100644 (file)
@@ -3,6 +3,7 @@
    Copyright (C) 2000-2001 Qualcomm Incorporated
    Copyright (C) 2009-2010 Gustavo F. Padovan <gustavo@padovan.org>
    Copyright (C) 2010 Google Inc.
+   Copyright (C) 2011 ProFUSION Embedded Systems
 
    Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
 
@@ -56,7 +57,7 @@
 #include <net/bluetooth/l2cap.h>
 #include <net/bluetooth/smp.h>
 
-int disable_ertm;
+bool disable_ertm;
 
 static u32 l2cap_feat_mask = L2CAP_FEAT_FIXED_CHAN;
 static u8 l2cap_fixed_chan[8] = { L2CAP_FC_L2CAP, };
@@ -76,37 +77,38 @@ static int l2cap_ertm_data_rcv(struct sock *sk, struct sk_buff *skb);
 
 /* ---- L2CAP channels ---- */
 
-static inline void chan_hold(struct l2cap_chan *c)
-{
-       atomic_inc(&c->refcnt);
-}
-
-static inline void chan_put(struct l2cap_chan *c)
-{
-       if (atomic_dec_and_test(&c->refcnt))
-               kfree(c);
-}
-
 static struct l2cap_chan *__l2cap_get_chan_by_dcid(struct l2cap_conn *conn, u16 cid)
 {
-       struct l2cap_chan *c;
+       struct l2cap_chan *c, *r = NULL;
 
-       list_for_each_entry(c, &conn->chan_l, list) {
-               if (c->dcid == cid)
-                       return c;
+       rcu_read_lock();
+
+       list_for_each_entry_rcu(c, &conn->chan_l, list) {
+               if (c->dcid == cid) {
+                       r = c;
+                       break;
+               }
        }
-       return NULL;
+
+       rcu_read_unlock();
+       return r;
 }
 
 static struct l2cap_chan *__l2cap_get_chan_by_scid(struct l2cap_conn *conn, u16 cid)
 {
-       struct l2cap_chan *c;
+       struct l2cap_chan *c, *r = NULL;
 
-       list_for_each_entry(c, &conn->chan_l, list) {
-               if (c->scid == cid)
-                       return c;
+       rcu_read_lock();
+
+       list_for_each_entry_rcu(c, &conn->chan_l, list) {
+               if (c->scid == cid) {
+                       r = c;
+                       break;
+               }
        }
-       return NULL;
+
+       rcu_read_unlock();
+       return r;
 }
 
 /* Find channel with given SCID.
@@ -115,34 +117,36 @@ static struct l2cap_chan *l2cap_get_chan_by_scid(struct l2cap_conn *conn, u16 ci
 {
        struct l2cap_chan *c;
 
-       mutex_lock(&conn->chan_lock);
        c = __l2cap_get_chan_by_scid(conn, cid);
        if (c)
                lock_sock(c->sk);
-       mutex_unlock(&conn->chan_lock);
        return c;
 }
 
 static struct l2cap_chan *__l2cap_get_chan_by_ident(struct l2cap_conn *conn, u8 ident)
 {
-       struct l2cap_chan *c;
+       struct l2cap_chan *c, *r = NULL;
 
-       list_for_each_entry(c, &conn->chan_l, list) {
-               if (c->ident == ident)
-                       return c;
+       rcu_read_lock();
+
+       list_for_each_entry_rcu(c, &conn->chan_l, list) {
+               if (c->ident == ident) {
+                       r = c;
+                       break;
+               }
        }
-       return NULL;
+
+       rcu_read_unlock();
+       return r;
 }
 
 static inline struct l2cap_chan *l2cap_get_chan_by_ident(struct l2cap_conn *conn, u8 ident)
 {
        struct l2cap_chan *c;
 
-       mutex_lock(&conn->chan_lock);
        c = __l2cap_get_chan_by_ident(conn, ident);
        if (c)
                lock_sock(c->sk);
-       mutex_unlock(&conn->chan_lock);
        return c;
 }
 
@@ -161,7 +165,7 @@ int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm)
 {
        int err;
 
-       write_lock_bh(&chan_list_lock);
+       write_lock(&chan_list_lock);
 
        if (psm && __l2cap_global_chan_by_addr(psm, src)) {
                err = -EADDRINUSE;
@@ -186,17 +190,17 @@ int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm)
        }
 
 done:
-       write_unlock_bh(&chan_list_lock);
+       write_unlock(&chan_list_lock);
        return err;
 }
 
 int l2cap_add_scid(struct l2cap_chan *chan,  __u16 scid)
 {
-       write_lock_bh(&chan_list_lock);
+       write_lock(&chan_list_lock);
 
        chan->scid = scid;
 
-       write_unlock_bh(&chan_list_lock);
+       write_unlock(&chan_list_lock);
 
        return 0;
 }
@@ -213,20 +217,6 @@ static u16 l2cap_alloc_cid(struct l2cap_conn *conn)
        return 0;
 }
 
-static void l2cap_set_timer(struct l2cap_chan *chan, struct delayed_work *work, long timeout)
-{
-       BT_DBG("chan %p state %d timeout %ld", chan, chan->state, timeout);
-
-       cancel_delayed_work_sync(work);
-
-       schedule_delayed_work(work, timeout);
-}
-
-static void l2cap_clear_timer(struct delayed_work *work)
-{
-       cancel_delayed_work_sync(work);
-}
-
 static char *state_to_string(int state)
 {
        switch(state) {
@@ -286,7 +276,7 @@ static void l2cap_chan_timeout(struct work_struct *work)
        release_sock(sk);
 
        chan->ops->close(chan->data);
-       chan_put(chan);
+       l2cap_chan_put(chan);
 }
 
 struct l2cap_chan *l2cap_chan_create(struct sock *sk)
@@ -299,9 +289,9 @@ struct l2cap_chan *l2cap_chan_create(struct sock *sk)
 
        chan->sk = sk;
 
-       write_lock_bh(&chan_list_lock);
+       write_lock(&chan_list_lock);
        list_add(&chan->global_l, &chan_list);
-       write_unlock_bh(&chan_list_lock);
+       write_unlock(&chan_list_lock);
 
        INIT_DELAYED_WORK(&chan->chan_timer, l2cap_chan_timeout);
 
@@ -316,14 +306,14 @@ struct l2cap_chan *l2cap_chan_create(struct sock *sk)
 
 void l2cap_chan_destroy(struct l2cap_chan *chan)
 {
-       write_lock_bh(&chan_list_lock);
+       write_lock(&chan_list_lock);
        list_del(&chan->global_l);
-       write_unlock_bh(&chan_list_lock);
+       write_unlock(&chan_list_lock);
 
-       chan_put(chan);
+       l2cap_chan_put(chan);
 }
 
-static void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan)
+static void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan)
 {
        BT_DBG("conn %p, psm 0x%2.2x, dcid 0x%4.4x", conn,
                        chan->psm, chan->dcid);
@@ -362,9 +352,9 @@ static void __l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan)
        chan->local_acc_lat     = L2CAP_DEFAULT_ACC_LAT;
        chan->local_flush_to    = L2CAP_DEFAULT_FLUSH_TO;
 
-       chan_hold(chan);
+       l2cap_chan_hold(chan);
 
-       list_add(&chan->list, &conn->chan_l);
+       list_add_rcu(&chan->list, &conn->chan_l);
 }
 
 /* Delete channel.
@@ -381,10 +371,10 @@ static void l2cap_chan_del(struct l2cap_chan *chan, int err)
 
        if (conn) {
                /* Delete from channel list */
-               mutex_lock(&conn->chan_lock);
-               list_del(&chan->list);
-               mutex_unlock(&conn->chan_lock);
-               chan_put(chan);
+               list_del_rcu(&chan->list);
+               synchronize_rcu();
+
+               l2cap_chan_put(chan);
 
                chan->conn = NULL;
                hci_conn_put(conn->hcon);
@@ -553,14 +543,14 @@ static u8 l2cap_get_ident(struct l2cap_conn *conn)
         *  200 - 254 are used by utilities like l2ping, etc.
         */
 
-       spin_lock_bh(&conn->lock);
+       spin_lock(&conn->lock);
 
        if (++conn->tx_ident > 128)
                conn->tx_ident = 1;
 
        id = conn->tx_ident;
 
-       spin_unlock_bh(&conn->lock);
+       spin_unlock(&conn->lock);
 
        return id;
 }
@@ -698,7 +688,7 @@ static void l2cap_do_start(struct l2cap_chan *chan)
                conn->info_state |= L2CAP_INFO_FEAT_MASK_REQ_SENT;
                conn->info_ident = l2cap_get_ident(conn);
 
-               schedule_delayed_work(&conn->info_work,
+               schedule_delayed_work(&conn->info_timer,
                                        msecs_to_jiffies(L2CAP_INFO_TIMEOUT));
 
                l2cap_send_cmd(conn, conn->info_ident,
@@ -750,13 +740,13 @@ static void l2cap_send_disconn_req(struct l2cap_conn *conn, struct l2cap_chan *c
 /* ---- L2CAP connections ---- */
 static void l2cap_conn_start(struct l2cap_conn *conn)
 {
-       struct l2cap_chan *chan, *tmp;
+       struct l2cap_chan *chan;
 
        BT_DBG("conn %p", conn);
 
-       mutex_lock(&conn->chan_lock);
+       rcu_read_lock();
 
-       list_for_each_entry_safe(chan, tmp, &conn->chan_l, list) {
+       list_for_each_entry_rcu(chan, &conn->chan_l, list) {
                struct sock *sk = chan->sk;
 
                bh_lock_sock(sk);
@@ -780,9 +770,7 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
                                        &chan->conf_state)) {
                                /* l2cap_chan_close() calls list_del(chan)
                                 * so release the lock */
-                               mutex_unlock(&conn->chan_lock);
                                l2cap_chan_close(chan, ECONNRESET);
-                               utex_lock(&conn->chan_lock);
                                bh_unlock_sock(sk);
                                continue;
                        }
@@ -838,7 +826,7 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
                bh_unlock_sock(sk);
        }
 
-       mutex_unlock(&conn->chan_lock);
+       rcu_read_unlock();
 }
 
 /* Find socket with cid and source bdaddr.
@@ -903,8 +891,6 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn)
 
        sk = chan->sk;
 
-       mutex_lock(&conn->chan_lock);
-
        hci_conn_hold(conn->hcon);
 
        bacpy(&bt_sk(sk)->src, conn->src);
@@ -912,15 +898,13 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn)
 
        bt_accept_enqueue(parent, sk);
 
-       __l2cap_chan_add(conn, chan);
+       l2cap_chan_add(conn, chan);
 
        __set_chan_timer(chan, sk->sk_sndtimeo);
 
        l2cap_state_change(chan, BT_CONNECTED);
        parent->sk_data_ready(parent, 0);
 
-       mutex_unlock(&conn->chan_lock);
-
 clean:
        release_sock(parent);
 }
@@ -954,9 +938,9 @@ static void l2cap_conn_ready(struct l2cap_conn *conn)
        if (conn->hcon->out && conn->hcon->type == LE_LINK)
                smp_conn_security(conn, conn->hcon->pending_sec_level);
 
-       mutex_lock(&conn->chan_lock);
+       rcu_read_lock();
 
-       list_for_each_entry(chan, &conn->chan_l, list) {
+       list_for_each_entry_rcu(chan, &conn->chan_l, list) {
                struct sock *sk = chan->sk;
 
                bh_lock_sock(sk);
@@ -976,7 +960,7 @@ static void l2cap_conn_ready(struct l2cap_conn *conn)
                bh_unlock_sock(sk);
        }
 
-       mutex_unlock(&conn->chan_lock);
+       rcu_read_unlock();
 }
 
 /* Notify sockets that we cannot guaranty reliability anymore */
@@ -986,22 +970,22 @@ static void l2cap_conn_unreliable(struct l2cap_conn *conn, int err)
 
        BT_DBG("conn %p", conn);
 
-       mutex_lock(&conn->chan_lock);
+       rcu_read_lock();
 
-       list_for_each_entry(chan, &conn->chan_l, list) {
+       list_for_each_entry_rcu(chan, &conn->chan_l, list) {
                struct sock *sk = chan->sk;
 
                if (test_bit(FLAG_FORCE_RELIABLE, &chan->flags))
                        sk->sk_err = err;
        }
 
-       mutex_unlock(&conn->chan_lock);
+       rcu_read_unlock();
 }
 
 static void l2cap_info_timeout(struct work_struct *work)
 {
        struct l2cap_conn *conn = container_of(work, struct l2cap_conn,
-                                                       info_work.work);
+                                                       info_timer.work);
 
        conn->info_state |= L2CAP_INFO_FEAT_MASK_REQ_DONE;
        conn->info_ident = 0;
@@ -1034,10 +1018,10 @@ static void l2cap_conn_del(struct hci_conn *hcon, int err)
        hci_chan_del(conn->hchan);
 
        if (conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_SENT)
-               cancel_delayed_work_sync(&conn->info_work);
+               __cancel_delayed_work(&conn->info_timer);
 
        if (test_and_clear_bit(HCI_CONN_LE_SMP_PEND, &hcon->pend)) {
-               del_timer(&conn->security_timer);
+               __cancel_delayed_work(&conn->security_timer);
                smp_chan_destroy(conn);
        }
 
@@ -1045,9 +1029,10 @@ static void l2cap_conn_del(struct hci_conn *hcon, int err)
        kfree(conn);
 }
 
-static void security_timeout(unsigned long arg)
+static void security_timeout(struct work_struct *work)
 {
-       struct l2cap_conn *conn = (void *) arg;
+       struct l2cap_conn *conn = container_of(work, struct l2cap_conn,
+                                               security_timer.work);
 
        l2cap_conn_del(conn->hcon, ETIMEDOUT);
 }
@@ -1087,28 +1072,19 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon, u8 status)
        conn->feat_mask = 0;
 
        spin_lock_init(&conn->lock);
-       mutex_init(&conn->chan_lock);
 
        INIT_LIST_HEAD(&conn->chan_l);
 
        if (hcon->type == LE_LINK)
-               setup_timer(&conn->security_timer, security_timeout,
-                                               (unsigned long) conn);
+               INIT_DELAYED_WORK(&conn->security_timer, security_timeout);
        else
-               INIT_DELAYED_WORK(&conn->info_work, l2cap_info_timeout);
+               INIT_DELAYED_WORK(&conn->info_timer, l2cap_info_timeout);
 
        conn->disc_reason = HCI_ERROR_REMOTE_USER_TERM;
 
        return conn;
 }
 
-static inline void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan)
-{
-       mutex_lock(&conn->chan_lock);
-       __l2cap_chan_add(conn, chan);
-       mutex_unlock(&conn->chan_lock);
-}
-
 /* ---- Socket interface ---- */
 
 /* Find socket with psm and source bdaddr.
@@ -1214,7 +1190,7 @@ inline int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, bdad
        }
 
        /* Set destination address and psm */
-       bacpy(&bt_sk(sk)->dst, src);
+       bacpy(&bt_sk(sk)->dst, dst);
        chan->psm = psm;
        chan->dcid = cid;
 
@@ -1825,8 +1801,9 @@ static void l2cap_raw_recv(struct l2cap_conn *conn, struct sk_buff *skb)
 
        BT_DBG("conn %p", conn);
 
-       mutex_lock(&conn->chan_lock);
-       list_for_each_entry(chan, &conn->chan_l, list) {
+       rcu_read_lock();
+
+       list_for_each_entry_rcu(chan, &conn->chan_l, list) {
                struct sock *sk = chan->sk;
                if (chan->chan_type != L2CAP_CHAN_RAW)
                        continue;
@@ -1841,7 +1818,8 @@ static void l2cap_raw_recv(struct l2cap_conn *conn, struct sk_buff *skb)
                if (chan->ops->recv(chan->data, nskb))
                        kfree_skb(nskb);
        }
-       mutex_unlock(&conn->chan_lock);
+
+       rcu_read_unlock();
 }
 
 /* ---- L2CAP signalling commands ---- */
@@ -2007,6 +1985,8 @@ static void l2cap_ack_timeout(struct work_struct *work)
        struct l2cap_chan *chan = container_of(work, struct l2cap_chan,
                                                        ack_timer.work);
 
+       BT_DBG("chan %p", chan);
+
        lock_sock(chan->sk);
        l2cap_send_ack(chan);
        release_sock(chan->sk);
@@ -2413,7 +2393,7 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
        void *ptr = req->data;
        int type, olen;
        unsigned long val;
-       struct l2cap_conf_rfc rfc;
+       struct l2cap_conf_rfc rfc = { .mode = L2CAP_MODE_BASIC };
        struct l2cap_conf_efs efs;
 
        BT_DBG("chan %p, rsp %p, len %d, req %p", chan, rsp, len, data);
@@ -2563,6 +2543,16 @@ static void l2cap_conf_rfc_get(struct l2cap_chan *chan, void *rsp, int len)
                }
        }
 
+       /* Use sane default values in case a misbehaving remote device
+        * did not send an RFC option.
+        */
+       rfc.mode = chan->mode;
+       rfc.retrans_timeout = cpu_to_le16(L2CAP_DEFAULT_RETRANS_TO);
+       rfc.monitor_timeout = cpu_to_le16(L2CAP_DEFAULT_MONITOR_TO);
+       rfc.max_pdu_size = cpu_to_le16(chan->imtu);
+
+       BT_ERR("Expected RFC option was not found, using defaults");
+
 done:
        switch (rfc.mode) {
        case L2CAP_MODE_ERTM:
@@ -2584,7 +2574,7 @@ static inline int l2cap_command_rej(struct l2cap_conn *conn, struct l2cap_cmd_hd
 
        if ((conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_SENT) &&
                                        cmd->ident == conn->info_ident) {
-               cancel_delayed_work_sync(&conn->info_work);
+               __cancel_delayed_work(&conn->info_timer);
 
                conn->info_state |= L2CAP_INFO_FEAT_MASK_REQ_DONE;
                conn->info_ident = 0;
@@ -2641,11 +2631,8 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd
 
        sk = chan->sk;
 
-       mutex_lock(&conn->chan_lock);
-
        /* Check if we already have channel with that dcid */
        if (__l2cap_get_chan_by_dcid(conn, scid)) {
-               mutex_unlock(&conn->chan_lock);
                sock_set_flag(sk, SOCK_ZAPPED);
                chan->ops->close(chan->data);
                goto response;
@@ -2660,7 +2647,7 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd
 
        bt_accept_enqueue(parent, sk);
 
-       __l2cap_chan_add(conn, chan);
+       l2cap_chan_add(conn, chan);
 
        dcid = chan->scid;
 
@@ -2691,8 +2678,6 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd
                status = L2CAP_CS_NO_INFO;
        }
 
-       mutex_unlock(&conn->chan_lock);
-
 response:
        release_sock(parent);
 
@@ -2710,7 +2695,7 @@ sendresp:
                conn->info_state |= L2CAP_INFO_FEAT_MASK_REQ_SENT;
                conn->info_ident = l2cap_get_ident(conn);
 
-               schedule_delayed_work(&conn->info_work,
+               schedule_delayed_work(&conn->info_timer,
                                        msecs_to_jiffies(L2CAP_INFO_TIMEOUT));
 
                l2cap_send_cmd(conn, conn->info_ident,
@@ -3135,7 +3120,7 @@ static inline int l2cap_information_rsp(struct l2cap_conn *conn, struct l2cap_cm
                        conn->info_state & L2CAP_INFO_FEAT_MASK_REQ_DONE)
                return 0;
 
-       cancel_delayed_work_sync(&conn->info_work);
+       __cancel_delayed_work(&conn->info_timer);
 
        if (result != L2CAP_IR_SUCCESS) {
                conn->info_state |= L2CAP_INFO_FEAT_MASK_REQ_DONE;
@@ -4419,14 +4404,11 @@ static void l2cap_recv_frame(struct l2cap_conn *conn, struct sk_buff *skb)
 
 /* ---- L2CAP interface with lower layer (HCI) ---- */
 
-static int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type)
+int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr)
 {
        int exact = 0, lm1 = 0, lm2 = 0;
        struct l2cap_chan *c;
 
-       if (type != ACL_LINK)
-               return -EINVAL;
-
        BT_DBG("hdev %s, bdaddr %s", hdev->name, batostr(bdaddr));
 
        /* Find listening sockets and check their link_mode */
@@ -4453,15 +4435,12 @@ static int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type)
        return exact ? lm1 : lm2;
 }
 
-static int l2cap_connect_cfm(struct hci_conn *hcon, u8 status)
+int l2cap_connect_cfm(struct hci_conn *hcon, u8 status)
 {
        struct l2cap_conn *conn;
 
        BT_DBG("hcon %p bdaddr %s status %d", hcon, batostr(&hcon->dst), status);
 
-       if (!(hcon->type == ACL_LINK || hcon->type == LE_LINK))
-               return -EINVAL;
-
        if (!status) {
                conn = l2cap_conn_add(hcon, status);
                if (conn)
@@ -4472,27 +4451,22 @@ static int l2cap_connect_cfm(struct hci_conn *hcon, u8 status)
        return 0;
 }
 
-static int l2cap_disconn_ind(struct hci_conn *hcon)
+int l2cap_disconn_ind(struct hci_conn *hcon)
 {
        struct l2cap_conn *conn = hcon->l2cap_data;
 
        BT_DBG("hcon %p", hcon);
 
-       if ((hcon->type != ACL_LINK && hcon->type != LE_LINK) || !conn)
+       if (!conn)
                return HCI_ERROR_REMOTE_USER_TERM;
-
        return conn->disc_reason;
 }
 
-static int l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason)
+int l2cap_disconn_cfm(struct hci_conn *hcon, u8 reason)
 {
        BT_DBG("hcon %p reason %d", hcon, reason);
 
-       if (!(hcon->type == ACL_LINK || hcon->type == LE_LINK))
-               return -EINVAL;
-
        l2cap_conn_del(hcon, bt_to_errno(reason));
-
        return 0;
 }
 
@@ -4513,7 +4487,7 @@ static inline void l2cap_check_encryption(struct l2cap_chan *chan, u8 encrypt)
        }
 }
 
-static int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
+int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
 {
        struct l2cap_conn *conn = hcon->l2cap_data;
        struct l2cap_chan *chan;
@@ -4525,12 +4499,12 @@ static int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
 
        if (hcon->type == LE_LINK) {
                smp_distribute_keys(conn, 0);
-               del_timer(&conn->security_timer);
+               __cancel_delayed_work(&conn->security_timer);
        }
 
-       mutex_lock(&conn->chan_lock);
+       rcu_read_lock();
 
-       list_for_each_entry(chan, &conn->chan_l, list) {
+       list_for_each_entry_rcu(chan, &conn->chan_l, list) {
                struct sock *sk = chan->sk;
 
                bh_lock_sock(sk);
@@ -4608,12 +4582,12 @@ static int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
                bh_unlock_sock(sk);
        }
 
-       mutex_unlock(&conn->chan_lock);
+       rcu_read_unlock();
 
        return 0;
 }
 
-static int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags)
+int l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags)
 {
        struct l2cap_conn *conn = hcon->l2cap_data;
 
@@ -4728,7 +4702,7 @@ static int l2cap_debugfs_show(struct seq_file *f, void *p)
 {
        struct l2cap_chan *c;
 
-       read_lock_bh(&chan_list_lock);
+       read_lock(&chan_list_lock);
 
        list_for_each_entry(c, &chan_list, global_l) {
                struct sock *sk = c->sk;
@@ -4741,7 +4715,7 @@ static int l2cap_debugfs_show(struct seq_file *f, void *p)
                                        c->sec_level, c->mode);
 }
 
-       read_unlock_bh(&chan_list_lock);
+       read_unlock(&chan_list_lock);
 
        return 0;
 }
@@ -4760,17 +4734,6 @@ static const struct file_operations l2cap_debugfs_fops = {
 
 static struct dentry *l2cap_debugfs;
 
-static struct hci_proto l2cap_hci_proto = {
-       .name           = "L2CAP",
-       .id             = HCI_PROTO_L2CAP,
-       .connect_ind    = l2cap_connect_ind,
-       .connect_cfm    = l2cap_connect_cfm,
-       .disconn_ind    = l2cap_disconn_ind,
-       .disconn_cfm    = l2cap_disconn_cfm,
-       .security_cfm   = l2cap_security_cfm,
-       .recv_acldata   = l2cap_recv_acldata
-};
-
 int __init l2cap_init(void)
 {
        int err;
@@ -4779,13 +4742,6 @@ int __init l2cap_init(void)
        if (err < 0)
                return err;
 
-       err = hci_register_proto(&l2cap_hci_proto);
-       if (err < 0) {
-               BT_ERR("L2CAP protocol registration failed");
-               bt_sock_unregister(BTPROTO_L2CAP);
-               goto error;
-       }
-
        if (bt_debugfs) {
                l2cap_debugfs = debugfs_create_file("l2cap", 0444,
                                        bt_debugfs, NULL, &l2cap_debugfs_fops);
@@ -4794,19 +4750,11 @@ int __init l2cap_init(void)
        }
 
        return 0;
-
-error:
-       l2cap_cleanup_sockets();
-       return err;
 }
 
 void l2cap_exit(void)
 {
        debugfs_remove(l2cap_debugfs);
-
-       if (hci_unregister_proto(&l2cap_hci_proto) < 0)
-               BT_ERR("L2CAP protocol unregistration failed");
-
        l2cap_cleanup_sockets();
 }