Skip to content

Commit d01b2ff

Browse files
author
Gustavo F. Padovan
committed
Bluetooth: convert chan_lock to mutex
spin lock doesn't fit ok anymore on the new code based on workqueues. Acked-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Gustavo F. Padovan <padovan@profusion.mobi>
1 parent 67d0dfb commit d01b2ff

2 files changed

Lines changed: 27 additions & 27 deletions

File tree

‎include/net/bluetooth/l2cap.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ struct l2cap_conn {
536536
struct smp_chan *smp_chan;
537537

538538
struct list_head chan_l;
539-
rwlock_t chan_lock;
539+
struct mutex chan_lock;
540540
};
541541

542542
#define L2CAP_INFO_CL_MTU_REQ_SENT 0x01

‎net/bluetooth/l2cap_core.c‎

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,11 @@ static struct l2cap_chan *l2cap_get_chan_by_scid(struct l2cap_conn *conn, u16 ci
115115
{
116116
struct l2cap_chan *c;
117117

118-
read_lock(&conn->chan_lock);
118+
mutex_lock(&conn->chan_lock);
119119
c = __l2cap_get_chan_by_scid(conn, cid);
120120
if (c)
121121
lock_sock(c->sk);
122-
read_unlock(&conn->chan_lock);
122+
mutex_unlock(&conn->chan_lock);
123123
return c;
124124
}
125125

@@ -138,11 +138,11 @@ static inline struct l2cap_chan *l2cap_get_chan_by_ident(struct l2cap_conn *conn
138138
{
139139
struct l2cap_chan *c;
140140

141-
read_lock(&conn->chan_lock);
141+
mutex_lock(&conn->chan_lock);
142142
c = __l2cap_get_chan_by_ident(conn, ident);
143143
if (c)
144144
lock_sock(c->sk);
145-
read_unlock(&conn->chan_lock);
145+
mutex_unlock(&conn->chan_lock);
146146
return c;
147147
}
148148

@@ -381,9 +381,9 @@ static void l2cap_chan_del(struct l2cap_chan *chan, int err)
381381

382382
if (conn) {
383383
/* Delete from channel list */
384-
write_lock_bh(&conn->chan_lock);
384+
mutex_lock(&conn->chan_lock);
385385
list_del(&chan->list);
386-
write_unlock_bh(&conn->chan_lock);
386+
mutex_unlock(&conn->chan_lock);
387387
chan_put(chan);
388388

389389
chan->conn = NULL;
@@ -754,7 +754,7 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
754754

755755
BT_DBG("conn %p", conn);
756756

757-
read_lock(&conn->chan_lock);
757+
mutex_lock(&conn->chan_lock);
758758

759759
list_for_each_entry_safe(chan, tmp, &conn->chan_l, list) {
760760
struct sock *sk = chan->sk;
@@ -780,9 +780,9 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
780780
&chan->conf_state)) {
781781
/* l2cap_chan_close() calls list_del(chan)
782782
* so release the lock */
783-
read_unlock(&conn->chan_lock);
783+
mutex_unlock(&conn->chan_lock);
784784
l2cap_chan_close(chan, ECONNRESET);
785-
read_lock(&conn->chan_lock);
785+
utex_lock(&conn->chan_lock);
786786
bh_unlock_sock(sk);
787787
continue;
788788
}
@@ -838,7 +838,7 @@ static void l2cap_conn_start(struct l2cap_conn *conn)
838838
bh_unlock_sock(sk);
839839
}
840840

841-
read_unlock(&conn->chan_lock);
841+
mutex_unlock(&conn->chan_lock);
842842
}
843843

844844
/* Find socket with cid and source bdaddr.
@@ -903,7 +903,7 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn)
903903

904904
sk = chan->sk;
905905

906-
write_lock_bh(&conn->chan_lock);
906+
mutex_lock(&conn->chan_lock);
907907

908908
hci_conn_hold(conn->hcon);
909909

@@ -919,7 +919,7 @@ static void l2cap_le_conn_ready(struct l2cap_conn *conn)
919919
l2cap_state_change(chan, BT_CONNECTED);
920920
parent->sk_data_ready(parent, 0);
921921

922-
write_unlock_bh(&conn->chan_lock);
922+
mutex_unlock(&conn->chan_lock);
923923

924924
clean:
925925
release_sock(parent);
@@ -954,7 +954,7 @@ static void l2cap_conn_ready(struct l2cap_conn *conn)
954954
if (conn->hcon->out && conn->hcon->type == LE_LINK)
955955
smp_conn_security(conn, conn->hcon->pending_sec_level);
956956

957-
read_lock(&conn->chan_lock);
957+
mutex_lock(&conn->chan_lock);
958958

959959
list_for_each_entry(chan, &conn->chan_l, list) {
960960
struct sock *sk = chan->sk;
@@ -976,7 +976,7 @@ static void l2cap_conn_ready(struct l2cap_conn *conn)
976976
bh_unlock_sock(sk);
977977
}
978978

979-
read_unlock(&conn->chan_lock);
979+
mutex_unlock(&conn->chan_lock);
980980
}
981981

982982
/* Notify sockets that we cannot guaranty reliability anymore */
@@ -986,7 +986,7 @@ static void l2cap_conn_unreliable(struct l2cap_conn *conn, int err)
986986

987987
BT_DBG("conn %p", conn);
988988

989-
read_lock(&conn->chan_lock);
989+
mutex_lock(&conn->chan_lock);
990990

991991
list_for_each_entry(chan, &conn->chan_l, list) {
992992
struct sock *sk = chan->sk;
@@ -995,7 +995,7 @@ static void l2cap_conn_unreliable(struct l2cap_conn *conn, int err)
995995
sk->sk_err = err;
996996
}
997997

998-
read_unlock(&conn->chan_lock);
998+
mutex_unlock(&conn->chan_lock);
999999
}
10001000

10011001
static void l2cap_info_timeout(unsigned long arg)
@@ -1086,7 +1086,7 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon, u8 status)
10861086
conn->feat_mask = 0;
10871087

10881088
spin_lock_init(&conn->lock);
1089-
rwlock_init(&conn->chan_lock);
1089+
mutex_init(&conn->chan_lock);
10901090

10911091
INIT_LIST_HEAD(&conn->chan_l);
10921092

@@ -1104,9 +1104,9 @@ static struct l2cap_conn *l2cap_conn_add(struct hci_conn *hcon, u8 status)
11041104

11051105
static inline void l2cap_chan_add(struct l2cap_conn *conn, struct l2cap_chan *chan)
11061106
{
1107-
write_lock_bh(&conn->chan_lock);
1107+
mutex_lock(&conn->chan_lock);
11081108
__l2cap_chan_add(conn, chan);
1109-
write_unlock_bh(&conn->chan_lock);
1109+
mutex_unlock(&conn->chan_lock);
11101110
}
11111111

11121112
/* ---- Socket interface ---- */
@@ -1771,7 +1771,7 @@ static void l2cap_raw_recv(struct l2cap_conn *conn, struct sk_buff *skb)
17711771

17721772
BT_DBG("conn %p", conn);
17731773

1774-
read_lock(&conn->chan_lock);
1774+
mutex_lock(&conn->chan_lock);
17751775
list_for_each_entry(chan, &conn->chan_l, list) {
17761776
struct sock *sk = chan->sk;
17771777
if (chan->chan_type != L2CAP_CHAN_RAW)
@@ -1787,7 +1787,7 @@ static void l2cap_raw_recv(struct l2cap_conn *conn, struct sk_buff *skb)
17871787
if (chan->ops->recv(chan->data, nskb))
17881788
kfree_skb(nskb);
17891789
}
1790-
read_unlock(&conn->chan_lock);
1790+
mutex_unlock(&conn->chan_lock);
17911791
}
17921792

17931793
/* ---- L2CAP signalling commands ---- */
@@ -2587,11 +2587,11 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd
25872587

25882588
sk = chan->sk;
25892589

2590-
write_lock_bh(&conn->chan_lock);
2590+
mutex_lock(&conn->chan_lock);
25912591

25922592
/* Check if we already have channel with that dcid */
25932593
if (__l2cap_get_chan_by_dcid(conn, scid)) {
2594-
write_unlock_bh(&conn->chan_lock);
2594+
mutex_unlock(&conn->chan_lock);
25952595
sock_set_flag(sk, SOCK_ZAPPED);
25962596
chan->ops->close(chan->data);
25972597
goto response;
@@ -2637,7 +2637,7 @@ static inline int l2cap_connect_req(struct l2cap_conn *conn, struct l2cap_cmd_hd
26372637
status = L2CAP_CS_NO_INFO;
26382638
}
26392639

2640-
write_unlock_bh(&conn->chan_lock);
2640+
mutex_unlock(&conn->chan_lock);
26412641

26422642
response:
26432643
release_sock(parent);
@@ -4474,7 +4474,7 @@ static int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
44744474
del_timer(&conn->security_timer);
44754475
}
44764476

4477-
read_lock(&conn->chan_lock);
4477+
mutex_lock(&conn->chan_lock);
44784478

44794479
list_for_each_entry(chan, &conn->chan_l, list) {
44804480
struct sock *sk = chan->sk;
@@ -4554,7 +4554,7 @@ static int l2cap_security_cfm(struct hci_conn *hcon, u8 status, u8 encrypt)
45544554
bh_unlock_sock(sk);
45554555
}
45564556

4557-
read_unlock(&conn->chan_lock);
4557+
mutex_unlock(&conn->chan_lock);
45584558

45594559
return 0;
45604560
}

0 commit comments

Comments
 (0)