Skip to content

Commit

Permalink
nfc: virtual_ncidev: Use wait queue instead of polling
Browse files Browse the repository at this point in the history
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>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Bongsu Jeon authored and David S. Miller committed Aug 18, 2021
1 parent ec18e84 commit 8675569
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions drivers/nfc/virtual_ncidev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down

0 comments on commit 8675569

Please sign in to comment.