linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Samuel Ortiz <sameo@linux.intel.com>
To: "John W. Linville" <linville@tuxdriver.com>
Cc: Lauro Ramos Venancio <lauro.venancio@openbossa.org>,
	Aloisio Almeida Jr <aloisio.almeida@openbossa.org>,
	Ilan Elias <ilane@ti.com>,
	linux-wireless@vger.kernel.org, linux-nfc@lists.01.org,
	Samuel Ortiz <sameo@linux.intel.com>
Subject: [PATCH 22/33] NFC: Release LLCP SAP when the owner is released
Date: Fri,  6 Jul 2012 22:09:42 +0200	[thread overview]
Message-ID: <1341605393-32056-23-git-send-email-sameo@linux.intel.com> (raw)
In-Reply-To: <1341605393-32056-1-git-send-email-sameo@linux.intel.com>

The LLCP SAP should only be freed when the socket owning it is released.
As long as the socket is alive, the SAP should be reserved in order to
e.g. send the right wks array when bringing the MAC up.

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
---
 net/nfc/llcp/llcp.c |   13 -------------
 net/nfc/llcp/llcp.h |    3 +++
 net/nfc/llcp/sock.c |    9 ++++++++-
 3 files changed, 11 insertions(+), 14 deletions(-)

diff --git a/net/nfc/llcp/llcp.c b/net/nfc/llcp/llcp.c
index 0c8d25e..1031abd 100644
--- a/net/nfc/llcp/llcp.c
+++ b/net/nfc/llcp/llcp.c
@@ -131,17 +131,6 @@ int nfc_llcp_local_put(struct nfc_llcp_local *local)
 	return kref_put(&local->ref, local_release);
 }
 
-static void nfc_llcp_clear_sdp(struct nfc_llcp_local *local)
-{
-	mutex_lock(&local->sdp_lock);
-
-	local->local_wks = 0;
-	local->local_sdp = 0;
-	local->local_sap = 0;
-
-	mutex_unlock(&local->sdp_lock);
-}
-
 static void nfc_llcp_timeout_work(struct work_struct *work)
 {
 	struct nfc_llcp_local *local = container_of(work, struct nfc_llcp_local,
@@ -993,8 +982,6 @@ void nfc_llcp_mac_is_down(struct nfc_dev *dev)
 	if (local == NULL)
 		return;
 
-	nfc_llcp_clear_sdp(local);
-
 	/* Close and purge all existing sockets */
 	nfc_llcp_socket_release(local, true);
 }
diff --git a/net/nfc/llcp/llcp.h b/net/nfc/llcp/llcp.h
index 7286c86..374cc47 100644
--- a/net/nfc/llcp/llcp.h
+++ b/net/nfc/llcp/llcp.h
@@ -113,6 +113,9 @@ struct nfc_llcp_sock {
 	/* Is the remote peer ready to receive */
 	u8 remote_ready;
 
+	/* Reserved source SAP */
+	u8 reserved_ssap;
+
 	struct sk_buff_head tx_queue;
 	struct sk_buff_head tx_pending_queue;
 	struct sk_buff_head tx_backlog_queue;
diff --git a/net/nfc/llcp/sock.c b/net/nfc/llcp/sock.c
index b08e99d..211cb23 100644
--- a/net/nfc/llcp/sock.c
+++ b/net/nfc/llcp/sock.c
@@ -124,6 +124,8 @@ static int llcp_sock_bind(struct socket *sock, struct sockaddr *addr, int alen)
 	if (llcp_sock->ssap == LLCP_MAX_SAP)
 		goto put_dev;
 
+	llcp_sock->reserved_ssap = llcp_sock->ssap;
+
 	nfc_llcp_sock_link(&local->sockets, sk);
 
 	pr_debug("Socket bound to SAP %d\n", llcp_sock->ssap);
@@ -409,7 +411,8 @@ static int llcp_sock_release(struct socket *sock)
 		}
 	}
 
-	nfc_llcp_put_ssap(llcp_sock->local, llcp_sock->ssap);
+	if (llcp_sock->reserved_ssap < LLCP_SAP_MAX)
+		nfc_llcp_put_ssap(llcp_sock->local, llcp_sock->ssap);
 
 	release_sock(sk);
 
@@ -489,6 +492,9 @@ static int llcp_sock_connect(struct socket *sock, struct sockaddr *_addr,
 		ret = -ENOMEM;
 		goto put_dev;
 	}
+
+	llcp_sock->reserved_ssap = llcp_sock->ssap;
+
 	if (addr->service_name_len == 0)
 		llcp_sock->dsap = addr->dsap;
 	else
@@ -690,6 +696,7 @@ struct sock *nfc_llcp_sock_alloc(struct socket *sock, int type, gfp_t gfp)
 	llcp_sock->send_n = llcp_sock->send_ack_n = 0;
 	llcp_sock->recv_n = llcp_sock->recv_ack_n = 0;
 	llcp_sock->remote_ready = 1;
+	llcp_sock->reserved_ssap = LLCP_SAP_MAX;
 	skb_queue_head_init(&llcp_sock->tx_queue);
 	skb_queue_head_init(&llcp_sock->tx_pending_queue);
 	skb_queue_head_init(&llcp_sock->tx_backlog_queue);
-- 
1.7.10


  parent reply	other threads:[~2012-07-06 20:00 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-06 20:09 [PATCH 00/33] NFC updates for 3.6 Samuel Ortiz
2012-07-06 20:09 ` [PATCH 01/33] NFC: Prepare asynchronous error management for driver and shdlc Samuel Ortiz
2012-07-06 20:09 ` [PATCH 02/33] NFC: Removed addressed shdlc TODOs Samuel Ortiz
2012-07-06 20:09 ` [PATCH 03/33] NFC: Handle SHDLC RSET frames from an SHDLC connected chip Samuel Ortiz
2012-07-06 20:09 ` [PATCH 04/33] NFC: Remove an impossible HCI error case Samuel Ortiz
2012-07-06 20:09 ` [PATCH 05/33] NFC: Implement HCP reaggregation allocation " Samuel Ortiz
2012-07-06 20:09 ` [PATCH 06/33] NFC: Changed HCI cmd execution completion result to std linux errno Samuel Ortiz
2012-07-06 20:09 ` [PATCH 07/33] NFC: Driver failure API Samuel Ortiz
2012-07-06 20:09 ` [PATCH 08/33] NFC: Factorize HCI cmd completion Samuel Ortiz
2012-07-06 20:09 ` [PATCH 09/33] NFC: Implement HCI driver or internal error management Samuel Ortiz
2012-07-06 20:09 ` [PATCH 10/33] NFC: Core must test the device polling state inside the device lock Samuel Ortiz
2012-07-06 20:09 ` [PATCH 11/33] NFC: nfc_targets_found() should accept zero target found Samuel Ortiz
2012-07-06 20:09 ` [PATCH 12/33] NFC: nfc_driver_failure() implementation Samuel Ortiz
2012-07-06 20:09 ` [PATCH 13/33] NFC: Error management documentation Samuel Ortiz
2012-07-06 20:09 ` [PATCH 14/33] NFC: update PN544 HCI driver state when opened/closed Samuel Ortiz
2012-07-06 20:09 ` [PATCH 15/33] NFC: Allow HCI driver to pre-open pipes to some gates Samuel Ortiz
2012-07-06 20:09 ` [PATCH 16/33] NFC: Add modules alias for NFC sockets Samuel Ortiz
2012-07-06 20:09 ` [PATCH 17/33] NFC: Add netlink module alias for NFC Samuel Ortiz
2012-07-06 20:09 ` [PATCH 18/33] NFC: Update LLCP socket target index when getting a connection Samuel Ortiz
2012-07-06 20:09 ` [PATCH 19/33] NFC: Fix LLCP getname socket op Samuel Ortiz
2012-07-06 20:09 ` [PATCH 20/33] NFC: Build LLCP general bytes upon request Samuel Ortiz
2012-07-06 20:09 ` [PATCH 21/33] NFC: Close listening LLCP sockets when the device is gone Samuel Ortiz
2012-07-06 20:09 ` Samuel Ortiz [this message]
2012-07-06 20:09 ` [PATCH 23/33] NFC: Forbid LLCP service name reusing Samuel Ortiz
2012-07-06 20:09 ` [PATCH 24/33] NFC: Forbid SSAP binding to a not well known LLCP service Samuel Ortiz
2012-07-06 20:09 ` [PATCH 25/33] NFC: LLCP late binding Samuel Ortiz
2012-07-06 20:09 ` [PATCH 26/33] NFC: Handle LLCP Disconnected Mode frames Samuel Ortiz
2012-07-06 20:09 ` [PATCH 27/33] NFC: Remove warning from nfc_llcp_local_put Samuel Ortiz
2012-07-06 20:09 ` [PATCH 28/33] NFC: Do not return EBUSY when stopping a poll that's already stopped Samuel Ortiz
2012-07-06 20:09 ` [PATCH 29/33] NFC: Dereference LLCP bind socket address after checking for it to be NULL Samuel Ortiz
2012-07-06 20:09 ` [PATCH 30/33] NFC: Add initial Sony RC-S360 support to pn533 Samuel Ortiz
2012-07-06 20:09 ` [PATCH 31/33] NFC: Use communicate thru only for PaSoRi when trying to read Felica tags Samuel Ortiz
2012-07-06 20:09 ` [PATCH 32/33] NFC: Add ISO 14443 type B protocol Samuel Ortiz
2012-07-06 20:09 ` [PATCH 33/33] NFC: Check for llcp_sock and its device from llcp_sock_getname Samuel Ortiz

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1341605393-32056-23-git-send-email-sameo@linux.intel.com \
    --to=sameo@linux.intel.com \
    --cc=aloisio.almeida@openbossa.org \
    --cc=ilane@ti.com \
    --cc=lauro.venancio@openbossa.org \
    --cc=linux-nfc@lists.01.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=linville@tuxdriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).