linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: bongsu.jeon2@gmail.com
To: shuah@kernel.org, krzysztof.kozlowski@canonical.com
Cc: netdev@vger.kernel.org, linux-nfc@lists.01.org,
	linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org,
	Bongsu Jeon <bongsu.jeon@samsung.com>
Subject: [PATCH v2 net-next 1/8] nfc: virtual_ncidev: Use wait queue instead of polling
Date: Tue, 17 Aug 2021 06:28:11 -0700	[thread overview]
Message-ID: <20210817132818.8275-2-bongsu.jeon2@gmail.com> (raw)
In-Reply-To: <20210817132818.8275-1-bongsu.jeon2@gmail.com>

From: Bongsu Jeon <bongsu.jeon@samsung.com>

In previous version, the user level virtual device application that used
this driver should have the polling scheme to read a NCI frame.
To remove this polling scheme, use Wait Queue.

Signed-off-by: Bongsu Jeon <bongsu.jeon@samsung.com>
---
 drivers/nfc/virtual_ncidev.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/nfc/virtual_ncidev.c b/drivers/nfc/virtual_ncidev.c
index 2ee0ec4bb739..221fa3bb8705 100644
--- a/drivers/nfc/virtual_ncidev.c
+++ b/drivers/nfc/virtual_ncidev.c
@@ -10,6 +10,7 @@
 #include <linux/module.h>
 #include <linux/miscdevice.h>
 #include <linux/mutex.h>
+#include <linux/wait.h>
 #include <net/nfc/nci_core.h>
 
 enum virtual_ncidev_mode {
@@ -27,6 +28,7 @@ enum virtual_ncidev_mode {
 				 NFC_PROTO_ISO15693_MASK)
 
 static enum virtual_ncidev_mode state;
+static DECLARE_WAIT_QUEUE_HEAD(wq);
 static struct miscdevice miscdev;
 static struct sk_buff *send_buff;
 static struct nci_dev *ndev;
@@ -61,6 +63,7 @@ static int virtual_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
 	}
 	send_buff = skb_copy(skb, GFP_KERNEL);
 	mutex_unlock(&nci_mutex);
+	wake_up_interruptible(&wq);
 
 	return 0;
 }
@@ -77,9 +80,11 @@ static ssize_t virtual_ncidev_read(struct file *file, char __user *buf,
 	size_t actual_len;
 
 	mutex_lock(&nci_mutex);
-	if (!send_buff) {
+	while (!send_buff) {
 		mutex_unlock(&nci_mutex);
-		return 0;
+		if (wait_event_interruptible(wq, send_buff))
+			return -EFAULT;
+		mutex_lock(&nci_mutex);
 	}
 
 	actual_len = min_t(size_t, count, send_buff->len);
-- 
2.32.0


  reply	other threads:[~2021-08-17 13:28 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-17 13:28 [PATCH v2 net-next 0/8] Update the virtual NCI device driver and add the NCI testcase bongsu.jeon2
2021-08-17 13:28 ` bongsu.jeon2 [this message]
2021-08-17 13:28 ` [PATCH v2 net-next 2/8] selftests: nci: Remove the polling code to read a NCI frame bongsu.jeon2
2021-08-17 13:28 ` [PATCH v2 net-next 3/8] selftests: nci: Fix the typo bongsu.jeon2
2021-08-17 13:28 ` [PATCH v2 net-next 4/8] selftests: nci: Fix the code for next nlattr offset bongsu.jeon2
2021-08-17 13:28 ` [PATCH v2 net-next 5/8] selftests: nci: Fix the wrong condition bongsu.jeon2
2021-08-17 13:28 ` [PATCH v2 net-next 6/8] selftests: nci: Add the flags parameter for the send_cmd_mt_nla bongsu.jeon2
2021-08-17 13:28 ` [PATCH v2 net-next 7/8] selftests: nci: Extract the start/stop discovery function bongsu.jeon2
2021-08-17 13:28 ` [PATCH v2 net-next 8/8] selftests: nci: Add the NCI testcase reading T4T Tag bongsu.jeon2
2021-08-18  9:40 ` [PATCH v2 net-next 0/8] Update the virtual NCI device driver and add the NCI testcase patchwork-bot+netdevbpf

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=20210817132818.8275-2-bongsu.jeon2@gmail.com \
    --to=bongsu.jeon2@gmail.com \
    --cc=bongsu.jeon@samsung.com \
    --cc=krzysztof.kozlowski@canonical.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-nfc@lists.01.org \
    --cc=netdev@vger.kernel.org \
    --cc=shuah@kernel.org \
    /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).