aboutsummaryrefslogtreecommitdiffstats
path: root/net/nfc/llcp/sock.c
diff options
context:
space:
mode:
authorSamuel Ortiz <sameo@linux.intel.com>2012-05-04 11:04:19 -0400
committerSamuel Ortiz <sameo@linux.intel.com>2012-06-04 15:34:28 -0400
commita69f32af86e389dd232b1bb2269e202c1bfcc60f (patch)
tree8639421ba70c67ac09f72323a4e5dca2b71e37e7 /net/nfc/llcp/sock.c
parentc7aa12252f5142b9eee2f6e34ca8870a8e7e048c (diff)
NFC: Socket linked list
Simplify the LLCP sockets structure by putting all the connected ones into a single linked list. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
Diffstat (limited to 'net/nfc/llcp/sock.c')
-rw-r--r--net/nfc/llcp/sock.c32
1 files changed, 12 insertions, 20 deletions
diff --git a/net/nfc/llcp/sock.c b/net/nfc/llcp/sock.c
index 9ac397b17718..8a60b53579b9 100644
--- a/net/nfc/llcp/sock.c
+++ b/net/nfc/llcp/sock.c
@@ -124,7 +124,7 @@ static int llcp_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
124 if (llcp_sock->ssap == LLCP_MAX_SAP) 124 if (llcp_sock->ssap == LLCP_MAX_SAP)
125 goto put_dev; 125 goto put_dev;
126 126
127 local->sockets[llcp_sock->ssap] = llcp_sock; 127 nfc_llcp_sock_link(&local->sockets, sk);
128 128
129 pr_debug("Socket bound to SAP %d\n", llcp_sock->ssap); 129 pr_debug("Socket bound to SAP %d\n", llcp_sock->ssap);
130 130
@@ -379,15 +379,6 @@ static int llcp_sock_release(struct socket *sock)
379 goto out; 379 goto out;
380 } 380 }
381 381
382 mutex_lock(&local->socket_lock);
383
384 if (llcp_sock == local->sockets[llcp_sock->ssap])
385 local->sockets[llcp_sock->ssap] = NULL;
386 else
387 list_del_init(&llcp_sock->list);
388
389 mutex_unlock(&local->socket_lock);
390
391 lock_sock(sk); 382 lock_sock(sk);
392 383
393 /* Send a DISC */ 384 /* Send a DISC */
@@ -412,14 +403,12 @@ static int llcp_sock_release(struct socket *sock)
412 } 403 }
413 } 404 }
414 405
415 /* Freeing the SAP */ 406 nfc_llcp_put_ssap(llcp_sock->local, llcp_sock->ssap);
416 if ((sk->sk_state == LLCP_CONNECTED
417 && llcp_sock->ssap > LLCP_LOCAL_SAP_OFFSET) ||
418 sk->sk_state == LLCP_BOUND || sk->sk_state == LLCP_LISTEN)
419 nfc_llcp_put_ssap(llcp_sock->local, llcp_sock->ssap);
420 407
421 release_sock(sk); 408 release_sock(sk);
422 409
410 nfc_llcp_sock_unlink(&local->sockets, sk);
411
423out: 412out:
424 sock_orphan(sk); 413 sock_orphan(sk);
425 sock_put(sk); 414 sock_put(sk);
@@ -505,21 +494,26 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr,
505 llcp_sock->service_name_len, 494 llcp_sock->service_name_len,
506 GFP_KERNEL); 495 GFP_KERNEL);
507 496
508 local->sockets[llcp_sock->ssap] = llcp_sock; 497 nfc_llcp_sock_link(&local->connecting_sockets, sk);
509 498
510 ret = nfc_llcp_send_connect(llcp_sock); 499 ret = nfc_llcp_send_connect(llcp_sock);
511 if (ret) 500 if (ret)
512 goto put_dev; 501 goto sock_unlink;
513 502
514 ret = sock_wait_state(sk, LLCP_CONNECTED, 503 ret = sock_wait_state(sk, LLCP_CONNECTED,
515 sock_sndtimeo(sk, flags & O_NONBLOCK)); 504 sock_sndtimeo(sk, flags & O_NONBLOCK));
516 if (ret) 505 if (ret)
517 goto put_dev; 506 goto sock_unlink;
518 507
519 release_sock(sk); 508 release_sock(sk);
520 509
521 return 0; 510 return 0;
522 511
512sock_unlink:
513 nfc_llcp_put_ssap(local, llcp_sock->ssap);
514
515 nfc_llcp_sock_unlink(&local->connecting_sockets, sk);
516
523put_dev: 517put_dev:
524 nfc_put_device(dev); 518 nfc_put_device(dev);
525 519
@@ -690,7 +684,6 @@ struct sock *nfc_llcp_sock_alloc(struct socket *sock, int type, gfp_t gfp)
690 skb_queue_head_init(&llcp_sock->tx_queue); 684 skb_queue_head_init(&llcp_sock->tx_queue);
691 skb_queue_head_init(&llcp_sock->tx_pending_queue); 685 skb_queue_head_init(&llcp_sock->tx_pending_queue);
692 skb_queue_head_init(&llcp_sock->tx_backlog_queue); 686 skb_queue_head_init(&llcp_sock->tx_backlog_queue);
693 INIT_LIST_HEAD(&llcp_sock->list);
694 INIT_LIST_HEAD(&llcp_sock->accept_queue); 687 INIT_LIST_HEAD(&llcp_sock->accept_queue);
695 688
696 if (sock != NULL) 689 if (sock != NULL)
@@ -708,7 +701,6 @@ void nfc_llcp_sock_free(struct nfc_llcp_sock *sock)
708 skb_queue_purge(&sock->tx_backlog_queue); 701 skb_queue_purge(&sock->tx_backlog_queue);
709 702
710 list_del_init(&sock->accept_queue); 703 list_del_init(&sock->accept_queue);
711 list_del_init(&sock->list);
712 704
713 sock->parent = NULL; 705 sock->parent = NULL;
714 706