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,
	Eric Lapuyade <eric.lapuyade@intel.com>,
	Samuel Ortiz <sameo@linux.intel.com>
Subject: [PATCH 04/20] NFC: Specify usage for targets found and target lost events
Date: Mon,  7 May 2012 12:31:15 +0200	[thread overview]
Message-ID: <1336386691-24840-5-git-send-email-sameo@linux.intel.com> (raw)
In-Reply-To: <1336386691-24840-1-git-send-email-sameo@linux.intel.com>

From: Eric Lapuyade <eric.lapuyade@intel.com>

It is now specified that nfc_target_found() and nfc_target_lost() core
functions must not be called from an atomic context. This allow us to
serialize calls and protect the targets table using the nfc device lock
instead of a spinlock.

Signed-off-by: Eric Lapuyade <eric.lapuyade@intel.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
---
 include/net/nfc/nfc.h |    1 -
 net/nfc/core.c        |   35 ++++++++++++++++++++++++++---------
 net/nfc/netlink.c     |    4 ++--
 3 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/include/net/nfc/nfc.h b/include/net/nfc/nfc.h
index 8ba1747..cee20aa 100644
--- a/include/net/nfc/nfc.h
+++ b/include/net/nfc/nfc.h
@@ -97,7 +97,6 @@ struct nfc_dev {
 	struct nfc_target *targets;
 	int n_targets;
 	int targets_generation;
-	spinlock_t targets_lock;
 	struct device dev;
 	bool dev_up;
 	bool polling;
diff --git a/net/nfc/core.c b/net/nfc/core.c
index 5d86f6c..02e1fda 100644
--- a/net/nfc/core.c
+++ b/net/nfc/core.c
@@ -501,6 +501,9 @@ EXPORT_SYMBOL(nfc_alloc_recv_skb);
  * The device driver must call this function when one or many nfc targets
  * are found. After calling this function, the device driver must stop
  * polling for targets.
+ * IMPORTANT: this function must not be called from an atomic context.
+ * In addition, it must also not be called from a context that would prevent
+ * the NFC Core to call other nfc ops entry point concurrently.
  */
 int nfc_targets_found(struct nfc_dev *dev,
 		      struct nfc_target *targets, int n_targets)
@@ -514,7 +517,7 @@ int nfc_targets_found(struct nfc_dev *dev,
 	for (i = 0; i < n_targets; i++)
 		targets[i].idx = dev->target_next_idx++;
 
-	spin_lock_bh(&dev->targets_lock);
+	device_lock(&dev->dev);
 
 	dev->targets_generation++;
 
@@ -524,12 +527,12 @@ int nfc_targets_found(struct nfc_dev *dev,
 
 	if (!dev->targets) {
 		dev->n_targets = 0;
-		spin_unlock_bh(&dev->targets_lock);
+		device_unlock(&dev->dev);
 		return -ENOMEM;
 	}
 
 	dev->n_targets = n_targets;
-	spin_unlock_bh(&dev->targets_lock);
+	device_unlock(&dev->dev);
 
 	nfc_genl_targets_found(dev);
 
@@ -537,6 +540,18 @@ int nfc_targets_found(struct nfc_dev *dev,
 }
 EXPORT_SYMBOL(nfc_targets_found);
 
+/**
+ * nfc_target_lost - inform that an activated target went out of field
+ *
+ * @dev: The nfc device that had the activated target in field
+ * @target_idx: the nfc index of the target
+ *
+ * The device driver must call this function when the activated target
+ * goes out of the field.
+ * IMPORTANT: this function must not be called from an atomic context.
+ * In addition, it must also not be called from a context that would prevent
+ * the NFC Core to call other nfc ops entry point concurrently.
+ */
 int nfc_target_lost(struct nfc_dev *dev, u32 target_idx)
 {
 	struct nfc_target *tg;
@@ -544,7 +559,7 @@ int nfc_target_lost(struct nfc_dev *dev, u32 target_idx)
 
 	pr_debug("dev_name %s n_target %d\n", dev_name(&dev->dev), target_idx);
 
-	spin_lock_bh(&dev->targets_lock);
+	device_lock(&dev->dev);
 
 	for (i = 0; i < dev->n_targets; i++) {
 		tg = &dev->targets[i];
@@ -553,7 +568,7 @@ int nfc_target_lost(struct nfc_dev *dev, u32 target_idx)
 	}
 
 	if (i == dev->n_targets) {
-		spin_unlock_bh(&dev->targets_lock);
+		device_unlock(&dev->dev);
 		return -EINVAL;
 	}
 
@@ -569,7 +584,7 @@ int nfc_target_lost(struct nfc_dev *dev, u32 target_idx)
 		dev->targets = NULL;
 	}
 
-	spin_unlock_bh(&dev->targets_lock);
+	device_unlock(&dev->dev);
 
 	nfc_genl_target_lost(dev, target_idx);
 
@@ -607,8 +622,10 @@ static void nfc_check_pres_work(struct work_struct *work)
 			mod_timer(&dev->check_pres_timer, jiffies +
 				  msecs_to_jiffies(NFC_CHECK_PRES_FREQ_MS));
 		} else {
-			nfc_target_lost(dev, dev->active_target->idx);
-			dev->active_target = NULL;
+			u32 active_target_idx = dev->active_target->idx;
+			device_unlock(&dev->dev);
+			nfc_target_lost(dev, active_target_idx);
+			return;
 		}
 	}
 
@@ -681,9 +698,9 @@ struct nfc_dev *nfc_allocate_device(struct nfc_ops *ops,
 	dev->tx_headroom = tx_headroom;
 	dev->tx_tailroom = tx_tailroom;
 
-	spin_lock_init(&dev->targets_lock);
 	nfc_genl_data_init(&dev->genl_data);
 
+
 	/* first generation must not be 0 */
 	dev->targets_generation = 1;
 
diff --git a/net/nfc/netlink.c b/net/nfc/netlink.c
index 6c558bc..cc89e4f 100644
--- a/net/nfc/netlink.c
+++ b/net/nfc/netlink.c
@@ -124,7 +124,7 @@ static int nfc_genl_dump_targets(struct sk_buff *skb,
 		cb->args[1] = (long) dev;
 	}
 
-	spin_lock_bh(&dev->targets_lock);
+	device_lock(&dev->dev);
 
 	cb->seq = dev->targets_generation;
 
@@ -137,7 +137,7 @@ static int nfc_genl_dump_targets(struct sk_buff *skb,
 		i++;
 	}
 
-	spin_unlock_bh(&dev->targets_lock);
+	device_unlock(&dev->dev);
 
 	cb->args[0] = i;
 
-- 
1.7.9.1


  parent reply	other threads:[~2012-05-07 10:32 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-07 10:31 [PATCH 00/20] NFC updates for 3.5 Samuel Ortiz
2012-05-07 10:31 ` [PATCH 01/20] NFC: Fix up for NLA_PUT_ api changes Samuel Ortiz
2012-05-07 13:01   ` Stephen Rothwell
2012-05-07 10:31 ` [PATCH 02/20] NFC: Cache the core NFC active target pointer instead of its index Samuel Ortiz
2012-05-07 10:31 ` [PATCH 03/20] NFC: Remove useless HCI private nfc target table Samuel Ortiz
2012-05-07 10:31 ` Samuel Ortiz [this message]
2012-05-07 10:31 ` [PATCH 05/20] NFC: Add HCI/SHDLC support to let driver check for tag presence Samuel Ortiz
2012-05-07 10:31 ` [PATCH 06/20] NFC: Update Documentation/nfc-hci.txt Samuel Ortiz
2012-05-07 10:31 ` [PATCH 07/20] NFC: Remove unneeded pn533 dev NULL check Samuel Ortiz
2012-05-07 10:31 ` [PATCH 08/20] NFC: LLCP connect must wait for a CC frame Samuel Ortiz
2012-05-07 10:31 ` [PATCH 09/20] NFC: Update the LLCP poll mask Samuel Ortiz
2012-05-07 10:31 ` [PATCH 10/20] NFC: Return the amount of LLCP bytes queued to sock_sendmsg Samuel Ortiz
2012-05-07 10:31 ` [PATCH 11/20] NFC: Send device index instead of its name when target is lost Samuel Ortiz
2012-05-07 10:31 ` [PATCH 12/20] NFC: Fix LLCP compilation warning Samuel Ortiz
2012-05-07 10:31 ` [PATCH 13/20] NFC: Quiet nci/data.c sparse noise about plain integer as NULL pointer Samuel Ortiz
2012-05-07 10:31 ` [PATCH 14/20] NFC: Include nci_core.h to nci/lib.c Samuel Ortiz
2012-05-07 10:31 ` [PATCH 15/20] NFC: Quiet nci/ntf.c sparse noise about plain integer as NULL pointer Samuel Ortiz
2012-05-07 10:31 ` [PATCH 16/20] NFC: HCI ops should not be exposed globally Samuel Ortiz
2012-05-07 10:31 ` [PATCH 17/20] NFC: The NFC genl family structure " Samuel Ortiz
2012-05-07 10:31 ` [PATCH 18/20] NFC: HCI based pn544 driver Samuel Ortiz
2012-05-07 10:31 ` [PATCH 19/20] feature-removal: Remove pn544 raw driver Samuel Ortiz
2012-05-07 10:31 ` [PATCH 20/20] NFC: HCI drivers don't have to keep track of polling state 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=1336386691-24840-5-git-send-email-sameo@linux.intel.com \
    --to=sameo@linux.intel.com \
    --cc=aloisio.almeida@openbossa.org \
    --cc=eric.lapuyade@intel.com \
    --cc=ilane@ti.com \
    --cc=lauro.venancio@openbossa.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).