Commit 8675569d authored by Bongsu Jeon's avatar Bongsu Jeon Committed by David S. Miller

nfc: virtual_ncidev: Use wait queue instead of polling

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: default avatarBongsu Jeon <bongsu.jeon@samsung.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent ec18e845
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/miscdevice.h> #include <linux/miscdevice.h>
#include <linux/mutex.h> #include <linux/mutex.h>
#include <linux/wait.h>
#include <net/nfc/nci_core.h> #include <net/nfc/nci_core.h>
enum virtual_ncidev_mode { enum virtual_ncidev_mode {
...@@ -27,6 +28,7 @@ enum virtual_ncidev_mode { ...@@ -27,6 +28,7 @@ enum virtual_ncidev_mode {
NFC_PROTO_ISO15693_MASK) NFC_PROTO_ISO15693_MASK)
static enum virtual_ncidev_mode state; static enum virtual_ncidev_mode state;
static DECLARE_WAIT_QUEUE_HEAD(wq);
static struct miscdevice miscdev; static struct miscdevice miscdev;
static struct sk_buff *send_buff; static struct sk_buff *send_buff;
static struct nci_dev *ndev; static struct nci_dev *ndev;
...@@ -61,6 +63,7 @@ static int virtual_nci_send(struct nci_dev *ndev, struct sk_buff *skb) ...@@ -61,6 +63,7 @@ static int virtual_nci_send(struct nci_dev *ndev, struct sk_buff *skb)
} }
send_buff = skb_copy(skb, GFP_KERNEL); send_buff = skb_copy(skb, GFP_KERNEL);
mutex_unlock(&nci_mutex); mutex_unlock(&nci_mutex);
wake_up_interruptible(&wq);
return 0; return 0;
} }
...@@ -77,9 +80,11 @@ static ssize_t virtual_ncidev_read(struct file *file, char __user *buf, ...@@ -77,9 +80,11 @@ static ssize_t virtual_ncidev_read(struct file *file, char __user *buf,
size_t actual_len; size_t actual_len;
mutex_lock(&nci_mutex); mutex_lock(&nci_mutex);
if (!send_buff) { while (!send_buff) {
mutex_unlock(&nci_mutex); 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); actual_len = min_t(size_t, count, send_buff->len);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment