aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iio/industrialio-event.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/iio/industrialio-event.c')
-rw-r--r--drivers/iio/industrialio-event.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/drivers/iio/industrialio-event.c b/drivers/iio/industrialio-event.c
index 261cae00557e..10aa9ef86cec 100644
--- a/drivers/iio/industrialio-event.c
+++ b/drivers/iio/industrialio-event.c
@@ -46,10 +46,11 @@ int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp)
46{ 46{
47 struct iio_event_interface *ev_int = indio_dev->event_interface; 47 struct iio_event_interface *ev_int = indio_dev->event_interface;
48 struct iio_event_data ev; 48 struct iio_event_data ev;
49 unsigned long flags;
49 int copied; 50 int copied;
50 51
51 /* Does anyone care? */ 52 /* Does anyone care? */
52 spin_lock(&ev_int->wait.lock); 53 spin_lock_irqsave(&ev_int->wait.lock, flags);
53 if (test_bit(IIO_BUSY_BIT_POS, &ev_int->flags)) { 54 if (test_bit(IIO_BUSY_BIT_POS, &ev_int->flags)) {
54 55
55 ev.id = ev_code; 56 ev.id = ev_code;
@@ -59,7 +60,7 @@ int iio_push_event(struct iio_dev *indio_dev, u64 ev_code, s64 timestamp)
59 if (copied != 0) 60 if (copied != 0)
60 wake_up_locked_poll(&ev_int->wait, POLLIN); 61 wake_up_locked_poll(&ev_int->wait, POLLIN);
61 } 62 }
62 spin_unlock(&ev_int->wait.lock); 63 spin_unlock_irqrestore(&ev_int->wait.lock, flags);
63 64
64 return 0; 65 return 0;
65} 66}
@@ -76,10 +77,10 @@ static unsigned int iio_event_poll(struct file *filep,
76 77
77 poll_wait(filep, &ev_int->wait, wait); 78 poll_wait(filep, &ev_int->wait, wait);
78 79
79 spin_lock(&ev_int->wait.lock); 80 spin_lock_irq(&ev_int->wait.lock);
80 if (!kfifo_is_empty(&ev_int->det_events)) 81 if (!kfifo_is_empty(&ev_int->det_events))
81 events = POLLIN | POLLRDNORM; 82 events = POLLIN | POLLRDNORM;
82 spin_unlock(&ev_int->wait.lock); 83 spin_unlock_irq(&ev_int->wait.lock);
83 84
84 return events; 85 return events;
85} 86}
@@ -96,14 +97,14 @@ static ssize_t iio_event_chrdev_read(struct file *filep,
96 if (count < sizeof(struct iio_event_data)) 97 if (count < sizeof(struct iio_event_data))
97 return -EINVAL; 98 return -EINVAL;
98 99
99 spin_lock(&ev_int->wait.lock); 100 spin_lock_irq(&ev_int->wait.lock);
100 if (kfifo_is_empty(&ev_int->det_events)) { 101 if (kfifo_is_empty(&ev_int->det_events)) {
101 if (filep->f_flags & O_NONBLOCK) { 102 if (filep->f_flags & O_NONBLOCK) {
102 ret = -EAGAIN; 103 ret = -EAGAIN;
103 goto error_unlock; 104 goto error_unlock;
104 } 105 }
105 /* Blocking on device; waiting for something to be there */ 106 /* Blocking on device; waiting for something to be there */
106 ret = wait_event_interruptible_locked(ev_int->wait, 107 ret = wait_event_interruptible_locked_irq(ev_int->wait,
107 !kfifo_is_empty(&ev_int->det_events)); 108 !kfifo_is_empty(&ev_int->det_events));
108 if (ret) 109 if (ret)
109 goto error_unlock; 110 goto error_unlock;
@@ -113,7 +114,7 @@ static ssize_t iio_event_chrdev_read(struct file *filep,
113 ret = kfifo_to_user(&ev_int->det_events, buf, count, &copied); 114 ret = kfifo_to_user(&ev_int->det_events, buf, count, &copied);
114 115
115error_unlock: 116error_unlock:
116 spin_unlock(&ev_int->wait.lock); 117 spin_unlock_irq(&ev_int->wait.lock);
117 118
118 return ret ? ret : copied; 119 return ret ? ret : copied;
119} 120}
@@ -122,7 +123,7 @@ static int iio_event_chrdev_release(struct inode *inode, struct file *filep)
122{ 123{
123 struct iio_event_interface *ev_int = filep->private_data; 124 struct iio_event_interface *ev_int = filep->private_data;
124 125
125 spin_lock(&ev_int->wait.lock); 126 spin_lock_irq(&ev_int->wait.lock);
126 __clear_bit(IIO_BUSY_BIT_POS, &ev_int->flags); 127 __clear_bit(IIO_BUSY_BIT_POS, &ev_int->flags);
127 /* 128 /*
128 * In order to maintain a clean state for reopening, 129 * In order to maintain a clean state for reopening,
@@ -130,7 +131,7 @@ static int iio_event_chrdev_release(struct inode *inode, struct file *filep)
130 * any new __iio_push_event calls running. 131 * any new __iio_push_event calls running.
131 */ 132 */
132 kfifo_reset_out(&ev_int->det_events); 133 kfifo_reset_out(&ev_int->det_events);
133 spin_unlock(&ev_int->wait.lock); 134 spin_unlock_irq(&ev_int->wait.lock);
134 135
135 return 0; 136 return 0;
136} 137}
@@ -151,18 +152,18 @@ int iio_event_getfd(struct iio_dev *indio_dev)
151 if (ev_int == NULL) 152 if (ev_int == NULL)
152 return -ENODEV; 153 return -ENODEV;
153 154
154 spin_lock(&ev_int->wait.lock); 155 spin_lock_irq(&ev_int->wait.lock);
155 if (__test_and_set_bit(IIO_BUSY_BIT_POS, &ev_int->flags)) { 156 if (__test_and_set_bit(IIO_BUSY_BIT_POS, &ev_int->flags)) {
156 spin_unlock(&ev_int->wait.lock); 157 spin_unlock_irq(&ev_int->wait.lock);
157 return -EBUSY; 158 return -EBUSY;
158 } 159 }
159 spin_unlock(&ev_int->wait.lock); 160 spin_unlock_irq(&ev_int->wait.lock);
160 fd = anon_inode_getfd("iio:event", 161 fd = anon_inode_getfd("iio:event",
161 &iio_event_chrdev_fileops, ev_int, O_RDONLY); 162 &iio_event_chrdev_fileops, ev_int, O_RDONLY);
162 if (fd < 0) { 163 if (fd < 0) {
163 spin_lock(&ev_int->wait.lock); 164 spin_lock_irq(&ev_int->wait.lock);
164 __clear_bit(IIO_BUSY_BIT_POS, &ev_int->flags); 165 __clear_bit(IIO_BUSY_BIT_POS, &ev_int->flags);
165 spin_unlock(&ev_int->wait.lock); 166 spin_unlock_irq(&ev_int->wait.lock);
166 } 167 }
167 return fd; 168 return fd;
168} 169}