aboutsummaryrefslogtreecommitdiffstats
path: root/net/bluetooth/l2cap_sock.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/bluetooth/l2cap_sock.c')
-rw-r--r--net/bluetooth/l2cap_sock.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 5c36b3e8739c..5c406d3136f7 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -26,6 +26,9 @@
26 26
27/* Bluetooth L2CAP sockets. */ 27/* Bluetooth L2CAP sockets. */
28 28
29#include <linux/security.h>
30#include <linux/export.h>
31
29#include <net/bluetooth/bluetooth.h> 32#include <net/bluetooth/bluetooth.h>
30#include <net/bluetooth/hci_core.h> 33#include <net/bluetooth/hci_core.h>
31#include <net/bluetooth/l2cap.h> 34#include <net/bluetooth/l2cap.h>
@@ -235,30 +238,26 @@ static int l2cap_sock_accept(struct socket *sock, struct socket *newsock, int fl
235 238
236 lock_sock_nested(sk, SINGLE_DEPTH_NESTING); 239 lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
237 240
238 if (sk->sk_state != BT_LISTEN) {
239 err = -EBADFD;
240 goto done;
241 }
242
243 timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK); 241 timeo = sock_rcvtimeo(sk, flags & O_NONBLOCK);
244 242
245 BT_DBG("sk %p timeo %ld", sk, timeo); 243 BT_DBG("sk %p timeo %ld", sk, timeo);
246 244
247 /* Wait for an incoming connection. (wake-one). */ 245 /* Wait for an incoming connection. (wake-one). */
248 add_wait_queue_exclusive(sk_sleep(sk), &wait); 246 add_wait_queue_exclusive(sk_sleep(sk), &wait);
249 while (!(nsk = bt_accept_dequeue(sk, newsock))) { 247 while (1) {
250 set_current_state(TASK_INTERRUPTIBLE); 248 set_current_state(TASK_INTERRUPTIBLE);
251 if (!timeo) { 249
252 err = -EAGAIN; 250 if (sk->sk_state != BT_LISTEN) {
251 err = -EBADFD;
253 break; 252 break;
254 } 253 }
255 254
256 release_sock(sk); 255 nsk = bt_accept_dequeue(sk, newsock);
257 timeo = schedule_timeout(timeo); 256 if (nsk)
258 lock_sock_nested(sk, SINGLE_DEPTH_NESTING); 257 break;
259 258
260 if (sk->sk_state != BT_LISTEN) { 259 if (!timeo) {
261 err = -EBADFD; 260 err = -EAGAIN;
262 break; 261 break;
263 } 262 }
264 263
@@ -266,8 +265,12 @@ static int l2cap_sock_accept(struct socket *sock, struct socket *newsock, int fl
266 err = sock_intr_errno(timeo); 265 err = sock_intr_errno(timeo);
267 break; 266 break;
268 } 267 }
268
269 release_sock(sk);
270 timeo = schedule_timeout(timeo);
271 lock_sock_nested(sk, SINGLE_DEPTH_NESTING);
269 } 272 }
270 set_current_state(TASK_RUNNING); 273 __set_current_state(TASK_RUNNING);
271 remove_wait_queue(sk_sleep(sk), &wait); 274 remove_wait_queue(sk_sleep(sk), &wait);
272 275
273 if (err) 276 if (err)
@@ -933,6 +936,8 @@ static void l2cap_sock_init(struct sock *sk, struct sock *parent)
933 chan->force_reliable = pchan->force_reliable; 936 chan->force_reliable = pchan->force_reliable;
934 chan->flushable = pchan->flushable; 937 chan->flushable = pchan->flushable;
935 chan->force_active = pchan->force_active; 938 chan->force_active = pchan->force_active;
939
940 security_sk_clone(parent, sk);
936 } else { 941 } else {
937 942
938 switch (sk->sk_type) { 943 switch (sk->sk_type) {
@@ -993,7 +998,7 @@ static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock, int p
993 INIT_LIST_HEAD(&bt_sk(sk)->accept_q); 998 INIT_LIST_HEAD(&bt_sk(sk)->accept_q);
994 999
995 sk->sk_destruct = l2cap_sock_destruct; 1000 sk->sk_destruct = l2cap_sock_destruct;
996 sk->sk_sndtimeo = msecs_to_jiffies(L2CAP_CONN_TIMEOUT); 1001 sk->sk_sndtimeo = L2CAP_CONN_TIMEOUT;
997 1002
998 sock_reset_flag(sk, SOCK_ZAPPED); 1003 sock_reset_flag(sk, SOCK_ZAPPED);
999 1004